提交 cad064f1 编写于 作者: B Bartosz Golaszewski 提交者: Greg Kroah-Hartman

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: NBartosz Golaszewski <bgolaszewski@baylibre.com>
Link: https://lore.kernel.org/r/20200629065008.27620-5-brgl@bgdev.plSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 67dd0772
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册