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/mmc | |
| 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/mmc')
| -rw-r--r-- | drivers/mmc/core/block.c | 12 | ||||
| -rw-r--r-- | drivers/mmc/core/bus.c | 2 | ||||
| -rw-r--r-- | drivers/mmc/core/mmc_test.c | 19 | ||||
| -rw-r--r-- | drivers/mmc/core/queue.c | 2 | ||||
| -rw-r--r-- | drivers/mmc/core/sdio_bus.c | 2 | ||||
| -rw-r--r-- | drivers/mmc/core/sdio_uart.c | 2 | ||||
| -rw-r--r-- | drivers/mmc/host/dw_mmc-rockchip.c | 3 | ||||
| -rw-r--r-- | drivers/mmc/host/dw_mmc.c | 2 | ||||
| -rw-r--r-- | drivers/mmc/host/mmc_spi.c | 2 | ||||
| -rw-r--r-- | drivers/mmc/host/of_mmc_spi.c | 2 | ||||
| -rw-r--r-- | drivers/mmc/host/ushc.c | 6 |
11 files changed, 26 insertions, 28 deletions
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index fb6eb2d79b4f..b39cd61cea44 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -422,7 +422,7 @@ static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user( struct mmc_blk_ioc_data *idata; int err; - idata = kzalloc(sizeof(*idata), GFP_KERNEL); + idata = kzalloc_obj(*idata, GFP_KERNEL); if (!idata) { err = -ENOMEM; goto out; @@ -737,7 +737,7 @@ static int mmc_blk_ioctl_multi_cmd(struct mmc_blk_data *md, return -EINVAL; n = num_of_cmds; - idata = kcalloc(n, sizeof(*idata), GFP_KERNEL); + idata = kzalloc_objs(*idata, n, GFP_KERNEL); if (!idata) return -ENOMEM; @@ -2562,7 +2562,7 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, return ERR_PTR(devidx); } - md = kzalloc(sizeof(*md), GFP_KERNEL); + md = kzalloc_obj(*md, GFP_KERNEL); if (!md) { ret = -ENOMEM; goto out; @@ -2794,12 +2794,12 @@ static struct mmc_blk_ioc_data **alloc_idata(struct mmc_rpmb_data *rpmb, struct mmc_blk_ioc_data **idata; unsigned int n; - idata = kcalloc(cmd_count, sizeof(*idata), GFP_KERNEL); + idata = kzalloc_objs(*idata, cmd_count, GFP_KERNEL); if (!idata) return NULL; for (n = 0; n < cmd_count; n++) { - idata[n] = kcalloc(1, sizeof(**idata), GFP_KERNEL); + idata[n] = kzalloc_objs(**idata, 1, GFP_KERNEL); if (!idata[n]) { free_idata(idata, n); return NULL; @@ -2942,7 +2942,7 @@ static int mmc_blk_alloc_rpmb_part(struct mmc_card *card, if (devidx < 0) return devidx; - rpmb = kzalloc(sizeof(*rpmb), GFP_KERNEL); + rpmb = kzalloc_obj(*rpmb, GFP_KERNEL); if (!rpmb) { ida_free(&mmc_rpmb_ida, devidx); return -ENOMEM; diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c index ec4f3462bf80..740b082da3e2 100644 --- a/drivers/mmc/core/bus.c +++ b/drivers/mmc/core/bus.c @@ -279,7 +279,7 @@ struct mmc_card *mmc_alloc_card(struct mmc_host *host, const struct device_type { struct mmc_card *card; - card = kzalloc(sizeof(struct mmc_card), GFP_KERNEL); + card = kzalloc_obj(struct mmc_card, GFP_KERNEL); if (!card) return ERR_PTR(-ENOMEM); diff --git a/drivers/mmc/core/mmc_test.c b/drivers/mmc/core/mmc_test.c index 01d1e62c2ce7..70cc83a8a1ee 100644 --- a/drivers/mmc/core/mmc_test.c +++ b/drivers/mmc/core/mmc_test.c @@ -348,11 +348,11 @@ static struct mmc_test_mem *mmc_test_alloc_mem(unsigned long min_sz, if (max_segs > max_page_cnt) max_segs = max_page_cnt; - mem = kzalloc(sizeof(*mem), GFP_KERNEL); + mem = kzalloc_obj(*mem, GFP_KERNEL); if (!mem) return NULL; - mem->arr = kcalloc(max_segs, sizeof(*mem->arr), GFP_KERNEL); + mem->arr = kzalloc_objs(*mem->arr, max_segs, GFP_KERNEL); if (!mem->arr) goto out_free; @@ -533,7 +533,7 @@ static void mmc_test_save_transfer_result(struct mmc_test_card *test, if (!test->gr) return; - tr = kmalloc(sizeof(*tr), GFP_KERNEL); + tr = kmalloc_obj(*tr, GFP_KERNEL); if (!tr) return; @@ -765,7 +765,7 @@ static void mmc_test_req_reset(struct mmc_test_req *rq) static struct mmc_test_req *mmc_test_req_alloc(void) { - struct mmc_test_req *rq = kmalloc(sizeof(*rq), GFP_KERNEL); + struct mmc_test_req *rq = kmalloc_obj(*rq, GFP_KERNEL); if (rq) mmc_test_req_reset(rq); @@ -1570,14 +1570,13 @@ static int mmc_test_area_init(struct mmc_test_card *test, int erase, int fill) if (!t->mem) return -ENOMEM; - t->sg = kmalloc_array(t->max_segs, sizeof(*t->sg), GFP_KERNEL); + t->sg = kmalloc_objs(*t->sg, t->max_segs, GFP_KERNEL); if (!t->sg) { ret = -ENOMEM; goto out_free; } - t->sg_areq = kmalloc_array(t->max_segs, sizeof(*t->sg_areq), - GFP_KERNEL); + t->sg_areq = kmalloc_objs(*t->sg_areq, t->max_segs, GFP_KERNEL); if (!t->sg_areq) { ret = -ENOMEM; goto out_free; @@ -2968,7 +2967,7 @@ static void mmc_test_run(struct mmc_test_card *test, int testcase) } } - gr = kzalloc(sizeof(*gr), GFP_KERNEL); + gr = kzalloc_obj(*gr, GFP_KERNEL); if (gr) { INIT_LIST_HEAD(&gr->tr_lst); @@ -3100,7 +3099,7 @@ static ssize_t mtf_test_write(struct file *file, const char __user *buf, if (ret) return ret; - test = kzalloc(sizeof(*test), GFP_KERNEL); + test = kzalloc_obj(*test, GFP_KERNEL); if (!test) return -ENOMEM; @@ -3189,7 +3188,7 @@ static int __mmc_test_register_dbgfs_file(struct mmc_card *card, file = debugfs_create_file(name, mode, card->debugfs_root, card, fops); - df = kmalloc(sizeof(*df), GFP_KERNEL); + df = kmalloc_obj(*df, GFP_KERNEL); if (!df) { debugfs_remove(file); return -ENOMEM; diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c index 284856c8f655..13000fc57e2e 100644 --- a/drivers/mmc/core/queue.c +++ b/drivers/mmc/core/queue.c @@ -167,7 +167,7 @@ static struct scatterlist *mmc_alloc_sg(unsigned short sg_len, gfp_t gfp) { struct scatterlist *sg; - sg = kmalloc_array(sg_len, sizeof(*sg), gfp); + sg = kmalloc_objs(*sg, sg_len, gfp); if (sg) sg_init_table(sg, sg_len); diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c index 6e5bdc2f0cc8..060da5c4ea75 100644 --- a/drivers/mmc/core/sdio_bus.c +++ b/drivers/mmc/core/sdio_bus.c @@ -337,7 +337,7 @@ struct sdio_func *sdio_alloc_func(struct mmc_card *card) { struct sdio_func *func; - func = kzalloc(sizeof(struct sdio_func), GFP_KERNEL); + func = kzalloc_obj(struct sdio_func, GFP_KERNEL); if (!func) return ERR_PTR(-ENOMEM); diff --git a/drivers/mmc/core/sdio_uart.c b/drivers/mmc/core/sdio_uart.c index 7423a601e1e5..a37d91347931 100644 --- a/drivers/mmc/core/sdio_uart.c +++ b/drivers/mmc/core/sdio_uart.c @@ -1021,7 +1021,7 @@ static int sdio_uart_probe(struct sdio_func *func, struct sdio_uart_port *port; int ret; - port = kzalloc(sizeof(struct sdio_uart_port), GFP_KERNEL); + port = kzalloc_obj(struct sdio_uart_port, GFP_KERNEL); if (!port) return -ENOMEM; diff --git a/drivers/mmc/host/dw_mmc-rockchip.c b/drivers/mmc/host/dw_mmc-rockchip.c index 62c68cda1e21..2a2aee4054f7 100644 --- a/drivers/mmc/host/dw_mmc-rockchip.c +++ b/drivers/mmc/host/dw_mmc-rockchip.c @@ -306,8 +306,7 @@ static int dw_mci_rk3288_execute_tuning(struct dw_mci_slot *slot, u32 opcode) return -EIO; } - ranges = kmalloc_array(priv->num_phases / 2 + 1, - sizeof(*ranges), GFP_KERNEL); + ranges = kmalloc_objs(*ranges, priv->num_phases / 2 + 1, GFP_KERNEL); if (!ranges) return -ENOMEM; diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 9e74b675e92d..1e0c3904cded 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -834,7 +834,7 @@ static int dw_mci_edmac_start_dma(struct dw_mci *host, static int dw_mci_edmac_init(struct dw_mci *host) { /* Request external dma channel */ - host->dms = kzalloc(sizeof(struct dw_mci_dma_slave), GFP_KERNEL); + host->dms = kzalloc_obj(struct dw_mci_dma_slave, GFP_KERNEL); if (!host->dms) return -ENOMEM; diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c index 42936e248c55..8ab52b4de02e 100644 --- a/drivers/mmc/host/mmc_spi.c +++ b/drivers/mmc/host/mmc_spi.c @@ -1236,7 +1236,7 @@ static int mmc_spi_probe(struct spi_device *spi) } /* Preallocate buffers */ - host->data = kmalloc(sizeof(*host->data), GFP_KERNEL); + host->data = kmalloc_obj(*host->data, GFP_KERNEL); if (!host->data) goto fail_nobuf1; diff --git a/drivers/mmc/host/of_mmc_spi.c b/drivers/mmc/host/of_mmc_spi.c index 05939f30a5ae..d3137d23533c 100644 --- a/drivers/mmc/host/of_mmc_spi.c +++ b/drivers/mmc/host/of_mmc_spi.c @@ -57,7 +57,7 @@ struct mmc_spi_platform_data *mmc_spi_get_pdata(struct spi_device *spi) if (dev->platform_data || !dev_fwnode(dev)) return dev->platform_data; - oms = kzalloc(sizeof(*oms), GFP_KERNEL); + oms = kzalloc_obj(*oms, GFP_KERNEL); if (!oms) return NULL; diff --git a/drivers/mmc/host/ushc.c b/drivers/mmc/host/ushc.c index 2b7456e942f7..6a4274bac5c0 100644 --- a/drivers/mmc/host/ushc.c +++ b/drivers/mmc/host/ushc.c @@ -462,7 +462,7 @@ static int ushc_probe(struct usb_interface *intf, const struct usb_device_id *id ret = -ENOMEM; goto err; } - ushc->int_data = kzalloc(sizeof(struct ushc_int_data), GFP_KERNEL); + ushc->int_data = kzalloc_obj(struct ushc_int_data, GFP_KERNEL); if (ushc->int_data == NULL) { ret = -ENOMEM; goto err; @@ -479,7 +479,7 @@ static int ushc_probe(struct usb_interface *intf, const struct usb_device_id *id ret = -ENOMEM; goto err; } - ushc->cbw = kzalloc(sizeof(struct ushc_cbw), GFP_KERNEL); + ushc->cbw = kzalloc_obj(struct ushc_cbw, GFP_KERNEL); if (ushc->cbw == NULL) { ret = -ENOMEM; goto err; @@ -501,7 +501,7 @@ static int ushc_probe(struct usb_interface *intf, const struct usb_device_id *id ret = -ENOMEM; goto err; } - ushc->csw = kzalloc(sizeof(struct ushc_csw), GFP_KERNEL); + ushc->csw = kzalloc_obj(struct ushc_csw, GFP_KERNEL); if (ushc->csw == NULL) { ret = -ENOMEM; goto err; |
