All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: wenhuizhang <wenhui@gwmail.gwu.edu>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Shakeel Butt <shakeelb@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Roman Gushchin <guro@fb.com>,
	Muchun Song <songmuchun@bytedance.com>,
	Yang Shi <shy828301@gmail.com>, Alex Shi <alexs@kernel.org>,
	Alexander Duyck <alexander.h.duyck@linux.intel.com>,
	Wei Yang <richard.weiyang@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] memcontrol: use flexible-array member
Date: Tue, 18 May 2021 10:08:21 +0200	[thread overview]
Message-ID: <YKN19XI/6Wpk9+Eh@dhcp22.suse.cz> (raw)
In-Reply-To: <20210518052038.491-1-wenhui@gwmail.gwu.edu>

On Tue 18-05-21 01:20:36, wenhuizhang wrote:
> 
> Change depracated zero-length-and-one-element-arrays into flexible 
> array member.
> Zero-length and one-element arrays detected by Lukas's CodeChecker.
> Zero/one element arrays causes undefined behaviours if sizeof() used.
> 
> https://www.kernel.org/doc/html/latest/processd/deprecated.html

I do understand why zero-length structures are discouraged for trail
space but does the same concern apply to internal padding inside
structures to enforce alignment to different cache lines? AFAIK this is
a trick we use at other places and I do not remember having heard about
any problems.

nodeinfo is a different case where flexible arrays seems reasonable to
me.

> Signed-off-by: wenhuizhang<wenhui@gwmail.gwu.edu>
> ---
>  include/linux/memcontrol.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 0ce97eff79e2..f879efb1bc6e 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -190,7 +190,7 @@ enum memcg_kmem_state {
>  
>  #if defined(CONFIG_SMP)
>  struct memcg_padding {
> -	char x[0];
> +	char x[];
>  } ____cacheline_internodealigned_in_smp;
>  #define MEMCG_PADDING(name)      struct memcg_padding name;
>  #else
> @@ -349,7 +349,7 @@ struct mem_cgroup {
>  	struct deferred_split deferred_split_queue;
>  #endif
>  
> -	struct mem_cgroup_per_node *nodeinfo[0];
> +	struct mem_cgroup_per_node *nodeinfo[];
>  	/* WARNING: nodeinfo must be the last member here */
>  };
>  
> -- 
> 2.17.1

-- 
Michal Hocko
SUSE Labs

  parent reply	other threads:[~2021-05-18  8:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18  5:20 [PATCH] memcontrol: use flexible-array member wenhuizhang
2021-05-18  6:35 ` [External] " Muchun Song
2021-05-18  8:08 ` Michal Hocko [this message]
2021-05-18  8:43   ` [External] " Muchun Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YKN19XI/6Wpk9+Eh@dhcp22.suse.cz \
    --to=mhocko@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.h.duyck@linux.intel.com \
    --cc=alexs@kernel.org \
    --cc=guro@fb.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richard.weiyang@gmail.com \
    --cc=shakeelb@google.com \
    --cc=shy828301@gmail.com \
    --cc=songmuchun@bytedance.com \
    --cc=wenhui@gwmail.gwu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.