summaryrefslogtreecommitdiff
path: root/arch/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 /arch/sh
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
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 'arch/sh')
-rw-r--r--arch/sh/drivers/dma/dmabrg.c3
-rw-r--r--arch/sh/drivers/heartbeat.c2
-rw-r--r--arch/sh/drivers/pci/pcie-sh7786.c4
-rw-r--r--arch/sh/drivers/push-switch.c2
-rw-r--r--arch/sh/kernel/cpu/sh4/sq.c2
-rw-r--r--arch/sh/kernel/dwarf.c4
6 files changed, 8 insertions, 9 deletions
diff --git a/arch/sh/drivers/dma/dmabrg.c b/arch/sh/drivers/dma/dmabrg.c
index 5b2c1fd254d7..72f90f0c799e 100644
--- a/arch/sh/drivers/dma/dmabrg.c
+++ b/arch/sh/drivers/dma/dmabrg.c
@@ -153,8 +153,7 @@ static int __init dmabrg_init(void)
unsigned long or;
int ret;
- dmabrg_handlers = kcalloc(10, sizeof(struct dmabrg_handler),
- GFP_KERNEL);
+ dmabrg_handlers = kzalloc_objs(struct dmabrg_handler, 10, GFP_KERNEL);
if (!dmabrg_handlers)
return -ENOMEM;
diff --git a/arch/sh/drivers/heartbeat.c b/arch/sh/drivers/heartbeat.c
index 42103038a7d0..aae320cef692 100644
--- a/arch/sh/drivers/heartbeat.c
+++ b/arch/sh/drivers/heartbeat.c
@@ -91,7 +91,7 @@ static int heartbeat_drv_probe(struct platform_device *pdev)
if (pdev->dev.platform_data) {
hd = pdev->dev.platform_data;
} else {
- hd = kzalloc(sizeof(struct heartbeat_data), GFP_KERNEL);
+ hd = kzalloc_obj(struct heartbeat_data, GFP_KERNEL);
if (unlikely(!hd))
return -ENOMEM;
}
diff --git a/arch/sh/drivers/pci/pcie-sh7786.c b/arch/sh/drivers/pci/pcie-sh7786.c
index a78b9a935585..1e67082eb3b4 100644
--- a/arch/sh/drivers/pci/pcie-sh7786.c
+++ b/arch/sh/drivers/pci/pcie-sh7786.c
@@ -558,8 +558,8 @@ static int __init sh7786_pcie_init(void)
if (unlikely(nr_ports == 0))
return -ENODEV;
- sh7786_pcie_ports = kcalloc(nr_ports, sizeof(struct sh7786_pcie_port),
- GFP_KERNEL);
+ sh7786_pcie_ports = kzalloc_objs(struct sh7786_pcie_port, nr_ports,
+ GFP_KERNEL);
if (unlikely(!sh7786_pcie_ports))
return -ENOMEM;
diff --git a/arch/sh/drivers/push-switch.c b/arch/sh/drivers/push-switch.c
index 443cc6fd26a8..492315fc96fd 100644
--- a/arch/sh/drivers/push-switch.c
+++ b/arch/sh/drivers/push-switch.c
@@ -46,7 +46,7 @@ static int switch_drv_probe(struct platform_device *pdev)
struct push_switch *psw;
int ret, irq;
- psw = kzalloc(sizeof(struct push_switch), GFP_KERNEL);
+ psw = kzalloc_obj(struct push_switch, GFP_KERNEL);
if (unlikely(!psw))
return -ENOMEM;
diff --git a/arch/sh/kernel/cpu/sh4/sq.c b/arch/sh/kernel/cpu/sh4/sq.c
index d289e99dc118..2a465c440168 100644
--- a/arch/sh/kernel/cpu/sh4/sq.c
+++ b/arch/sh/kernel/cpu/sh4/sq.c
@@ -342,7 +342,7 @@ static int sq_dev_add(struct device *dev, struct subsys_interface *sif)
struct kobject *kobj;
int error;
- sq_kobject[cpu] = kzalloc(sizeof(struct kobject), GFP_KERNEL);
+ sq_kobject[cpu] = kzalloc_obj(struct kobject, GFP_KERNEL);
if (unlikely(!sq_kobject[cpu]))
return -ENOMEM;
diff --git a/arch/sh/kernel/dwarf.c b/arch/sh/kernel/dwarf.c
index a1b54bedc929..46df80942418 100644
--- a/arch/sh/kernel/dwarf.c
+++ b/arch/sh/kernel/dwarf.c
@@ -741,7 +741,7 @@ static int dwarf_parse_cie(void *entry, void *p, unsigned long len,
unsigned long flags;
int count;
- cie = kzalloc(sizeof(*cie), GFP_KERNEL);
+ cie = kzalloc_obj(*cie, GFP_KERNEL);
if (!cie)
return -ENOMEM;
@@ -874,7 +874,7 @@ static int dwarf_parse_fde(void *entry, u32 entry_type,
int count;
void *p = start;
- fde = kzalloc(sizeof(*fde), GFP_KERNEL);
+ fde = kzalloc_obj(*fde, GFP_KERNEL);
if (!fde)
return -ENOMEM;