summaryrefslogtreecommitdiff
path: root/drivers/sh
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-20 23:49:23 -0800
committerKees Cook <kees@kernel.org>2026-02-21 01:02:28 -0800
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/sh
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
downloadlwn-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/sh')
-rw-r--r--drivers/sh/clk/cpg.c2
-rw-r--r--drivers/sh/intc/core.c11
-rw-r--r--drivers/sh/intc/virq.c4
-rw-r--r--drivers/sh/maple/maple.c4
4 files changed, 9 insertions, 12 deletions
diff --git a/drivers/sh/clk/cpg.c b/drivers/sh/clk/cpg.c
index 64ed7d64458a..58e64a666b2f 100644
--- a/drivers/sh/clk/cpg.c
+++ b/drivers/sh/clk/cpg.c
@@ -459,7 +459,7 @@ int __init sh_clk_fsidiv_register(struct clk *clks, int nr)
for (i = 0; i < nr; i++) {
- map = kzalloc(sizeof(struct clk_mapping), GFP_KERNEL);
+ map = kzalloc_obj(struct clk_mapping, GFP_KERNEL);
if (!map) {
pr_err("%s: unable to alloc memory\n", __func__);
return -ENOMEM;
diff --git a/drivers/sh/intc/core.c b/drivers/sh/intc/core.c
index 3dde703b7766..aa68fe190865 100644
--- a/drivers/sh/intc/core.c
+++ b/drivers/sh/intc/core.c
@@ -204,7 +204,7 @@ int __init register_intc_controller(struct intc_desc *desc)
pr_info("Registered controller '%s' with %u IRQs\n",
desc->name, hw->nr_vectors);
- d = kzalloc(sizeof(*d), GFP_NOWAIT);
+ d = kzalloc_obj(*d, GFP_NOWAIT);
if (!d)
goto err0;
@@ -217,8 +217,7 @@ int __init register_intc_controller(struct intc_desc *desc)
if (desc->num_resources) {
d->nr_windows = desc->num_resources;
- d->window = kcalloc(d->nr_windows, sizeof(*d->window),
- GFP_NOWAIT);
+ d->window = kzalloc_objs(*d->window, d->nr_windows, GFP_NOWAIT);
if (!d->window)
goto err1;
@@ -267,8 +266,7 @@ int __init register_intc_controller(struct intc_desc *desc)
}
if (hw->prio_regs) {
- d->prio = kcalloc(hw->nr_vectors, sizeof(*d->prio),
- GFP_NOWAIT);
+ d->prio = kzalloc_objs(*d->prio, hw->nr_vectors, GFP_NOWAIT);
if (!d->prio)
goto err4;
@@ -283,8 +281,7 @@ int __init register_intc_controller(struct intc_desc *desc)
}
if (hw->sense_regs) {
- d->sense = kcalloc(hw->nr_vectors, sizeof(*d->sense),
- GFP_NOWAIT);
+ d->sense = kzalloc_objs(*d->sense, hw->nr_vectors, GFP_NOWAIT);
if (!d->sense)
goto err5;
diff --git a/drivers/sh/intc/virq.c b/drivers/sh/intc/virq.c
index a638c3048207..291798526519 100644
--- a/drivers/sh/intc/virq.c
+++ b/drivers/sh/intc/virq.c
@@ -93,7 +93,7 @@ static int add_virq_to_pirq(unsigned int irq, unsigned int virq)
last = &entry->next;
}
- entry = kzalloc(sizeof(struct intc_virq_list), GFP_ATOMIC);
+ entry = kzalloc_obj(struct intc_virq_list, GFP_ATOMIC);
if (!entry)
return -ENOMEM;
@@ -168,7 +168,7 @@ static void __init intc_subgroup_init_one(struct intc_desc *desc,
if (!subgroup->enum_ids[i])
continue;
- entry = kmalloc(sizeof(*entry), GFP_NOWAIT);
+ entry = kmalloc_obj(*entry, GFP_NOWAIT);
if (!entry)
break;
diff --git a/drivers/sh/maple/maple.c b/drivers/sh/maple/maple.c
index 6dc0549f7900..c9c3ba77653a 100644
--- a/drivers/sh/maple/maple.c
+++ b/drivers/sh/maple/maple.c
@@ -187,7 +187,7 @@ static struct mapleq *maple_allocq(struct maple_device *mdev)
{
struct mapleq *mq;
- mq = kzalloc(sizeof(*mq), GFP_KERNEL);
+ mq = kzalloc_obj(*mq, GFP_KERNEL);
if (!mq)
goto failed_nomem;
@@ -215,7 +215,7 @@ static struct maple_device *maple_alloc_dev(int port, int unit)
/* zero this out to avoid kobj subsystem
* thinking it has already been registered */
- mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
+ mdev = kzalloc_obj(*mdev, GFP_KERNEL);
if (!mdev)
return NULL;