On Thu, Feb 4, 2021 at 3:41 PM Alexandru Ardelean <ardeleanalex@xxxxxxxxx> wrote: > On Wed, Feb 3, 2021 at 12:04 PM Andy Shevchenko > <andy.shevchenko@xxxxxxxxx> wrote: > > On Mon, Feb 1, 2021 at 5:28 PM Alexandru Ardelean > > <alexandru.ardelean@xxxxxxxxxx> wrote: ... > > > + group->attrs = kcalloc(buffer_attrcount + 1, > > > + sizeof(struct attribute *), GFP_KERNEL); > > > + if (!group->attrs) > > > + return -ENOMEM; > > > + > > > + memcpy(group->attrs, buffer_attrs, > > > + buffer_attrcount * sizeof(struct attribute *)); > > > > kmemdup() ? > > Perhaps introduce kmemdup_array(). > > doesn't add much benefit from what i can tell; > and it complicates things with the fact that we need to add the extra > null terminator element; > [1] if we kmemdup(buffer_attrcount + 1) , the copy an extra element we > don't need, which needs to be null-ed Ah, I see now. Thanks for pointing it out! > > > + group->attrs = kcalloc(scan_el_attrcount + 1, > > > + sizeof(struct attribute *), GFP_KERNEL); > > > + if (!group->attrs) { > > > + ret = -ENOMEM; > > > + goto error_free_buffer_attrs; > > > + } > > > + > > > + memcpy(group->attrs, &buffer_attrs[buffer_attrcount], > > > + scan_el_attrcount * sizeof(struct attribute *)); > > > > Ditto. > > continuing from [1] > here it may be worse, because kmemdup() would copy 1 element from > undefined memory; -- With Best Regards, Andy Shevchenko