Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-Wsometimes-uninitialized in net/atm/resources.c #386

Closed
nickdesaulniers opened this issue Feb 26, 2019 · 5 comments
Closed

-Wsometimes-uninitialized in net/atm/resources.c #386

nickdesaulniers opened this issue Feb 26, 2019 · 5 comments
Assignees
Labels
-Wsometimes-uninitialized [ARCH] arm32 This bug impacts ARCH=arm [BUG] linux A bug that should be fixed in the mainline kernel. [FIXED][LINUX] 5.1 This bug was fixed in Linux 5.1

Comments

@nickdesaulniers
Copy link
Member

from #381

net/atm/resources.c:256:6: error: variable 'number' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
net/atm/resources.c:212:7: error: variable 'iobuf_len' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
@nickdesaulniers nickdesaulniers added good first issue Good for newcomers [BUG] linux A bug that should be fixed in the mainline kernel. low priority This bug is not critical and not a priority [ARCH] arm32 This bug impacts ARCH=arm -Wsometimes-uninitialized labels Feb 26, 2019
@nickdesaulniers
Copy link
Member Author

This case looks trickier. Also, I don't get the same line numbers in my checkout of -next, so maybe that's making it hard to spot. The dual preprocessor and runtime check for compat is very odd.

@nickdesaulniers nickdesaulniers removed the good first issue Good for newcomers label Feb 26, 2019
@nathanchance
Copy link
Member

Hmm odd... Here is the full warning:

net/atm/resources.c:256:6: warning: variable 'number' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
        if (compat) {
            ^~~~~~
net/atm/resources.c:283:47: note: uninitialized use occurs here
        dev = try_then_request_module(atm_dev_lookup(number), "atm-device-%d",
                                                     ^~~~~~
include/linux/kmod.h:41:4: note: expanded from macro 'try_then_request_module'
        ((x) ?: (__request_module(true, mod), (x)))
          ^
net/atm/resources.c:256:2: note: remove the 'if' if its condition is always false
        if (compat) {
        ^~~~~~~~~~~~~
net/atm/resources.c:199:24: note: initialize the variable 'number' to silence this warning
        int error, len, number, size = 0;
                              ^
                               = 0
net/atm/resources.c:212:7: warning: variable 'iobuf_len' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
                if (compat) {
                    ^~~~~~
net/atm/resources.c:227:21: note: uninitialized use occurs here
                if (get_user(len, iobuf_len))
                                  ^~~~~~~~~
arch/arm/include/asm/uaccess.h:237:23: note: expanded from macro 'get_user'
                __get_user_check(x, p);                                 \
                                    ^
arch/arm/include/asm/uaccess.h:197:50: note: expanded from macro '__get_user_check'
                register typeof(*(p)) __user *__p asm("r0") = (p);      \
                                                               ^
net/atm/resources.c:212:3: note: remove the 'if' if its condition is always false
                if (compat) {
                ^~~~~~~~~~~~~
net/atm/resources.c:204:23: note: initialize the variable 'iobuf_len' to silence this warning
        int __user *iobuf_len;
                             ^
                              = NULL
2 warnings generated.

My guess is it is one of those "Clang does analysis before optimization" because when CONFIG_COMPAT isn't set, compat is always 0 so the true case will never happen.

@nathanchance
Copy link
Member

@nathanchance nathanchance added [PATCH] Submitted A patch has been submitted for review and removed low priority This bug is not critical and not a priority labels Mar 7, 2019
@nathanchance nathanchance self-assigned this Mar 7, 2019
@nathanchance nathanchance added [PATCH] Accepted A submitted patch has been accepted upstream and removed [PATCH] Submitted A patch has been submitted for review labels Mar 7, 2019
fengguang pushed a commit to 0day-ci/linux that referenced this issue Mar 7, 2019
When building with -Wsometimes-uninitialized, Clang warns:

net/atm/resources.c:256:6: warning: variable 'number' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
net/atm/resources.c:212:7: warning: variable 'iobuf_len' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]

Clang won't realize that compat is 0 when CONFIG_COMPAT is not set until
the constant folding stage, which happens after this semantic analysis.
Use IS_ENABLED instead so that the zero is present at the semantic
analysis stage, which eliminates this warning.

Link: ClangBuiltLinux#386
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
fengguang pushed a commit to 0day-ci/linux that referenced this issue Mar 10, 2019
When building with -Wsometimes-uninitialized, Clang warns:

net/atm/resources.c:256:6: warning: variable 'number' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
net/atm/resources.c:212:7: warning: variable 'iobuf_len' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]

Clang won't realize that compat is 0 when CONFIG_COMPAT is not set until
the constant folding stage, which happens after this semantic analysis.
Use IS_ENABLED instead so that the zero is present at the semantic
analysis stage, which eliminates this warning.

Link: ClangBuiltLinux#386
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
@nathanchance
Copy link
Member

Merged into mainline (second was a follow up fix):

https://git.kernel.org/torvalds/c/f9d19a7494e5341a7f256823e32788ae560ca22f

https://git.kernel.org/torvalds/c/0805a4b894a8daaf76ad99934563d8ecfc6e7aed

@nathanchance nathanchance added [FIXED][LINUX] 5.1 This bug was fixed in Linux 5.1 and removed [PATCH] Accepted A submitted patch has been accepted upstream labels Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Wsometimes-uninitialized [ARCH] arm32 This bug impacts ARCH=arm [BUG] linux A bug that should be fixed in the mainline kernel. [FIXED][LINUX] 5.1 This bug was fixed in Linux 5.1
Projects
None yet
Development

No branches or pull requests

2 participants