Re: [PATCH v3 1/3] string.h: add memcpy_and_pad()

2017-07-23 Thread kbuild test robot
Hi Martin,

[auto build test ERROR on linus/master]
[also build test ERROR on v4.13-rc1 next-20170721]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Martin-Wilck/Improve-readbility-of-NVME-wwid-attribute/20170722-110309
config: x86_64-randconfig-v0-07240033 (attached as .config)
compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All errors (new ones prefixed by >>):

   cc1: warnings being treated as errors
   In file included from include/linux/bitmap.h:8,
from include/linux/cpumask.h:11,
from arch/x86/include/asm/cpumask.h:4,
from arch/x86/include/asm/msr.h:10,
from arch/x86/include/asm/processor.h:20,
from arch/x86/include/asm/cpufeature.h:4,
from arch/x86/include/asm/thread_info.h:52,
from include/linux/thread_info.h:37,
from arch/x86/include/asm/preempt.h:6,
from include/linux/preempt.h:80,
from include/linux/spinlock.h:50,
from include/linux/mmzone.h:7,
from include/linux/gfp.h:5,
from include/linux/slab.h:14,
from include/linux/resource_ext.h:19,
from include/linux/acpi.h:26,
from drivers/gpu//drm/i915/i915_drv.c:30:
   include/linux/string.h: In function 'memcpy_and_pad':
>> include/linux/string.h:413: error: '__f' is static but declared in 
>> inline function 'memcpy_and_pad' which is not static
   include/linux/string.h:414: error: '__f' is static but declared in 
inline function 'memcpy_and_pad' which is not static
   include/linux/string.h:416: error: '__f' is static but declared in 
inline function 'memcpy_and_pad' which is not static
   include/linux/string.h:419: error: '__f' is static but declared in 
inline function 'memcpy_and_pad' which is not static
   include/linux/string.h:421: error: '__f' is static but declared in 
inline function 'memcpy_and_pad' which is not static

vim +413 include/linux/string.h

   398  
   399  /**
   400   * memcpy_and_pad - Copy one buffer to another with padding
   401   * @dest: Where to copy to
   402   * @dest_len: The destination buffer size
   403   * @src: Where to copy from
   404   * @count: The number of bytes to copy
   405   * @pad: Character to use for padding if space is left in destination.
   406   */
   407  __FORTIFY_INLINE void memcpy_and_pad(void *dest, size_t dest_len,
   408   const void *src, size_t count, int 
pad)
   409  {
   410  size_t dest_size = __builtin_object_size(dest, 0);
   411  size_t src_size = __builtin_object_size(src, 0);
   412  
 > 413  if (__builtin_constant_p(dest_len) && 
 > __builtin_constant_p(count)) {
   414  if (dest_size < dest_len && dest_size < count)
   415  __write_overflow();
   416  else if (src_size < dest_len && src_size < count)
   417  __read_overflow3();
   418  }
   419  if (dest_size < dest_len)
   420  fortify_panic(__func__);
   421  if (dest_len > count) {
   422  memcpy(dest, src, count);
   423  memset(dest + count, pad,  dest_len - count);
   424  } else
   425  memcpy(dest, src, dest_len);
   426  }
   427  

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH v3 1/3] string.h: add memcpy_and_pad()

2017-07-21 Thread kbuild test robot
Hi Martin,

[auto build test WARNING on linus/master]
[also build test WARNING on v4.13-rc1 next-20170721]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Martin-Wilck/Improve-readbility-of-NVME-wwid-attribute/20170722-110309
config: x86_64-randconfig-x005-201729 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   In file included from include/uapi/linux/stddef.h:1:0,
from include/linux/stddef.h:4,
from include/uapi/linux/posix_types.h:4,
from include/uapi/linux/types.h:13,
from include/linux/types.h:5,
from include/linux/mod_devicetable.h:11,
from scripts/mod/devicetable-offsets.c:2:
>> include/linux/compiler.h:162:4: warning: '__f' is static but declared in 
>> inline function 'memcpy_and_pad' which is not static
   __f = { \
   ^
   include/linux/compiler.h:154:23: note: in expansion of macro '__trace_if'
#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
  ^~
   include/linux/string.h:421:2: note: in expansion of macro 'if'
 if (dest_len > count) {
 ^~
>> include/linux/compiler.h:162:4: warning: '__f' is static but declared in 
>> inline function 'memcpy_and_pad' which is not static
   __f = { \
   ^
   include/linux/compiler.h:154:23: note: in expansion of macro '__trace_if'
#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
  ^~
   include/linux/string.h:419:2: note: in expansion of macro 'if'
 if (dest_size < dest_len)
 ^~
>> include/linux/compiler.h:162:4: warning: '__f' is static but declared in 
>> inline function 'memcpy_and_pad' which is not static
   __f = { \
   ^
   include/linux/compiler.h:154:23: note: in expansion of macro '__trace_if'
#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
  ^~
   include/linux/string.h:416:8: note: in expansion of macro 'if'
  else if (src_size < dest_len && src_size < count)
   ^~
>> include/linux/compiler.h:162:4: warning: '__f' is static but declared in 
>> inline function 'memcpy_and_pad' which is not static
   __f = { \
   ^
   include/linux/compiler.h:154:23: note: in expansion of macro '__trace_if'
#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
  ^~
   include/linux/string.h:414:3: note: in expansion of macro 'if'
  if (dest_size < dest_len && dest_size < count)
  ^~
>> include/linux/compiler.h:162:4: warning: '__f' is static but declared in 
>> inline function 'memcpy_and_pad' which is not static
   __f = { \
   ^
   include/linux/compiler.h:154:23: note: in expansion of macro '__trace_if'
#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
  ^~
   include/linux/string.h:413:2: note: in expansion of macro 'if'
 if (__builtin_constant_p(dest_len) && __builtin_constant_p(count)) {
 ^~
   include/linux/compiler.h:162:4: warning: '__f' is static but declared in 
inline function 'strcpy' which is not static
   __f = { \
   ^
   include/linux/compiler.h:154:23: note: in expansion of macro '__trace_if'
#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
  ^~
   include/linux/string.h:391:2: note: in expansion of macro 'if'
 if (p_size == (size_t)-1 && q_size == (size_t)-1)
 ^~
   include/linux/compiler.h:162:4: warning: '__f' is static but declared in 
inline function 'kmemdup' which is not static
   __f = { \
   ^
   include/linux/compiler.h:154:23: note: in expansion of macro '__trace_if'
#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
  ^~
   include/linux/string.h:381:2: note: in expansion of macro 'if'
 if (p_size < size)
 ^~
   include/linux/compiler.h:162:4: warning: '__f' is static but declared in 
inline function 'kmemdup' which is not static
   __f = { \
   ^
   include/linux/compiler.h:154:23: note: in expansion of macro '__trace_if'
#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
  ^~
   include/linux/string.h:379:2: note: in expansion of macro 'if'
 if (__builtin_constant_p(size) && p_size < size)
 ^~
   include/linux/compiler.h:162:4: warning: '__f' is static but declared in 
inline function 'memchr_inv' which is not static
   __f = { \
   ^
   include/linux/compiler.h:154:23: note: in expansion of macro '__trace_if'
#define if(cond, ...) __trace_if( (cond , ## __

[PATCH v3 1/3] string.h: add memcpy_and_pad()

2017-07-20 Thread Martin Wilck
This helper function is useful for the nvme subsystem, and maybe
others.

Signed-off-by: Martin Wilck 
---
 include/linux/string.h | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/include/linux/string.h b/include/linux/string.h
index a467e617eeb08..0bec4151b0eb9 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -200,6 +200,7 @@ static inline const char *kbasename(const char *path)
 void fortify_panic(const char *name) __noreturn __cold;
 void __read_overflow(void) __compiletime_error("detected read beyond size of 
object passed as 1st parameter");
 void __read_overflow2(void) __compiletime_error("detected read beyond size of 
object passed as 2nd parameter");
+void __read_overflow3(void) __compiletime_error("detected read beyond size of 
object passed as 3rd parameter");
 void __write_overflow(void) __compiletime_error("detected write beyond size of 
object passed as 1st parameter");
 
 #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)
+{
+   size_t dest_size = __builtin_object_size(dest, 0);
+   size_t src_size = __builtin_object_size(src, 0);
+
+   if (__builtin_constant_p(dest_len) && __builtin_constant_p(count)) {
+   if (dest_size < dest_len && dest_size < count)
+   __write_overflow();
+   else if (src_size < dest_len && src_size < count)
+   __read_overflow3();
+   }
+   if (dest_size < dest_len)
+   fortify_panic(__func__);
+   if (dest_len > count) {
+   memcpy(dest, src, count);
+   memset(dest + count, pad,  dest_len - count);
+   } else
+   memcpy(dest, src, dest_len);
+}
+
 #endif /* _LINUX_STRING_H_ */
-- 
2.13.2