Subject: Re: [PATCH v5 4/8] cgroup: Remove CGROUP_BUILTIN_SUBSYS_COUNT

From: Li Zefan <[email-masked]>
Date: Thu, 13 Sep 2012 16:07:05 +0800

On 2012/9/13 15:50, Daniel Wagner wrote:
> From: Daniel Wagner <[email-masked]>
> 
> CGROUP_BUILTIN_SUBSYS_COUNT is used as start index or stop index when
> looping over the subsys array looking either at the builtin or the
> module subsystems. Since all the builtin subsystems have an id which
> is lower then CGROUP_BUILTIN_SUBSYS_COUNT we know that any module will
> have an id larger than CGROUP_BUILTIN_SUBSYS_COUNT. In short the ids
> are sorted.
> 
> We are about to change id assignment to happen only at compile time
> later in this series. That means we can't rely on the above trick
> since all ids will always be defined at compile time. Furthermore,
> ordering the builtin subsystems and the module subsystems is not
> really necessary.
> 
> So we need a different way to know which subsystem is a builtin or a
> module one. We can use the subsys[]->module pointer for this. Any
> place where we need to know if a subsys is module we just check for
> the pointer. If it is NULL then the subsystem is a builtin one.
> 
> With this we are able to drop the CGROUP_BUILTIN_SUBSYS_COUNT
> enum. Though we need to introduce a temporary placeholder so that we
> don't get a compilation error when only CONFIG_CGROUP is selected and
> no single controller. An empty enum definition is not valid. Later in
> this series we are able to remove the placeholder again.
> 
> And with this change we get a fix for this:
> 
> kernel/cgroup.c: In function ‘cgroup_load_subsys’:
> kernel/cgroup.c:4326:38: warning: array subscript is below array bounds [-Warray-bounds]
> 
> when CONFIG_CGROUP=y and no built in controller was enabled.
> 
> Signed-off-by: Daniel Wagner <[email-masked]>
> Acked-by: Tejun Heo <[email-masked]>
> Cc: Gao feng <[email-masked]>
> Cc: Jamal Hadi Salim <jhs-jkUAjuhPggJWk0Htik3J/[email-masked]>
> Cc: John Fastabend <[email-masked]>
> Cc: Li Zefan <[email-masked]>
> Cc: Neil Horman <[email-masked]>
> Cc: [email-masked]
> Cc: [email-masked]
> ---
>  include/linux/cgroup.h |  2 +-
>  kernel/cgroup.c        | 68 +++++++++++++++++++++++++++++---------------------
>  2 files changed, 41 insertions(+), 29 deletions(-)
> 

Acked-by: Li Zefan <[email-masked]>