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/bus | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (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 'drivers/bus')
| -rw-r--r-- | drivers/bus/arm-cci.c | 2 | ||||
| -rw-r--r-- | drivers/bus/fsl-mc/fsl-mc-bus.c | 7 | ||||
| -rw-r--r-- | drivers/bus/fsl-mc/fsl-mc-uapi.c | 2 | ||||
| -rw-r--r-- | drivers/bus/mhi/ep/main.c | 16 | ||||
| -rw-r--r-- | drivers/bus/mhi/ep/ring.c | 3 | ||||
| -rw-r--r-- | drivers/bus/mhi/host/boot.c | 10 | ||||
| -rw-r--r-- | drivers/bus/mhi/host/init.c | 14 | ||||
| -rw-r--r-- | drivers/bus/mhi/host/pm.c | 2 | ||||
| -rw-r--r-- | drivers/bus/mips_cdmm.c | 4 | ||||
| -rw-r--r-- | drivers/bus/moxtet.c | 2 | ||||
| -rw-r--r-- | drivers/bus/omap_l3_smx.c | 2 | ||||
| -rw-r--r-- | drivers/bus/stm32_firewall.c | 2 | ||||
| -rw-r--r-- | drivers/bus/sunxi-rsb.c | 4 | ||||
| -rw-r--r-- | drivers/bus/ti-sysc.c | 8 | ||||
| -rw-r--r-- | drivers/bus/vexpress-config.c | 2 |
15 files changed, 40 insertions, 40 deletions
diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c index b8184a903583..bc7698cbf5e1 100644 --- a/drivers/bus/arm-cci.c +++ b/drivers/bus/arm-cci.c @@ -451,7 +451,7 @@ static int cci_probe_ports(struct device_node *np) nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite; - ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL); + ports = kzalloc_objs(*ports, nb_cci_ports, GFP_KERNEL); if (!ports) return -ENOMEM; diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c index 290ce13bcb09..3e12cde4443b 100644 --- a/drivers/bus/fsl-mc/fsl-mc-bus.c +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c @@ -672,8 +672,7 @@ static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev, return -EINVAL; } - regions = kmalloc_array(obj_desc->region_count, - sizeof(regions[0]), GFP_KERNEL); + regions = kmalloc_objs(regions[0], obj_desc->region_count, GFP_KERNEL); if (!regions) return -ENOMEM; @@ -788,7 +787,7 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc, /* * Allocate an MC bus device object: */ - mc_bus = kzalloc(sizeof(*mc_bus), GFP_KERNEL); + mc_bus = kzalloc_obj(*mc_bus, GFP_KERNEL); if (!mc_bus) return -ENOMEM; @@ -798,7 +797,7 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc, /* * Allocate a regular fsl_mc_device object: */ - mc_dev = kzalloc(sizeof(*mc_dev), GFP_KERNEL); + mc_dev = kzalloc_obj(*mc_dev, GFP_KERNEL); if (!mc_dev) return -ENOMEM; } diff --git a/drivers/bus/fsl-mc/fsl-mc-uapi.c b/drivers/bus/fsl-mc/fsl-mc-uapi.c index 823969e4159c..db20ea5ade01 100644 --- a/drivers/bus/fsl-mc/fsl-mc-uapi.c +++ b/drivers/bus/fsl-mc/fsl-mc-uapi.c @@ -483,7 +483,7 @@ static int fsl_mc_uapi_dev_open(struct inode *inode, struct file *filep) struct fsl_mc_bus *mc_bus; int error; - priv_data = kzalloc(sizeof(*priv_data), GFP_KERNEL); + priv_data = kzalloc_obj(*priv_data, GFP_KERNEL); if (!priv_data) return -ENOMEM; diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c index 35922e7a24c1..48f76438a138 100644 --- a/drivers/bus/mhi/ep/main.c +++ b/drivers/bus/mhi/ep/main.c @@ -963,7 +963,7 @@ static void mhi_ep_process_ctrl_interrupt(struct mhi_ep_cntrl *mhi_cntrl, { struct mhi_ep_state_transition *item; - item = kzalloc(sizeof(*item), GFP_ATOMIC); + item = kzalloc_obj(*item, GFP_ATOMIC); if (!item) return; @@ -1136,9 +1136,8 @@ int mhi_ep_power_up(struct mhi_ep_cntrl *mhi_cntrl) mhi_ep_mmio_mask_interrupts(mhi_cntrl); mhi_ep_mmio_init(mhi_cntrl); - mhi_cntrl->mhi_event = kcalloc(mhi_cntrl->event_rings, - sizeof(*mhi_cntrl->mhi_event), - GFP_KERNEL); + mhi_cntrl->mhi_event = kzalloc_objs(*mhi_cntrl->mhi_event, + mhi_cntrl->event_rings, GFP_KERNEL); if (!mhi_cntrl->mhi_event) return -ENOMEM; @@ -1276,7 +1275,7 @@ static struct mhi_ep_device *mhi_ep_alloc_device(struct mhi_ep_cntrl *mhi_cntrl, struct mhi_ep_device *mhi_dev; struct device *dev; - mhi_dev = kzalloc(sizeof(*mhi_dev), GFP_KERNEL); + mhi_dev = kzalloc_obj(*mhi_dev, GFP_KERNEL); if (!mhi_dev) return ERR_PTR(-ENOMEM); @@ -1400,8 +1399,8 @@ static int mhi_ep_chan_init(struct mhi_ep_cntrl *mhi_cntrl, * Allocate max_channels supported by the MHI endpoint and populate * only the defined channels */ - mhi_cntrl->mhi_chan = kcalloc(mhi_cntrl->max_chan, sizeof(*mhi_cntrl->mhi_chan), - GFP_KERNEL); + mhi_cntrl->mhi_chan = kzalloc_objs(*mhi_cntrl->mhi_chan, + mhi_cntrl->max_chan, GFP_KERNEL); if (!mhi_cntrl->mhi_chan) return -ENOMEM; @@ -1460,7 +1459,8 @@ int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl, if (ret) return ret; - mhi_cntrl->mhi_cmd = kcalloc(NR_OF_CMD_RINGS, sizeof(*mhi_cntrl->mhi_cmd), GFP_KERNEL); + mhi_cntrl->mhi_cmd = kzalloc_objs(*mhi_cntrl->mhi_cmd, NR_OF_CMD_RINGS, + GFP_KERNEL); if (!mhi_cntrl->mhi_cmd) { ret = -ENOMEM; goto err_free_ch; diff --git a/drivers/bus/mhi/ep/ring.c b/drivers/bus/mhi/ep/ring.c index 26357ee68dee..ee5b7f4755c5 100644 --- a/drivers/bus/mhi/ep/ring.c +++ b/drivers/bus/mhi/ep/ring.c @@ -205,7 +205,8 @@ int mhi_ep_ring_start(struct mhi_ep_cntrl *mhi_cntrl, struct mhi_ep_ring *ring, ring->wr_offset = mhi_ep_ring_addr2offset(ring, le64_to_cpu(val)); /* Allocate ring cache memory for holding the copy of host ring */ - ring->ring_cache = kcalloc(ring->ring_size, sizeof(struct mhi_ring_element), GFP_KERNEL); + ring->ring_cache = kzalloc_objs(struct mhi_ring_element, + ring->ring_size, GFP_KERNEL); if (!ring->ring_cache) return -ENOMEM; diff --git a/drivers/bus/mhi/host/boot.c b/drivers/bus/mhi/host/boot.c index c76db35bc29a..b295992476e4 100644 --- a/drivers/bus/mhi/host/boot.c +++ b/drivers/bus/mhi/host/boot.c @@ -333,12 +333,12 @@ static int mhi_alloc_bhi_buffer(struct mhi_controller *mhi_cntrl, struct image_info *img_info; struct mhi_buf *mhi_buf; - img_info = kzalloc(sizeof(*img_info), GFP_KERNEL); + img_info = kzalloc_obj(*img_info, GFP_KERNEL); if (!img_info) return -ENOMEM; /* Allocate memory for entry */ - img_info->mhi_buf = kzalloc(sizeof(*img_info->mhi_buf), GFP_KERNEL); + img_info->mhi_buf = kzalloc_obj(*img_info->mhi_buf, GFP_KERNEL); if (!img_info->mhi_buf) goto error_alloc_mhi_buf; @@ -375,13 +375,13 @@ int mhi_alloc_bhie_table(struct mhi_controller *mhi_cntrl, struct image_info *img_info; struct mhi_buf *mhi_buf; - img_info = kzalloc(sizeof(*img_info), GFP_KERNEL); + img_info = kzalloc_obj(*img_info, GFP_KERNEL); if (!img_info) return -ENOMEM; /* Allocate memory for entries */ - img_info->mhi_buf = kcalloc(segments, sizeof(*img_info->mhi_buf), - GFP_KERNEL); + img_info->mhi_buf = kzalloc_objs(*img_info->mhi_buf, segments, + GFP_KERNEL); if (!img_info->mhi_buf) goto error_alloc_mhi_buf; diff --git a/drivers/bus/mhi/host/init.c b/drivers/bus/mhi/host/init.c index c47f66833cda..fa62f8219510 100644 --- a/drivers/bus/mhi/host/init.c +++ b/drivers/bus/mhi/host/init.c @@ -313,7 +313,7 @@ static int mhi_init_dev_ctxt(struct mhi_controller *mhi_cntrl) atomic_set(&mhi_cntrl->dev_wake, 0); atomic_set(&mhi_cntrl->pending_pkts, 0); - mhi_ctxt = kzalloc(sizeof(*mhi_ctxt), GFP_KERNEL); + mhi_ctxt = kzalloc_obj(*mhi_ctxt, GFP_KERNEL); if (!mhi_ctxt) return -ENOMEM; @@ -699,8 +699,8 @@ static int parse_ev_cfg(struct mhi_controller *mhi_cntrl, num = config->num_events; mhi_cntrl->total_ev_rings = num; - mhi_cntrl->mhi_event = kcalloc(num, sizeof(*mhi_cntrl->mhi_event), - GFP_KERNEL); + mhi_cntrl->mhi_event = kzalloc_objs(*mhi_cntrl->mhi_event, num, + GFP_KERNEL); if (!mhi_cntrl->mhi_event) return -ENOMEM; @@ -938,8 +938,8 @@ int mhi_register_controller(struct mhi_controller *mhi_cntrl, if (ret) return -EINVAL; - mhi_cntrl->mhi_cmd = kcalloc(NR_OF_CMD_RINGS, - sizeof(*mhi_cntrl->mhi_cmd), GFP_KERNEL); + mhi_cntrl->mhi_cmd = kzalloc_objs(*mhi_cntrl->mhi_cmd, NR_OF_CMD_RINGS, + GFP_KERNEL); if (!mhi_cntrl->mhi_cmd) { ret = -ENOMEM; goto err_free_event; @@ -1095,7 +1095,7 @@ struct mhi_controller *mhi_alloc_controller(void) { struct mhi_controller *mhi_cntrl; - mhi_cntrl = kzalloc(sizeof(*mhi_cntrl), GFP_KERNEL); + mhi_cntrl = kzalloc_obj(*mhi_cntrl, GFP_KERNEL); return mhi_cntrl; } @@ -1232,7 +1232,7 @@ struct mhi_device *mhi_alloc_device(struct mhi_controller *mhi_cntrl) struct mhi_device *mhi_dev; struct device *dev; - mhi_dev = kzalloc(sizeof(*mhi_dev), GFP_KERNEL); + mhi_dev = kzalloc_obj(*mhi_dev, GFP_KERNEL); if (!mhi_dev) return ERR_PTR(-ENOMEM); diff --git a/drivers/bus/mhi/host/pm.c b/drivers/bus/mhi/host/pm.c index b4ef115189b5..f799503c8f36 100644 --- a/drivers/bus/mhi/host/pm.c +++ b/drivers/bus/mhi/host/pm.c @@ -764,7 +764,7 @@ exit_sys_error_transition: int mhi_queue_state_transition(struct mhi_controller *mhi_cntrl, enum dev_st_transition state) { - struct state_transition *item = kmalloc(sizeof(*item), GFP_ATOMIC); + struct state_transition *item = kmalloc_obj(*item, GFP_ATOMIC); unsigned long flags; if (!item) diff --git a/drivers/bus/mips_cdmm.c b/drivers/bus/mips_cdmm.c index 12dd32fd0b62..7d43ecc9d2fa 100644 --- a/drivers/bus/mips_cdmm.c +++ b/drivers/bus/mips_cdmm.c @@ -306,7 +306,7 @@ static struct mips_cdmm_bus *mips_cdmm_get_bus(void) bus = *bus_p; /* Attempt allocation if NULL */ if (unlikely(!bus)) { - bus = kzalloc(sizeof(*bus), GFP_ATOMIC); + bus = kzalloc_obj(*bus, GFP_ATOMIC); if (unlikely(!bus)) bus = ERR_PTR(-ENOMEM); else @@ -541,7 +541,7 @@ static void mips_cdmm_bus_discover(struct mips_cdmm_bus *bus) (drb + size + 1) * CDMM_DRB_SIZE - 1, type, rev); - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + dev = kzalloc_obj(*dev, GFP_KERNEL); if (!dev) break; diff --git a/drivers/bus/moxtet.c b/drivers/bus/moxtet.c index 5a53bfab470a..e7caa6b63318 100644 --- a/drivers/bus/moxtet.c +++ b/drivers/bus/moxtet.c @@ -145,7 +145,7 @@ moxtet_alloc_device(struct moxtet *moxtet) if (!get_device(moxtet->dev)) return NULL; - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + dev = kzalloc_obj(*dev, GFP_KERNEL); if (!dev) { put_device(moxtet->dev); return NULL; diff --git a/drivers/bus/omap_l3_smx.c b/drivers/bus/omap_l3_smx.c index 7f0a8f8b3f4c..63b64da191b1 100644 --- a/drivers/bus/omap_l3_smx.c +++ b/drivers/bus/omap_l3_smx.c @@ -215,7 +215,7 @@ static int omap3_l3_probe(struct platform_device *pdev) struct resource *res; int ret; - l3 = kzalloc(sizeof(*l3), GFP_KERNEL); + l3 = kzalloc_obj(*l3, GFP_KERNEL); if (!l3) return -ENOMEM; diff --git a/drivers/bus/stm32_firewall.c b/drivers/bus/stm32_firewall.c index 2fc9761dadec..aa282083c8cd 100644 --- a/drivers/bus/stm32_firewall.c +++ b/drivers/bus/stm32_firewall.c @@ -260,7 +260,7 @@ int stm32_firewall_populate_bus(struct stm32_firewall_controller *firewall_contr return -EINVAL; } - firewalls = kcalloc(len, sizeof(*firewalls), GFP_KERNEL); + firewalls = kzalloc_objs(*firewalls, len, GFP_KERNEL); if (!firewalls) { of_node_put(child); return -ENOMEM; diff --git a/drivers/bus/sunxi-rsb.c b/drivers/bus/sunxi-rsb.c index 82735c58be11..df9c0a0adfbb 100644 --- a/drivers/bus/sunxi-rsb.c +++ b/drivers/bus/sunxi-rsb.c @@ -205,7 +205,7 @@ static struct sunxi_rsb_device *sunxi_rsb_device_create(struct sunxi_rsb *rsb, int err; struct sunxi_rsb_device *rdev; - rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); + rdev = kzalloc_obj(*rdev, GFP_KERNEL); if (!rdev) return ERR_PTR(-ENOMEM); @@ -477,7 +477,7 @@ static struct sunxi_rsb_ctx *regmap_sunxi_rsb_init_ctx(struct sunxi_rsb_device * return ERR_PTR(-EINVAL); } - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); + ctx = kzalloc_obj(*ctx, GFP_KERNEL); if (!ctx) return ERR_PTR(-ENOMEM); diff --git a/drivers/bus/ti-sysc.c b/drivers/bus/ti-sysc.c index 610354ce7f8f..931948d05a03 100644 --- a/drivers/bus/ti-sysc.c +++ b/drivers/bus/ti-sysc.c @@ -354,7 +354,7 @@ static int sysc_add_named_clock_from_child(struct sysc *ddata, * limit for clk_get(). If cl ever needs to be freed, it should be done * with clkdev_drop(). */ - cl = kzalloc(sizeof(*cl), GFP_KERNEL); + cl = kzalloc_obj(*cl, GFP_KERNEL); if (!cl) return -ENOMEM; @@ -2470,7 +2470,7 @@ static void sysc_add_restored(struct sysc *ddata) { struct sysc_module *restored_module; - restored_module = kzalloc(sizeof(*restored_module), GFP_KERNEL); + restored_module = kzalloc_obj(*restored_module, GFP_KERNEL); if (!restored_module) return; @@ -2953,7 +2953,7 @@ static int sysc_add_disabled(unsigned long base) { struct sysc_address *disabled_module; - disabled_module = kzalloc(sizeof(*disabled_module), GFP_KERNEL); + disabled_module = kzalloc_obj(*disabled_module, GFP_KERNEL); if (!disabled_module) return -ENOMEM; @@ -2984,7 +2984,7 @@ static int sysc_init_static_data(struct sysc *ddata) if (sysc_soc) return 0; - sysc_soc = kzalloc(sizeof(*sysc_soc), GFP_KERNEL); + sysc_soc = kzalloc_obj(*sysc_soc, GFP_KERNEL); if (!sysc_soc) return -ENOMEM; diff --git a/drivers/bus/vexpress-config.c b/drivers/bus/vexpress-config.c index 64ee920721ee..074918ed86fd 100644 --- a/drivers/bus/vexpress-config.c +++ b/drivers/bus/vexpress-config.c @@ -284,7 +284,7 @@ static struct regmap *vexpress_syscfg_regmap_init(struct device *dev, val = energy_quirk; } - func = kzalloc(struct_size(func, template, num), GFP_KERNEL); + func = kzalloc_flex(*func, template, num, GFP_KERNEL); if (!func) return ERR_PTR(-ENOMEM); |
