From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753039AbdFUJZi (ORCPT ); Wed, 21 Jun 2017 05:25:38 -0400 Received: from smtp121.iad3a.emailsrvr.com ([173.203.187.121]:58776 "EHLO smtp121.iad3a.emailsrvr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752819AbdFUJZg (ORCPT ); Wed, 21 Jun 2017 05:25:36 -0400 X-Auth-ID: siepeng@mev.co.uk X-Sender-Id: siepeng@mev.co.uk Subject: Re: [PATCH] kernel.h: fix new warnings for container_of() To: Arnd Bergmann , Andrew Morton References: <20170620200940.90557-1-arnd@arndb.de> Cc: Michal Nazarewicz , Kees Cook , Borislav Petkov , Johannes Berg , Peter Zijlstra , Alexander Potapenko , linux-kernel@vger.kernel.org From: Ian Abbott Message-ID: <8a59e380-be8b-9dce-26a8-1015c7aabb7c@mev.co.uk> Date: Wed, 21 Jun 2017 10:25:27 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170620200940.90557-1-arnd@arndb.de> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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 -- -=( Ian Abbott @ MEV Ltd. E-mail: )=- -=( Web: http://www.mev.co.uk/ )=-