diff options
author | Bartosz Golaszewski <bgolaszewski@baylibre.com> | 2020-06-29 08:50:06 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-07-02 14:36:02 +0200 |
commit | cad064f1bd5237481d15b72b481809e3f0907dd9 (patch) | |
tree | a86ec4ec838e7efb4a6a671586db5e2e458e9235 /drivers/base/devres.c | |
parent | device: remove 'extern' attribute from function prototypes in device.h (diff) | |
download | linux-cad064f1bd5237481d15b72b481809e3f0907dd9.tar.xz linux-cad064f1bd5237481d15b72b481809e3f0907dd9.zip |
devres: handle zero size in devm_kmalloc()
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.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Link: https://lore.kernel.org/r/20200629065008.27620-5-brgl@bgdev.pl
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base/devres.c')
-rw-r--r-- | drivers/base/devres.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 1df1fb10b2d9..ed615d3b9cf1 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -819,6 +819,9 @@ void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) { struct devres *dr; + if (unlikely(!size)) + return ZERO_SIZE_PTR; + /* use raw alloc_dr for kmalloc caller tracing */ dr = alloc_dr(devm_kmalloc_release, size, gfp, dev_to_node(dev)); if (unlikely(!dr)) @@ -950,10 +953,10 @@ void devm_kfree(struct device *dev, const void *p) int rc; /* - * Special case: pointer to a string in .rodata returned by - * devm_kstrdup_const(). + * Special cases: pointer to a string in .rodata returned by + * devm_kstrdup_const() or NULL/ZERO ptr. */ - if (unlikely(is_kernel_rodata((unsigned long)p))) + if (unlikely(is_kernel_rodata((unsigned long)p) || ZERO_OR_NULL_PTR(p))) return; rc = devres_destroy(dev, devm_kmalloc_release, |