Skip to contentSkip to conversation

mm/memcontrol.c: fix another unused function warning

PATCH In review Arnd Bergmann 4 participants 7 messages Oct 1, 2019 – Oct 2, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

Fixes 4d0e3230a56a ("mm/memcontrol.c: fix a -Wunused-function warning")
---
 mm/memcontrol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/memcontrol.c +2 -1
index c313c49074ca..5f9f90e3cef8 100644
@@ -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
#1 lore raw
Quoted 2 lines · Arnd Bergmann

Removing the mem_cgroup_id_get() stub function introduced a new warning of the same kind when CONFIG_MMU is 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_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.

Fixes 4d0e3230a56a ("mm/memcontrol.c: fix a -Wunused-function warning")
---
 mm/memcontrol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/memcontrol.c +2 -1
index c313c49074ca..5f9f90e3cef8 100644
@@ -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);
 }
#2 lore raw
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 when CONFIG_MMU is disabled:

Shouldn't CONFIG_MEMCG depends on CONFIG_MMU instead?

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

#3 lore raw
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 when CONFIG_MMU is disabled:

Shouldn't CONFIG_MEMCG depends on CONFIG_MMU instead?

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.

Those blindly mark __maybe_unused might just mask important warnings off in the future, and they are ugly. Let's fix it properly.

maintainer
#4 lore raw
In reply to Qian Cai
Quoted 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 when CONFIG_MMU is disabled:

Shouldn't CONFIG_MEMCG depends on CONFIG_MMU instead?

I wanted to do that in the past but there was a clear disagreement from Johannes.

Signature · 2 lines
Michal Hocko
SUSE Labs
#5 lore raw
In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

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

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")
---
 mm/memcontrol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/memcontrol.c +2 -2
index c313c49074ca..5f9f90e3cef8 100644
@@ -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
maintainer
#6 lore raw
Quoted 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 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.

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 of mem_cgroup_id_get_many() to just before __mem_cgroup_clear_mc()? I find __maybe_unused to be a code smell.

Agreed!

Signature · 2 lines
Michal Hocko
SUSE Labs