mm/memcontrol.c: fix another unused function warning
Subsystems (3)
PATCH 1/1 mm/memcontrol.c: fix another unused function warning
Removing the mem_cgroup_id_get() stub function introduced a new warning of the same kind when CONFIG_MMU is disabled:
mm/memcontrol.c:4929:13: error: unused function 'mem_cgroup_id_get_many' [-Werror,-Wunused-function]
Address this using a __maybe_unused annotation.
Note: alternatively, this could be moved into an #ifdef block. Marking it 'static inline' would not work here as that would still produce the warning on clang, which only ignores unused inline functions declared in header files instead of .c files.
--- mm/memcontrol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/memcontrol.c +2 -1
@@ -4921,7 +4921,8 @@ static void mem_cgroup_id_remove(struct mem_cgroup *memcg) } } -static void mem_cgroup_id_get_many (struct mem_cgroup *memcg,unsigned int n) +static void __maybe_unused +mem_cgroup_id_get_many (struct mem_cgroup *memcg,unsigned int n) {refcount_add (n, &memcg->id.ref); }
Signature · 1 line
2.20.0
Quoted 2 lines · Arnd Bergmann
Removing the
mem_cgroup_id_get()stub function introduced a new warning of the same kind whenCONFIG_MMUis disabled:
Shouldn't CONFIG_MEMCG depends on CONFIG_MMU instead?
Quoted 30 lines
mm/memcontrol.c:4929:13: error: unused function 'mem_cgroup_id_get_many' [-Werror,-Wunused-function]Address this using a
__maybe_unusedannotation.Note: alternatively, this could be moved into an #ifdef block. Marking it 'static inline' would not work here as that would still produce the warning on clang, which only ignores unused inline functions declared in header files instead of .c files.
Fixes 4d0e3230a56a ("mm/memcontrol.c: fix a -Wunused-function warning")Signed-off-by Arnd Bergmann <[email protected]>--- mm/memcontrol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/memcontrol.c +2
-1@@ -4921,7 +4921,8 @@ static void mem_cgroup_id_remove(struct mem_cgroup *memcg) } } -static void mem_cgroup_id_get_many (struct mem_cgroup *memcg,unsigned int n) +static void __maybe_unused +mem_cgroup_id_get_many (struct mem_cgroup *memcg,unsigned int n) {refcount_add (n, &memcg->id.ref); }
Quoted 6 lines · Qian Cai
Quoted 2 lines · Arnd Bergmann
Removing the
mem_cgroup_id_get()stub function introduced a new warning of the same kind whenCONFIG_MMUis disabled:Shouldn't
CONFIG_MEMCGdepends onCONFIG_MMUinstead?
Maybe. Generally we allow building a lot of stuff without CONFIG_MMU that may not make sense, so I just followed the same idea here.
Arnd
Quoted 10 lines · Arnd Bergmann
Quoted 6 lines · Qian Cai
Quoted 2 lines · Arnd Bergmann
Removing the
mem_cgroup_id_get()stub function introduced a new warning of the same kind whenCONFIG_MMUis disabled:Shouldn't
CONFIG_MEMCGdepends onCONFIG_MMUinstead?Maybe. Generally we allow building a lot of stuff without
CONFIG_MMUthat may not make sense, so I just followed the same idea here.
Those blindly mark __maybe_unused might just mask important warnings off in the future, and they are ugly. Let's fix it properly.
Michal Hocko
maintainerQuoted 5 lines · Qian Cai
Quoted 2 lines · Arnd Bergmann
Removing the
mem_cgroup_id_get()stub function introduced a new warning of the same kind whenCONFIG_MMUis disabled:Shouldn't
CONFIG_MEMCGdepends onCONFIG_MMUinstead?
I wanted to do that in the past but there was a clear disagreement from Johannes.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 9 lines · Arnd Bergmann
Removing the
mem_cgroup_id_get()stub function introduced a new warning of the same kind whenCONFIG_MMUis disabled:
mm/memcontrol.c:4929:13: error: unused function 'mem_cgroup_id_get_many' [-Werror,-Wunused-function]Address this using a
__maybe_unusedannotation.Note: alternatively, this could be moved into an #ifdef block. Marking it
Hi Arnd,
Thank you for the patch! I would prefer to move the definition to the correct set of #ifdef guards rather than __maybe_unused. Maybe move the definition of mem_cgroup_id_get_many() to just before __mem_cgroup_clear_mc()? I find __maybe_unused to be a code smell.
Quoted 25 lines
'static inline' would not work here as that would still produce the warning on clang, which only ignores unused inline functions declared in header files instead of .c files.
Fixes 4d0e3230a56a ("mm/memcontrol.c: fix a -Wunused-function warning")Signed-off-by Arnd Bergmann <[email protected]>--- mm/memcontrol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/memcontrol.c +2
-2@@ -4921,7 +4921,8 @@ static void mem_cgroup_id_remove(struct mem_cgroup *memcg) } } -static void mem_cgroup_id_get_many (struct mem_cgroup *memcg,unsigned int n) +static void __maybe_unused +mem_cgroup_id_get_many (struct mem_cgroup *memcg,unsigned int n) {refcount_add (n, &memcg->id.ref); } --
Signature · 2 lines
Thanks, ~Nick Desaulniers
Michal Hocko
maintainerQuoted 9 lines · Nick Desaulniers
Quoted 8 lines · Arnd Bergmann
Removing the
mem_cgroup_id_get()stub function introduced a new warning of the same kind whenCONFIG_MMUis disabled:
mm/memcontrol.c:4929:13: error: unused function 'mem_cgroup_id_get_many' [-Werror,-Wunused-function]Address this using a
__maybe_unusedannotation.
Quoted 7 lines
Quoted 1 line
Note: alternatively, this could be moved into an #ifdef block. Marking it
Hi Arnd,
Thank you for the patch! I would prefer to move the definition to the correct set of #ifdef guards rather than__maybe_unused. Maybe move the definition ofmem_cgroup_id_get_many()to just before__mem_cgroup_clear_mc()? I find__maybe_unusedto be a code smell.
Agreed!
Signature · 2 lines
Michal Hocko SUSE Labs