Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752271AbdIEH2b (ORCPT ); Tue, 5 Sep 2017 03:28:31 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:35034 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751843AbdIEH20 (ORCPT ); Tue, 5 Sep 2017 03:28:26 -0400 X-Google-Smtp-Source: ADKCNb6+YCZQtXZmdJ9B2/QxebfnFd1rPbH1kqx8QqwPLkt+aCK/GHCwdpZO6IQMjVfV9CoatbH1eGkYM2Wcwa1TLKA= MIME-Version: 1.0 In-Reply-To: <20170814201239.15255-3-mwilck@suse.com> References: <20170810084541.bawqaebfycnguomx@infradead.org> <20170814201239.15255-1-mwilck@suse.com> <20170814201239.15255-3-mwilck@suse.com> From: Arnd Bergmann Date: Tue, 5 Sep 2017 09:28:25 +0200 X-Google-Sender-Auth: QtOSUhWLskXtlYHG2jgPRzKgE3A Message-ID: Subject: Re: [PATCH v4 2/3] string.h: add memcpy_and_pad() To: Martin Wilck Cc: Christoph Hellwig , Keith Busch , Sagi Grimberg , Martin Wilck , Johannes Thumshirn , Hannes Reinecke , linux-nvme@lists.infradead.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2833 Lines: 67 On Mon, Aug 14, 2017 at 10:12 PM, Martin Wilck wrote: > This helper function is useful for the nvme subsystem, and maybe > others. > > Note: the warnings reported by the kbuild test robot for this patch > are actually generated by the use of CONFIG_PROFILE_ALL_BRANCHES > together with __FORTIFY_INLINE. > > Signed-off-by: Martin Wilck > --- > #if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE) > @@ -395,4 +396,33 @@ __FORTIFY_INLINE char *strcpy(char *p, const char *q) > > #endif > > +/** > + * memcpy_and_pad - Copy one buffer to another with padding > + * @dest: Where to copy to > + * @dest_len: The destination buffer size > + * @src: Where to copy from > + * @count: The number of bytes to copy > + * @pad: Character to use for padding if space is left in destination. > + */ > +__FORTIFY_INLINE void memcpy_and_pad(void *dest, size_t dest_len, > + const void *src, size_t count, int pad) > +{ This is causing compile-time warnings for me: In file included from /git/arm-soc/arch/x86/include/asm/string.h:2:0, from /git/arm-soc/include/linux/string.h:18, from /git/arm-soc/arch/x86/include/asm/page_32.h:34, from /git/arm-soc/arch/x86/include/asm/page.h:13, from /git/arm-soc/arch/x86/include/asm/thread_info.h:11, from /git/arm-soc/include/linux/thread_info.h:37, from /git/arm-soc/arch/x86/include/asm/preempt.h:6, from /git/arm-soc/include/linux/preempt.h:80, from /git/arm-soc/include/linux/spinlock.h:50, from /git/arm-soc/include/linux/seqlock.h:35, from /git/arm-soc/include/linux/time.h:5, from /git/arm-soc/include/linux/stat.h:18, from /git/arm-soc/include/linux/module.h:10, from /git/arm-soc/drivers/md/dm-integrity.c:9: /git/arm-soc/arch/x86/include/asm/string_32.h:196:25: error: '__memcpy' is static but used in inline function 'memcpy_and_pad' which is not static [-Werror] #define memcpy(t, f, n) __memcpy((t), (f), (n)) ^~~~~~~~ /git/arm-soc/include/linux/string.h:466:3: note: in expansion of macro 'memcpy' ^ /git/arm-soc/arch/x86/include/asm/string_32.h:196:25: error: '__memcpy' is static but used in inline function 'memcpy_and_pad' which is not static [-Werror] #define memcpy(t, f, n) __memcpy((t), (f), (n)) ^~~~~~~~ The problem is the use of __FORTIFY_INLINE outside of the #ifdef section above it. I used an ugly local workaround, duplicating the function with a 'static inline' variant in an #else block. Alternatively we could add an extern version in lib/string.c for the non-fortified case. Arnd