linux-next: build warning after merge of the akpm-current tree
Subsystems (2)
Hi Andrew,
After merging the akpm-current tree, today's linux-next build (powerpc ppc64_defconfig) produced this warning:
In file included from include/linux/mmzone.h:17:0,
from include/linux/mempolicy.h:10,
from mm/mempolicy.c:70:
mm/mempolicy.c: In function 'mpol_to_str':
include/linux/nodemask.h:107:41: warning: the address of 'nodes' will always evaluate as 'true' [-Waddress]
#define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL
^
mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args'
nodemask_pr_args(&nodes));
^
include/linux/nodemask.h:107:69: warning: the address of 'nodes' will always evaluate as 'true' [-Waddress]
#define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL
^
mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args'
nodemask_pr_args(&nodes));
^Introduced by commit
b2c1ed23bdc1 ("mm: simplify nodemask printing")
Signature · 2 lines
Cheers, Stephen Rothwell
Quoted 6 lines · Stephen Rothwell
Hi Andrew,
After merging the akpm-current tree, today's linux-next build (powerpc
ppc64_defconfig) produced this warning:In file included from
include/linux/mmzone.h:17:0,
Quoted 9 lines
from include/linux/mempolicy.h:10,
from mm/mempolicy.c:70:
mm/mempolicy.c: In function 'mpol_to_str':
include/linux/nodemask.h:107:41: warning: the address of 'nodes' will always evaluate as 'true' [-Waddress]
#define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL
^
mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args'
nodemask_pr_args(&nodes));
^Hmm, this warning is quite surprising to me. Sure in this particular case maskp will always be non-NULL so we always expand to
MAX_NUMNODES, maskp->bits
which is what we want. But we have other users which may be NULL. Does anybody understan why this warns at all?
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 17 lines · Michal Hocko
Quoted 6 lines · Stephen Rothwell
Hi Andrew,
After merging the akpm-current tree, today's linux-next build (powerpc
ppc64_defconfig) produced this warning:In file included from
include/linux/mmzone.h:17:0,Quoted 9 lines
from include/linux/mempolicy.h:10, from mm/mempolicy.c:70: mm/mempolicy.c: In function 'mpol_to_str': include/linux/nodemask.h:107:41: warning: the address of 'nodes' will always evaluate as 'true' [-Waddress] #define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL ^ mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args' nodemask_pr_args(&nodes)); ^
Quoted 5 lines
Hmm, this warning is quite surprising to me. Sure in this particular case maskp will always be non-NULL so we always expand to
MAX_NUMNODES, maskp->bitswhich is what we want. But we have other users which may be NULL. Does anybody understan why this warns at all?
Strange I played with the following minimal test case and it warns only for the explicit &m use while n is clearly never null as well. This all smells like -Waddress is just confused (at least with my gcc 7.2.0-12
#include <stdio.h>
#define MAX_NUMNODES 10
struct mask {
void *bits;
};#define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL
int foo(void)
{
struct mask m;
struct mask *n = &m;
printf("%*p\n", nodemask_pr_args(&m));
printf("%*p\n", nodemask_pr_args(n));
return 0;
}Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 17 lines · Michal Hocko
Quoted 6 lines · Stephen Rothwell
Hi Andrew,
After merging the akpm-current tree, today's linux-next build (powerpc
ppc64_defconfig) produced this warning:In file included from
include/linux/mmzone.h:17:0,Quoted 9 lines
from include/linux/mempolicy.h:10, from mm/mempolicy.c:70: mm/mempolicy.c: In function 'mpol_to_str': include/linux/nodemask.h:107:41: warning: the address of 'nodes' will always evaluate as 'true' [-Waddress] #define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL ^ mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args' nodemask_pr_args(&nodes)); ^
Quoted 5 lines
Hmm, this warning is quite surprising to me. Sure in this particular case maskp will always be non-NULL so we always expand to
MAX_NUMNODES, maskp->bitswhich is what we want. But we have other users which may be NULL. Does anybody understan why this warns at all?
As I understand it, the warning tries to address a common typo of accidentally testing the pointer to a stack object for being non-NULL, rather than the object pointed to for being non-zero.
Adding an extra '!= NULL' comparison gets rid of the warning for me:
#define nodemask_pr_args(maskp) \
((maskp) != NULL) ? MAX_NUMNODES : 0, \
((maskp) != NULL) ?(maskp)->bits : NULL
Arnd
Quoted 28 lines · Arnd Bergmann
Quoted 17 lines · Michal Hocko
Quoted 6 lines · Stephen Rothwell
Hi Andrew,
After merging the akpm-current tree, today's linux-next build (powerpc
ppc64_defconfig) produced this warning:In file included from
include/linux/mmzone.h:17:0,Quoted 9 lines
from include/linux/mempolicy.h:10, from mm/mempolicy.c:70: mm/mempolicy.c: In function 'mpol_to_str': include/linux/nodemask.h:107:41: warning: the address of 'nodes' will always evaluate as 'true' [-Waddress] #define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL ^ mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args' nodemask_pr_args(&nodes)); ^Quoted 5 lines
Hmm, this warning is quite surprising to me. Sure in this particular case maskp will always be non-NULL so we always expand to
MAX_NUMNODES, maskp->bitswhich is what we want. But we have other users which may be NULL. Does anybody understan why this warns at all?
As I understand it, the warning tries to address a common typo of accidentally testing the pointer to a stack object for being non-NULL, rather than the object pointed to for being non-zero.
Quoted 5 lines
Adding an extra '!= NULL' comparison gets rid of the warning for me:
#define nodemask_pr_args(maskp) \ ((maskp) != NULL) ? MAX_NUMNODES : 0, \ ((maskp) != NULL) ?(maskp)->bits : NULL
OK, that is a reasonable workaround. I was talking to our gcc guy and he suggested to report a bug for this. Andrew, could you fold the explicit != NULL check into the patch please?
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 29 lines · Michal Hocko
Quoted 28 lines · Arnd Bergmann
Quoted 17 lines · Michal Hocko
Quoted 6 lines · Stephen Rothwell
Hi Andrew,
After merging the akpm-current tree, today's linux-next build (powerpc
ppc64_defconfig) produced this warning:In file included from
include/linux/mmzone.h:17:0,Quoted 9 lines
from include/linux/mempolicy.h:10, from mm/mempolicy.c:70: mm/mempolicy.c: In function 'mpol_to_str': include/linux/nodemask.h:107:41: warning: the address of 'nodes' will always evaluate as 'true' [-Waddress] #define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL ^ mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args' nodemask_pr_args(&nodes)); ^Quoted 5 lines
Hmm, this warning is quite surprising to me. Sure in this particular case maskp will always be non-NULL so we always expand to
MAX_NUMNODES, maskp->bitswhich is what we want. But we have other users which may be NULL. Does anybody understan why this warns at all?
As I understand it, the warning tries to address a common typo of accidentally testing the pointer to a stack object for being non-NULL, rather than the object pointed to for being non-zero.
Quoted 8 lines
Quoted 5 lines
Adding an extra '!= NULL' comparison gets rid of the warning for me:
#define nodemask_pr_args(maskp) \ ((maskp) != NULL) ? MAX_NUMNODES : 0, \ ((maskp) != NULL) ?(maskp)->bits : NULLOK, that is a reasonable workaround. I was talking to our gcc guy and he suggested to report a bug for this.
That might also be useful. Some warnings in gcc get disabled when they show up inside of a macro, and that could presumably be done here too.
Arnd
Quoted 29 lines · Michal Hocko
Quoted 28 lines · Arnd Bergmann
Quoted 17 lines · Michal Hocko
Quoted 6 lines · Stephen Rothwell
Hi Andrew,
After merging the akpm-current tree, today's linux-next build (powerpc
ppc64_defconfig) produced this warning:In file included from
include/linux/mmzone.h:17:0,Quoted 9 lines
from include/linux/mempolicy.h:10, from mm/mempolicy.c:70: mm/mempolicy.c: In function 'mpol_to_str': include/linux/nodemask.h:107:41: warning: the address of 'nodes' will always evaluate as 'true' [-Waddress] #define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL ^ mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args' nodemask_pr_args(&nodes)); ^Quoted 5 lines
Hmm, this warning is quite surprising to me. Sure in this particular case maskp will always be non-NULL so we always expand to
MAX_NUMNODES, maskp->bitswhich is what we want. But we have other users which may be NULL. Does anybody understan why this warns at all?
As I understand it, the warning tries to address a common typo of accidentally testing the pointer to a stack object for being non-NULL, rather than the object pointed to for being non-zero.
Quoted 8 lines
Quoted 5 lines
Adding an extra '!= NULL' comparison gets rid of the warning for me:
#define nodemask_pr_args(maskp) \ ((maskp) != NULL) ? MAX_NUMNODES : 0, \ ((maskp) != NULL) ?(maskp)->bits : NULLOK, that is a reasonable workaround. I was talking to our gcc guy and he suggested to report a bug for this.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82963
Signature · 2 lines
Michal Hocko SUSE Labs
Hi all,
Quoted 28 lines · On Mon, 13 Nov 2017 12:43:08 +0100 Arnd Bergmann <[email protected]> wrote:
Quoted 16 lines · Michal Hocko
Quoted 5 lines · Stephen Rothwell
After merging the akpm-current tree, today's linux-next build (powerpc
ppc64_defconfig) produced this warning:In file included from
include/linux/mmzone.h:17:0,Quoted 9 lines
from include/linux/mempolicy.h:10, from mm/mempolicy.c:70: mm/mempolicy.c: In function 'mpol_to_str': include/linux/nodemask.h:107:41: warning: the address of 'nodes' will always evaluate as 'true' [-Waddress] #define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL ^ mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args' nodemask_pr_args(&nodes)); ^Quoted 5 lines
Hmm, this warning is quite surprising to me. Sure in this particular case maskp will always be non-NULL so we always expand to
MAX_NUMNODES, maskp->bitswhich is what we want. But we have other users which may be NULL. Does anybody understan why this warns at all?
As I understand it, the warning tries to address a common typo of accidentally testing the pointer to a stack object for being non-NULL, rather than the object pointed to for being non-zero.
Quoted 7 lines
Adding an extra '!= NULL' comparison gets rid of the warning for me:
#define nodemask_pr_args(maskp) \ ((maskp) != NULL) ? MAX_NUMNODES : 0, \ ((maskp) != NULL) ?(maskp)->bits : NULL Arnd
This warning now exists in Linus' tree :-(
Signature · 2 lines
Cheers, Stephen Rothwell
Hi all,
Quoted 32 lines · On Fri, 17 Nov 2017 09:44:39 +1100 Stephen Rothwell <[email protected]>…
Quoted 30 lines · On Mon, 13 Nov 2017 12:43:08 +0100 Arnd Bergmann <[email protected]> wrote:
Quoted 16 lines · Michal Hocko
Quoted 5 lines · Stephen Rothwell
After merging the akpm-current tree, today's linux-next build (powerpc
ppc64_defconfig) produced this warning:In file included from
include/linux/mmzone.h:17:0,Quoted 9 lines
from include/linux/mempolicy.h:10, from mm/mempolicy.c:70: mm/mempolicy.c: In function 'mpol_to_str': include/linux/nodemask.h:107:41: warning: the address of 'nodes' will always evaluate as 'true' [-Waddress] #define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL ^ mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args' nodemask_pr_args(&nodes)); ^Quoted 5 lines
Hmm, this warning is quite surprising to me. Sure in this particular case maskp will always be non-NULL so we always expand to
MAX_NUMNODES, maskp->bitswhich is what we want. But we have other users which may be NULL. Does anybody understan why this warns at all?
As I understand it, the warning tries to address a common typo of accidentally testing the pointer to a stack object for being non-NULL, rather than the object pointed to for being non-zero.
Adding an extra '!= NULL' comparison gets rid of the warning for me:
Quoted 7 lines
Quoted 5 lines
#define nodemask_pr_args(maskp) \ ((maskp) != NULL) ? MAX_NUMNODES : 0, \ ((maskp) != NULL) ?(maskp)->bits : NULL ArndThis warning now exists in Linus' tree :-(
Looking closer, it seems that the above workaround doesn't work for my compiler (gcc v5.2.0):
In file included from include/linux/mmzone.h:17:0,
from include/linux/mempolicy.h:10,
from mm/mempolicy.c:70:
mm/mempolicy.c: In function 'mpol_to_str':
include/linux/nodemask.h:108:11: warning: the comparison will always evaluate as 'true' for the address of 'nodes' will never be NULL [-Waddress]
((maskp) != NULL) ? MAX_NUMNODES : 0, \
^
mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args'
nodemask_pr_args(&nodes));
^
include/linux/nodemask.h:109:11: warning: the comparison will always evaluate as 'true' for the address of 'nodes' will never be NULL [-Waddress]
((maskp) != NULL) ? (maskp)->bits : NULL
^
mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args'
nodemask_pr_args(&nodes));
^Signature · 2 lines
Cheers, Stephen Rothwell
Hi,
Quoted 39 lines · Stephen Rothwell
Hi all,
Quoted 36 lines · On Fri, 17 Nov 2017 09:44:39 +1100 Stephen Rothwell <[email protected]>…
Quoted 34 lines · On Mon, 13 Nov 2017 12:43:08 +0100 Arnd Bergmann <[email protected]> wrote:
Quoted 16 lines · Michal Hocko
Quoted 5 lines · Stephen Rothwell
After merging the akpm-current tree, today's linux-next build (powerpc
ppc64_defconfig) produced this warning:In file included from
include/linux/mmzone.h:17:0,Quoted 9 lines
from include/linux/mempolicy.h:10, from mm/mempolicy.c:70: mm/mempolicy.c: In function 'mpol_to_str': include/linux/nodemask.h:107:41: warning: the address of 'nodes' will always evaluate as 'true' [-Waddress] #define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL ^ mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args' nodemask_pr_args(&nodes)); ^Quoted 5 lines
Hmm, this warning is quite surprising to me. Sure in this particular case maskp will always be non-NULL so we always expand to
MAX_NUMNODES, maskp->bitswhich is what we want. But we have other users which may be NULL. Does anybody understan why this warns at all?
As I understand it, the warning tries to address a common typo of accidentally testing the pointer to a stack object for being non-NULL, rather than the object pointed to for being non-zero.
Adding an extra '!= NULL' comparison gets rid of the warning for me:
#define nodemask_pr_args(maskp) \ ((maskp) != NULL) ? MAX_NUMNODES : 0, \ ((maskp) != NULL) ?(maskp)->bits : NULL
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Arnd
This warning now exists in Linus' tree :-(
Looking closer, it seems that the above workaround doesn't work for my compiler (gcc v5.2.0):
I also came across this issue using Linus' tree and my gcc is gcc version 5.4.0 20160609
(Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.5).
CC drivers/clk/renesas/rcar-gen3-cpg.o
In file included from ./include/linux/mmzone.h:17:0,
from ./include/linux/mempolicy.h:10,
from mm/mempolicy.c:70:
mm/mempolicy.c: In function ‘mpol_to_str’:
./include/linux/nodemask.h:108:11: warning: the comparison will always evaluate as ‘true’ for the address of ‘nodes’ will never be NULL [-Waddress]
((maskp) != NULL) ? MAX_NUMNODES : 0, \
^
mm/mempolicy.c:2817:11: note: in expansion of macro ‘nodemask_pr_args’
nodemask_pr_args(&nodes));
^
./include/linux/nodemask.h:109:11: warning: the comparison will always evaluate as ‘true’ for the address of ‘nodes’ will never be NULL [-Waddress]
((maskp) != NULL) ? (maskp)->bits : NULL
^
mm/mempolicy.c:2817:11: note: in expansion of macro ‘nodemask_pr_args’
nodemask_pr_args(&nodes));
^ CC drivers/clk/renesas/renesas-cpg-mssr.o
Thanks,
Shaokun
Quoted 17 lines
In file included from
include/linux/mmzone.h:17:0,from include/linux/mempolicy.h:10, from mm/mempolicy.c:70: mm/mempolicy.c: In function 'mpol_to_str': include/linux/nodemask.h:108:11: warning: the comparison will always evaluate as 'true' for the address of 'nodes' will never be NULL [-Waddress] ((maskp) != NULL) ? MAX_NUMNODES : 0, \ ^ mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args' nodemask_pr_args(&nodes)); ^ include/linux/nodemask.h:109:11: warning: the comparison will always evaluate as 'true' for the address of 'nodes' will never be NULL [-Waddress] ((maskp) != NULL) ? (maskp)->bits : NULL ^ mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args' nodemask_pr_args(&nodes)); ^
Quoted 39 lines · Stephen Rothwell
Hi all,
Quoted 36 lines · On Fri, 17 Nov 2017 09:44:39 +1100 Stephen Rothwell <[email protected]>…
Quoted 34 lines · On Mon, 13 Nov 2017 12:43:08 +0100 Arnd Bergmann <[email protected]> wrote:
Quoted 16 lines · Michal Hocko
Quoted 5 lines · Stephen Rothwell
After merging the akpm-current tree, today's linux-next build (powerpc
ppc64_defconfig) produced this warning:In file included from
include/linux/mmzone.h:17:0,Quoted 9 lines
from include/linux/mempolicy.h:10, from mm/mempolicy.c:70: mm/mempolicy.c: In function 'mpol_to_str': include/linux/nodemask.h:107:41: warning: the address of 'nodes' will always evaluate as 'true' [-Waddress] #define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL ^ mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args' nodemask_pr_args(&nodes)); ^Quoted 5 lines
Hmm, this warning is quite surprising to me. Sure in this particular case maskp will always be non-NULL so we always expand to
MAX_NUMNODES, maskp->bitswhich is what we want. But we have other users which may be NULL. Does anybody understan why this warns at all?
As I understand it, the warning tries to address a common typo of accidentally testing the pointer to a stack object for being non-NULL, rather than the object pointed to for being non-zero.
Adding an extra '!= NULL' comparison gets rid of the warning for me:
#define nodemask_pr_args(maskp) \ ((maskp) != NULL) ? MAX_NUMNODES : 0, \ ((maskp) != NULL) ?(maskp)->bits : NULL
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Arnd
This warning now exists in Linus' tree :-(
Looking closer, it seems that the above workaround doesn't work for my compiler (gcc v5.2.0):
Right, I see now that all versions from gcc-4.6 to gcc-6 are affected by this, while 4.5 and
earlier as well as 7 and 8 are not.
I'll try to come up with an alternative workaround, it will probably be even uglier.
Arnd
PATCH 1/1 mm: fix nodemask printing
The cleanup caused build warnings for constant mask pointers:
mm/mempolicy.c: In function ‘mpol_to_str’:./include/linux/nodemask.h:108:11: warning: the comparison will always evaluate as ‘true’ for the address of ‘nodes’ will never be NULL [-Waddress]
An earlier workaround I suggested was incorporated in the version that got merged, but that only solved the problem for gcc-7 and higher, while gcc-4.6 through gcc-6.x still warn.
This changes the printing again to use inline functions that make it clear to the compiler that the line that does the NULL check has no idea whether the argument is a constant NULL.
---
I've done only minimal build testing on this, but did check it with all compiler versions this time.
--- include/linux/nodemask.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
include/linux/nodemask.h +10 -3
@@ -104,9 +104,16 @@ extern nodemask_t _unused_nodemask_arg_;* * Can be used to provide arguments for '%*pb[l]' when printing a nodemask. */ -#define nodemask_pr_args (maskp) \ - ((maskp) != NULL) ? MAX_NUMNODES : 0, \ - ((maskp) != NULL) ? (maskp)->bits : NULL +#define nodemask_pr_args (maskp) __nodemask_pr_numnodes(maskp), \ + __nodemask_pr_bits(maskp) +static inline unsigned int __nodemask_pr_numnodes (const nodemask_t *m) +{ +return m ?MAX_NUMNODES :0 ; +} +static inline const unsigned long *__nodemask_pr_bits (const nodemask_t *m) +{ +return m ? m->bits :NULL ; +}/* * The inline keyword gives the compiler room to decide to inline, or
Signature · 1 line
2.9.0
Re: [PATCH] mm: fix nodemask printing
Quoted 9 lines · Arnd Bergmann
The cleanup caused build warnings for constant mask pointers:
mm/mempolicy.c: In function ‘mpol_to_str’:./include/linux/nodemask.h:108:11: warning: the comparison will always evaluate as ‘true’ for the address of ‘nodes’ will never be NULL [-Waddress]An earlier workaround I suggested was incorporated in the version that got merged, but that only solved the problem for gcc-7 and higher, while gcc-4.6 through gcc-6.x still warn.
Quoted 6 lines
This changes the printing again to use inline functions that make it clear to the compiler that the line that does the NULL check has no idea whether the argument is a constant NULL.
Fixes 0205f75571e3 ("mm: simplify nodemask printing")Signed-off-by Arnd Bergmann <[email protected]>
Thanks for the fixup. It is sad how a questionable warning makes the code worse... Does it make sense to have the warning enabled? Gcc bug [1] suggests there is no great interest into fixing it.
Anyway to the patch
[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82963
Quoted 33 lines
---
I've done only minimal build testing on this, but did check it with all compiler versions this time.--- include/linux/nodemask.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)include/linux/nodemask.h +10
-3@@ -104,9 +104,16 @@ extern nodemask_t _unused_nodemask_arg_;* * Can be used to provide arguments for '%*pb[l]' when printing a nodemask. */ -#define nodemask_pr_args (maskp) \ - ((maskp) != NULL) ? MAX_NUMNODES : 0, \ - ((maskp) != NULL) ? (maskp)->bits : NULL +#define nodemask_pr_args (maskp) __nodemask_pr_numnodes(maskp), \ + __nodemask_pr_bits(maskp) +static inline unsigned int __nodemask_pr_numnodes (const nodemask_t *m) +{ +return m ?MAX_NUMNODES :0 ; +} +static inline const unsigned long *__nodemask_pr_bits (const nodemask_t *m) +{ +return m ? m->bits :NULL ; +}/* * The inline keyword gives the compiler room to decide to inline, or Signature · 1 line
2.9.0
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH] mm: fix nodemask printing
Quoted 17 lines · Michal Hocko
Quoted 9 lines · Arnd Bergmann
The cleanup caused build warnings for constant mask pointers:
mm/mempolicy.c: In function ‘mpol_to_str’:./include/linux/nodemask.h:108:11: warning: the comparison will always evaluate as ‘true’ for the address of ‘nodes’ will never be NULL [-Waddress]An earlier workaround I suggested was incorporated in the version that got merged, but that only solved the problem for gcc-7 and higher, while gcc-4.6 through gcc-6.x still warn.
Quoted 6 lines
This changes the printing again to use inline functions that make it clear to the compiler that the line that does the NULL check has no idea whether the argument is a constant NULL.
Fixes 0205f75571e3 ("mm: simplify nodemask printing")Signed-off-by Arnd Bergmann <[email protected]>
Quoted 8 lines
Thanks for the fixup. It is sad how a questionable warning makes the code worse... Does it make sense to have the warning enabled? Gcc bug [1] suggests there is no great interest into fixing it.
Anyway to the patch
Acked-by Michal Hocko <[email protected]>
I think I found some real bugs when I started seeing that warning elsewhere, so I'd rather keep it enabled in general. I'd still agree that the gcc behavior in macros is questionable though, in particular since they decided to stop warning for the "!= NULL" case. I've found the commit that changed gcc-7 behavior and commented again in the bugzilla, but did not reopen.
The inline function was mentioned in bugzilla there[2] as the preferred workaround.
Arnd