diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/of | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.zip | |
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:
Single allocations: kmalloc(sizeof(TYPE), ...)
are replaced with: kmalloc_obj(TYPE, ...)
Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with: kmalloc_objs(TYPE, COUNT, ...)
Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...)
(where TYPE may also be *VAR)
The resulting allocations no longer return "void *", instead returning
"TYPE *".
Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'drivers/of')
| -rw-r--r-- | drivers/of/address.c | 2 | ||||
| -rw-r--r-- | drivers/of/dynamic.c | 6 | ||||
| -rw-r--r-- | drivers/of/irq.c | 2 | ||||
| -rw-r--r-- | drivers/of/of_reserved_mem.c | 2 | ||||
| -rw-r--r-- | drivers/of/overlay.c | 6 | ||||
| -rw-r--r-- | drivers/of/platform.c | 2 | ||||
| -rw-r--r-- | drivers/of/unittest.c | 8 |
7 files changed, 14 insertions, 14 deletions
diff --git a/drivers/of/address.c b/drivers/of/address.c index 4034d798c55a..590d2db007d2 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -929,7 +929,7 @@ int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map) if (!num_ranges) return -EINVAL; - r = kcalloc(num_ranges + 1, sizeof(*r), GFP_KERNEL); + r = kzalloc_objs(*r, num_ranges + 1, GFP_KERNEL); if (!r) return -ENOMEM; diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 2eaaddcb0ec4..1b3cc351a895 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -411,7 +411,7 @@ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags) { struct property *new; - new = kzalloc(sizeof(*new), allocflags); + new = kzalloc_obj(*new, allocflags); if (!new) return NULL; @@ -454,7 +454,7 @@ struct device_node *__of_node_dup(const struct device_node *np, { struct device_node *node; - node = kzalloc(sizeof(*node), GFP_KERNEL); + node = kzalloc_obj(*node, GFP_KERNEL); if (!node) return NULL; node->full_name = kstrdup(full_name, GFP_KERNEL); @@ -908,7 +908,7 @@ int of_changeset_action(struct of_changeset *ocs, unsigned long action, if (WARN_ON(action >= ARRAY_SIZE(action_names))) return -EINVAL; - ce = kzalloc(sizeof(*ce), GFP_KERNEL); + ce = kzalloc_obj(*ce, GFP_KERNEL); if (!ce) return -ENOMEM; diff --git a/drivers/of/irq.c b/drivers/of/irq.c index f374d8b212b8..55c2de65a13a 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -669,7 +669,7 @@ void __init of_irq_init(const struct of_device_id *matches) * Here, we allocate and populate an of_intc_desc with the node * pointer, interrupt-parent device_node etc. */ - desc = kzalloc(sizeof(*desc), GFP_KERNEL); + desc = kzalloc_obj(*desc, GFP_KERNEL); if (!desc) { of_node_put(np); goto err; diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 31c5bc751d0d..0344c55300b6 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -646,7 +646,7 @@ int of_reserved_mem_device_init_by_idx(struct device *dev, if (!rmem || !rmem->ops || !rmem->ops->device_init) return -EINVAL; - rd = kmalloc(sizeof(struct rmem_assigned_device), GFP_KERNEL); + rd = kmalloc_obj(struct rmem_assigned_device, GFP_KERNEL); if (!rd) return -ENOMEM; diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 5b4f42230e6c..87faec65c865 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -248,7 +248,7 @@ static struct property *dup_and_fixup_symbol_prop( return NULL; target_path_len = strlen(target_path); - new_prop = kzalloc(sizeof(*new_prop), GFP_KERNEL); + new_prop = kzalloc_obj(*new_prop, GFP_KERNEL); if (!new_prop) goto err_free_target_path; @@ -784,7 +784,7 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs, of_node_put(node); } - fragments = kcalloc(cnt, sizeof(*fragments), GFP_KERNEL); + fragments = kzalloc_objs(*fragments, cnt, GFP_KERNEL); if (!fragments) { ret = -ENOMEM; goto err_out; @@ -1009,7 +1009,7 @@ int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, if (overlay_fdt_size < size) return -EINVAL; - ovcs = kzalloc(sizeof(*ovcs), GFP_KERNEL); + ovcs = kzalloc_obj(*ovcs, GFP_KERNEL); if (!ovcs) return -ENOMEM; diff --git a/drivers/of/platform.c b/drivers/of/platform.c index d90b1677d84e..d9a717c47ad6 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -111,7 +111,7 @@ struct platform_device *of_device_alloc(struct device_node *np, /* Populate the resource table */ if (num_reg) { - res = kcalloc(num_reg, sizeof(*res), GFP_KERNEL); + res = kzalloc_objs(*res, num_reg, GFP_KERNEL); if (!res) { platform_device_put(dev); return NULL; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index a9cc2c990562..a8b70b49e780 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -197,7 +197,7 @@ static void __init of_unittest_dynamic(void) } /* Array of 4 properties for the purpose of testing */ - prop = kcalloc(4, sizeof(*prop), GFP_KERNEL); + prop = kzalloc_objs(*prop, 4, GFP_KERNEL); if (!prop) { unittest(0, "kzalloc() failed\n"); return; @@ -379,7 +379,7 @@ static void __init of_unittest_check_phandles(void) } } - nh = kzalloc(sizeof(*nh), GFP_KERNEL); + nh = kzalloc_obj(*nh, GFP_KERNEL); if (!nh) return; @@ -1136,7 +1136,7 @@ static void __init of_unittest_dma_ranges_one(const char *path, dma_addr_t dma_addr; struct device *dev_bogus; - dev_bogus = kzalloc(sizeof(struct device), GFP_KERNEL); + dev_bogus = kzalloc_obj(struct device, GFP_KERNEL); if (!dev_bogus) { unittest(0, "kzalloc() failed\n"); kfree(map); @@ -2275,7 +2275,7 @@ static int unittest_gpio_probe(struct platform_device *pdev) unittest_gpio_probe_count++; - devptr = kzalloc(sizeof(*devptr), GFP_KERNEL); + devptr = kzalloc_obj(*devptr, GFP_KERNEL); if (!devptr) return -ENOMEM; |
