mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Abbott <abbotti@mev.co.uk>
To: Arnd Bergmann <arnd@arndb.de>, Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Nazarewicz <mina86@mina86.com>,
	Kees Cook <keescook@chromium.org>, Borislav Petkov <bp@suse.de>,
	Johannes Berg <johannes.berg@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Alexander Potapenko <glider@google.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kernel.h: fix new warnings for container_of()
Date: Wed, 21 Jun 2017 10:25:27 +0100	[thread overview]
Message-ID: <8a59e380-be8b-9dce-26a8-1015c7aabb7c@mev.co.uk> (raw)
In-Reply-To: <20170620200940.90557-1-arnd@arndb.de>

On 20/06/17 21:09, Arnd Bergmann wrote:
> I see new warnings with gcc-7.0.1 with the modified container_of():
>
> fs/f2fs/dir.c: In function 'F2FS_I':
> fs/f2fs/f2fs.h:1122:385: note: found mismatched ssa struct pointer types: 'struct f2fs_inode_info' and 'struct inode'

Is that actually a warning, or just informational?  In any case, it 
seems like a good idea to avoid it.

>
> This seems to happen for all structures that have a zero offset
> between the member and the container structure, i.e. idential
> pointers.
>
> Reverting to an intermediate pointer avoids the warning, and using
> a void pointer instead of the target type should also avoid
> regressing on the previous patch again.
>
> Fixes: mmotm ("kernel.h: handle pointers to arrays better in container_of()")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  include/linux/kernel.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index d043adadcf33..bd6d96cf80b1 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -856,10 +856,11 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
>   *
>   */
>  #define container_of(ptr, type, member) ({				\
> +	void *__mptr = (void *)(ptr);					\
>  	BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&	\
>  			 !__same_type(*(ptr), void),			\
>  			 "pointer type mismatch in container_of()");	\
> -	((type *)((char *)(ptr) - offsetof(type, member))); })
> +	((type *)(__mptr - offsetof(type, member))); })
>
>  /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */
>  #ifdef CONFIG_FTRACE_MCOUNT_RECORD
>

Acked-by: Ian Abbott <abbotti@mev.co.uk>

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@mev.co.uk> )=-
-=(                          Web: http://www.mev.co.uk/  )=-

  parent reply	other threads:[~2017-06-21  9:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-20 20:09 Arnd Bergmann
2017-06-20 22:43 ` Kees Cook
2017-06-20 22:46   ` Kees Cook
2017-06-21  9:25 ` Ian Abbott [this message]
2017-06-21 10:15   ` Arnd Bergmann

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=8a59e380-be8b-9dce-26a8-1015c7aabb7c@mev.co.uk \
    --to=abbotti@mev.co.uk \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=bp@suse.de \
    --cc=glider@google.com \
    --cc=johannes.berg@intel.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mina86@mina86.com \
    --cc=peterz@infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®