[PATCH v7 1/3] devres: provide devm_krealloc()

Andy Shevchenko andriy.shevchenko at linux.intel.com
Tue Aug 18 04:25:00 EDT 2020


On Mon, Aug 17, 2020 at 10:02:05PM +0200, Bartosz Golaszewski wrote:
> On Mon, Aug 17, 2020 at 7:43 PM Andy Shevchenko
> <andriy.shevchenko at linux.intel.com> wrote:
> > On Mon, Aug 17, 2020 at 07:05:33PM +0200, Bartosz Golaszewski wrote:
> > > From: Bartosz Golaszewski <bgolaszewski at baylibre.com>

...

> > > +static struct devres *to_devres(void *data)
> > > +{
> > > +     return (struct devres *)((u8 *)data - ALIGN(sizeof(struct devres),
> > > +                                                 ARCH_KMALLOC_MINALIGN));
> >
> > Do you really need both explicit castings?
> >
> 
> Yeah, we can probably drop the (struct devres *) here.

void * -> u8 * here is also not needed, it is considered byte access IIRC.

> > > +}

...

> >  - hasn't gone while you run a ksize()?

> At some point you need to draw a line. In the end: how do you
> guarantee a devres buffer hasn't been freed when you're using it? In
> my comment to the previous version of this patch I clarified that we
> need to protect all modifications of the devres linked list - we must
> not realloc a chunk that contains the links without taking the
> spinlock but also we must not call alloc() funcs with GFP_KERNEL with
> spinlock taken. The issue we could run into is: someone modifies the
> linked list by adding/removing other managed resources, not modifying
> this one.
> 
> The way this function works now guarantees it but other than that:
> it's up to the users to not free memory they're actively using.

Thanks for clarification. I agree.

-- 
With Best Regards,
Andy Shevchenko





More information about the linux-arm-kernel mailing list