lkml.org 
[lkml]   [2021]   [Apr]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 4/6] devres: handle zero size in devm_kmalloc()
Hi Bartosz,

On Mon, Jun 29, 2020 at 1:56 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> Make devm_kmalloc() behave similarly to non-managed kmalloc(): return
> ZERO_SIZE_PTR when requested size is 0. Update devm_kfree() to handle
> this case.

This is wrong if you consider devm_krealloc API that you added. The
premise of devm_krealloc() is that it does not disturb devres "stack",
however in this case there is no entry in the stack. Consider:

ptr = devm_kzalloc(dev, 0, GFP_KERNEL);
...
more devm API calls
...

/* This allocation will be on top of devm stack, not bottom ! */
ptr = devm_krealloc(dev, ptr, 16, GFP_KERNEL);

And also:

ptr = devm_kzalloc(dev, 16, GFP_KERNEL);
...
more devm API calls
...
/* Here we lose out position */
ptr = devm_krealloc(dev, ptr, 0, GFP_KERNEL);
...
/* and now our memory allocation will be released first */
ptr = devm_krealloc(dev, ptr, 16, GFP_KERNEL);


IMO special-casing 0-size allocations for managed memory allocations
should not be done.

Thanks.

--
Dmitry

\
 
 \ /
  Last update: 2021-04-11 05:22    [W:0.340 / U:0.320 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site