[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMRc=Me=D1cOsaRqK-BwHT7f-_=3=eciduA=G95FfE2e_XUWfg@mail.gmail.com>
Date: Fri, 21 Aug 2020 10:59:19 +0200
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: Jonathan Cameron <jic23@...nel.org>,
Hartmut Knaack <knaack.h@....de>,
Lars-Peter Clausen <lars@...afoo.de>,
Peter Meerwald-Stadler <pmeerw@...erw.net>,
Michal Simek <michal.simek@...inx.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Guenter Roeck <linux@...ck-us.net>,
linux-iio <linux-iio@...r.kernel.org>,
Linux ARM <linux-arm-kernel@...ts.infradead.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Bartosz Golaszewski <bgolaszewski@...libre.com>
Subject: Re: [PATCH v8 1/3] devres: provide devm_krealloc()
On Fri, Aug 21, 2020 at 10:35 AM Andy Shevchenko
<andriy.shevchenko@...ux.intel.com> wrote:
>
> On Thu, Aug 20, 2020 at 08:51:08PM +0200, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bgolaszewski@...libre.com>
> >
> > Implement the managed variant of krealloc(). This function works with
> > all memory allocated by devm_kmalloc() (or devres functions using it
> > implicitly like devm_kmemdup(), devm_kstrdup() etc.).
> >
> > Managed realloc'ed chunks can be manually released with devm_kfree().
> >
> > Signed-off-by: Bartosz Golaszewski <bgolaszewski@...libre.com>
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
>
> ...
>
> > +static struct devres *to_devres(void *data)
> > +{
> > + return data - ALIGN(sizeof(struct devres), ARCH_KMALLOC_MINALIGN);
> > +}
> > +
> > +static size_t devres_data_size(size_t total_size)
> > +{
> > + return total_size - ALIGN(sizeof(struct devres), ARCH_KMALLOC_MINALIGN);
> > +}
>
> I'm fine with above, but here is a side note, perhaps
>
> offsetof(struct devres, data)
>
> will be more practical (no duplication of alignment and hence slightly better
> maintenance)? (Note, I didn't check if it provides the correct result)
>
Hi Andy,
The data pointer in struct devres is defined as:
u8 __aligned(ARCH_KMALLOC_MINALIGN) data[];
And this value (assigned the value of ARCH_DMA_MINALIGN) varies from
one arch to another. I wasn't really sure if offsetof() would work for
every case so I went with something very explicit.
> Another side note: do we have existing users of these helpers?
>
Which ones? Because I assume you're not referring to the ones I'm
adding in this patch. :)
Bart
Powered by blists - more mailing lists