Re: [PATCH] net/802: use struct_size over open coded arithmetic

From: kernel test robot
Date: Fri Jan 28 2022 - 07:41:27 EST


Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]
[also build test ERROR on net/master horms-ipvs/master linus/master v5.17-rc1 next-20220128]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/cgel-zte-gmail-com/net-802-use-struct_size-over-open-coded-arithmetic/20220128-160925
base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 72d044e4bfa6bd9096536e2e1c62aecfe1a525e4
config: riscv-randconfig-r042-20220124 (https://download.01.org/0day-ci/archive/20220128/202201282017.0TQvVTtf-lkp@xxxxxxxxx/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 33b45ee44b1f32ffdbc995e6fec806271b4b3ba4)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/0day-ci/linux/commit/9b64e5078d3d779fc56432d43129479f63996c74
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review cgel-zte-gmail-com/net-802-use-struct_size-over-open-coded-arithmetic/20220128-160925
git checkout 9b64e5078d3d779fc56432d43129479f63996c74
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash drivers/net/wireless/ath/wcn36xx/ net/802/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>

All errors (new ones prefixed by >>):

>> net/802/garp.c:187:17: error: member reference type 'struct garp_attr' is not a pointer; did you mean to use '.'?
attr = kmalloc(struct_size(*attr, data, len), GFP_ATOMIC);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:194:18: note: expanded from macro 'struct_size'
sizeof(*(p)->member) + __must_be_array((p)->member),\
~~~^
>> net/802/garp.c:187:17: error: indirection requires pointer operand ('unsigned char[]' invalid)
attr = kmalloc(struct_size(*attr, data, len), GFP_ATOMIC);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:194:14: note: expanded from macro 'struct_size'
sizeof(*(p)->member) + __must_be_array((p)->member),\
^~~~~~~~~~~~
>> net/802/garp.c:187:17: error: member reference type 'struct garp_attr' is not a pointer; did you mean to use '.'?
attr = kmalloc(struct_size(*attr, data, len), GFP_ATOMIC);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:194:49: note: expanded from macro 'struct_size'
sizeof(*(p)->member) + __must_be_array((p)->member),\
~~~~~~~~~~~~~~~~~~~^~~~~~~~~
include/linux/compiler.h:258:59: note: expanded from macro '__must_be_array'
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
include/linux/compiler_types.h:287:63: note: expanded from macro '__same_type'
#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
^
include/linux/build_bug.h:16:62: note: expanded from macro 'BUILD_BUG_ON_ZERO'
#define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
^
>> net/802/garp.c:187:17: error: member reference type 'struct garp_attr' is not a pointer; did you mean to use '.'?
attr = kmalloc(struct_size(*attr, data, len), GFP_ATOMIC);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:194:49: note: expanded from macro 'struct_size'
sizeof(*(p)->member) + __must_be_array((p)->member),\
~~~~~~~~~~~~~~~~~~~^~~~~~~~~
include/linux/compiler.h:258:65: note: expanded from macro '__must_be_array'
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
include/linux/compiler_types.h:287:74: note: expanded from macro '__same_type'
#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
^
include/linux/build_bug.h:16:62: note: expanded from macro 'BUILD_BUG_ON_ZERO'
#define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
^
>> net/802/garp.c:187:17: error: indirection requires pointer operand ('struct garp_attr' invalid)
attr = kmalloc(struct_size(*attr, data, len), GFP_ATOMIC);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:195:14: note: expanded from macro 'struct_size'
sizeof(*(p)))
^~~~
5 errors generated.
--
>> net/802/mrp.c:276:17: error: member reference type 'struct mrp_attr' is not a pointer; did you mean to use '.'?
attr = kmalloc(struct_size(*attr, value, len), GFP_ATOMIC);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:194:18: note: expanded from macro 'struct_size'
sizeof(*(p)->member) + __must_be_array((p)->member),\
~~~^
>> net/802/mrp.c:276:17: error: indirection requires pointer operand ('unsigned char[]' invalid)
attr = kmalloc(struct_size(*attr, value, len), GFP_ATOMIC);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:194:14: note: expanded from macro 'struct_size'
sizeof(*(p)->member) + __must_be_array((p)->member),\
^~~~~~~~~~~~
>> net/802/mrp.c:276:17: error: member reference type 'struct mrp_attr' is not a pointer; did you mean to use '.'?
attr = kmalloc(struct_size(*attr, value, len), GFP_ATOMIC);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:194:49: note: expanded from macro 'struct_size'
sizeof(*(p)->member) + __must_be_array((p)->member),\
~~~~~~~~~~~~~~~~~~~^~~~~~~~~
include/linux/compiler.h:258:59: note: expanded from macro '__must_be_array'
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
include/linux/compiler_types.h:287:63: note: expanded from macro '__same_type'
#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
^
include/linux/build_bug.h:16:62: note: expanded from macro 'BUILD_BUG_ON_ZERO'
#define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
^
>> net/802/mrp.c:276:17: error: member reference type 'struct mrp_attr' is not a pointer; did you mean to use '.'?
attr = kmalloc(struct_size(*attr, value, len), GFP_ATOMIC);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:194:49: note: expanded from macro 'struct_size'
sizeof(*(p)->member) + __must_be_array((p)->member),\
~~~~~~~~~~~~~~~~~~~^~~~~~~~~
include/linux/compiler.h:258:65: note: expanded from macro '__must_be_array'
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
include/linux/compiler_types.h:287:74: note: expanded from macro '__same_type'
#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
^
include/linux/build_bug.h:16:62: note: expanded from macro 'BUILD_BUG_ON_ZERO'
#define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
^
>> net/802/mrp.c:276:17: error: indirection requires pointer operand ('struct mrp_attr' invalid)
attr = kmalloc(struct_size(*attr, value, len), GFP_ATOMIC);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/overflow.h:195:14: note: expanded from macro 'struct_size'
sizeof(*(p)))
^~~~
5 errors generated.


vim +187 net/802/garp.c

166
167 static struct garp_attr *garp_attr_create(struct garp_applicant *app,
168 const void *data, u8 len, u8 type)
169 {
170 struct rb_node *parent = NULL, **p = &app->gid.rb_node;
171 struct garp_attr *attr;
172 int d;
173
174 while (*p) {
175 parent = *p;
176 attr = rb_entry(parent, struct garp_attr, node);
177 d = garp_attr_cmp(attr, data, len, type);
178 if (d > 0)
179 p = &parent->rb_left;
180 else if (d < 0)
181 p = &parent->rb_right;
182 else {
183 /* The attribute already exists; re-use it. */
184 return attr;
185 }
186 }
> 187 attr = kmalloc(struct_size(*attr, data, len), GFP_ATOMIC);
188 if (!attr)
189 return attr;
190 attr->state = GARP_APPLICANT_VO;
191 attr->type = type;
192 attr->dlen = len;
193 memcpy(attr->data, data, len);
194
195 rb_link_node(&attr->node, parent, p);
196 rb_insert_color(&attr->node, &app->gid);
197 return attr;
198 }
199

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx