Skip to content

Commit c462d30

Browse files
committed
devres: handle zero size in devm_kmalloc()
jira LE-1907 Rebuild_History Non-Buildable kernel-4.18.0-532.el8 commit-author Bartosz Golaszewski <[email protected]> commit cad064f 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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit cad064f) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 45dea6b commit c462d30

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/base/devres.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,9 @@ void * devm_kmalloc(struct device *dev, size_t size, gfp_t gfp)
822822
{
823823
struct devres *dr;
824824

825+
if (unlikely(!size))
826+
return ZERO_SIZE_PTR;
827+
825828
/* use raw alloc_dr for kmalloc caller tracing */
826829
dr = alloc_dr(devm_kmalloc_release, size, gfp, dev_to_node(dev));
827830
if (unlikely(!dr))
@@ -1050,10 +1053,10 @@ void devm_kfree(struct device *dev, const void *p)
10501053
int rc;
10511054

10521055
/*
1053-
* Special case: pointer to a string in .rodata returned by
1054-
* devm_kstrdup_const().
1056+
* Special cases: pointer to a string in .rodata returned by
1057+
* devm_kstrdup_const() or NULL/ZERO ptr.
10551058
*/
1056-
if (unlikely(is_kernel_rodata((unsigned long)p)))
1059+
if (unlikely(is_kernel_rodata((unsigned long)p) || ZERO_OR_NULL_PTR(p)))
10571060
return;
10581061

10591062
rc = devres_destroy(dev, devm_kmalloc_release,

0 commit comments

Comments
 (0)