Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1357688 > unrolled thread

[PATCH v2] cgroup: avoid false positive gcc-6 warning

Started byArnd Bergmann <arnd@arndb.de>
First post2016-03-15 00:30 +0100
Last post2016-03-16 21:40 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v2] cgroup: avoid false positive gcc-6 warning Arnd Bergmann <arnd@arndb.de> - 2016-03-15 00:30 +0100
    Re: [PATCH v2] cgroup: avoid false positive gcc-6 warning Tejun Heo <tj@kernel.org> - 2016-03-16 21:40 +0100

#1357688 — [PATCH v2] cgroup: avoid false positive gcc-6 warning

FromArnd Bergmann <arnd@arndb.de>
Date2016-03-15 00:30 +0100
Subject[PATCH v2] cgroup: avoid false positive gcc-6 warning
Message-ID<rcK5X-28k-3@gated-at.bofh.it>
When all subsystems are disabled, gcc notices that cgroup_subsys_enabled_key
is a zero-length array and that any access to it must be out of bounds:

In file included from ../include/linux/cgroup.h:19:0,
                 from ../kernel/cgroup.c:31:
../kernel/cgroup.c: In function 'cgroup_add_cftypes':
../kernel/cgroup.c:261:53: error: array subscript is above array bounds [-Werror=array-bounds]
  return static_key_enabled(cgroup_subsys_enabled_key[ssid]);
                            ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
../include/linux/jump_label.h:271:40: note: in definition of macro 'static_key_enabled'
  static_key_count((struct static_key *)x) > 0;    \
                                        ^

We should never call the function in this particular case, so this is
not a bug. In order to silence the warning, this adds an explicit check
for the CGROUP_SUBSYS_COUNT==0 case.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v2: use 'false' as the return code instead of '0', as suggested by
the friendly kbuild test robot.

 kernel/cgroup.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 155c88470543..5f65c1002b4b 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -258,6 +258,9 @@ static int cgroup_addrm_files(struct cgroup_subsys_state *css,
  */
 static bool cgroup_ssid_enabled(int ssid)
 {
+	if (CGROUP_SUBSYS_COUNT == 0)
+		return false;
+
 	return static_key_enabled(cgroup_subsys_enabled_key[ssid]);
 }
 
-- 
2.7.0

[toc] | [next] | [standalone]


#1359352

FromTejun Heo <tj@kernel.org>
Date2016-03-16 21:40 +0100
Message-ID<rdqox-5zZ-13@gated-at.bofh.it>
In reply to#1357688
On Tue, Mar 15, 2016 at 12:21:06AM +0100, Arnd Bergmann wrote:
> When all subsystems are disabled, gcc notices that cgroup_subsys_enabled_key
> is a zero-length array and that any access to it must be out of bounds:
> 
> In file included from ../include/linux/cgroup.h:19:0,
>                  from ../kernel/cgroup.c:31:
> ../kernel/cgroup.c: In function 'cgroup_add_cftypes':
> ../kernel/cgroup.c:261:53: error: array subscript is above array bounds [-Werror=array-bounds]
>   return static_key_enabled(cgroup_subsys_enabled_key[ssid]);
>                             ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
> ../include/linux/jump_label.h:271:40: note: in definition of macro 'static_key_enabled'
>   static_key_count((struct static_key *)x) > 0;    \
>                                         ^
> 
> We should never call the function in this particular case, so this is
> not a bug. In order to silence the warning, this adds an explicit check
> for the CGROUP_SUBSYS_COUNT==0 case.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied to cgroup/for-4.6.

Thanks.

-- 
tejun

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web