Re: [PATCH 2/5] iio: adc: xilinx: use devm_krealloc() instead of kfree() + kcalloc()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Oct 27, 2020 at 10:33 AM Andy Shevchenko
<andy.shevchenko@xxxxxxxxx> wrote:
>
> On Mon, Oct 26, 2020 at 4:03 PM Bartosz Golaszewski <brgl@xxxxxxxx> wrote:
> >
> > From: Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx>
> >
> > We now have devm_krealloc() in the kernel Use it indstead of calling
> > kfree() and kcalloc() separately.
>
> Which is completely lawful when size > previous_size (I mean, the
> additional patch you sent previously seems not related to this).
>

Sure but devm_krealloc() is cleaner and adds the benefit of resource management.

> > -       kfree(xadc->data);
> > -       xadc->data = kcalloc(n, sizeof(*xadc->data), GFP_KERNEL);
> > +       xadc->data = devm_krealloc(indio_dev->dev.parent, xadc->data,
> > +                                  n * sizeof(*xadc->data),
>
> I think you need to use something from overflow.h instead of explicit
> multiplication here.
>

Or maybe add devm_krealloc_array() which would perform the checks
behind the scenes?

> > +                                  GFP_KERNEL | __GFP_ZERO);
>
> --
> With Best Regards,
> Andy Shevchenko

Bartosz



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux