lkml.org 
[lkml]   [2021]   [Feb]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    Date
    SubjectRe: [PATCH v3 06/11] iio: core: merge buffer/ & scan_elements/ attributes
    On Thu, Feb 4, 2021 at 3:41 PM Alexandru Ardelean
    <ardeleanalex@gmail.com> wrote:
    > On Wed, Feb 3, 2021 at 12:04 PM Andy Shevchenko
    > <andy.shevchenko@gmail.com> wrote:
    > > On Mon, Feb 1, 2021 at 5:28 PM Alexandru Ardelean
    > > <alexandru.ardelean@analog.com> 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

    \
     
     \ /
      Last update: 2021-02-05 12:41    [W:3.030 / U:1.296 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site