summaryrefslogtreecommitdiff
path: root/drivers/i3c
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/i3c
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
downloadlinux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz
linux-next-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/i3c')
-rw-r--r--drivers/i3c/master.c15
-rw-r--r--drivers/i3c/master/adi-i3c-master.c6
-rw-r--r--drivers/i3c/master/dw-i3c-master.c6
-rw-r--r--drivers/i3c/master/i3c-master-cdns.c6
-rw-r--r--drivers/i3c/master/mipi-i3c-hci/core.c4
-rw-r--r--drivers/i3c/master/mipi-i3c-hci/dma.c8
-rw-r--r--drivers/i3c/master/mipi-i3c-hci/hci.h2
-rw-r--r--drivers/i3c/master/mipi-i3c-hci/mipi-i3c-hci-pci.c2
-rw-r--r--drivers/i3c/master/mipi-i3c-hci/pio.c2
-rw-r--r--drivers/i3c/master/renesas-i3c.c6
-rw-r--r--drivers/i3c/master/svc-i3c-master.c6
11 files changed, 32 insertions, 31 deletions
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 0eae19b3823d..161eab16d17e 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -858,7 +858,7 @@ i3c_master_alloc_i2c_dev(struct i3c_master_controller *master,
{
struct i2c_dev_desc *dev;
- dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ dev = kzalloc_obj(*dev, GFP_KERNEL);
if (!dev)
return ERR_PTR(-ENOMEM);
@@ -983,7 +983,7 @@ i3c_master_alloc_i3c_dev(struct i3c_master_controller *master,
{
struct i3c_dev_desc *dev;
- dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ dev = kzalloc_obj(*dev, GFP_KERNEL);
if (!dev)
return ERR_PTR(-ENOMEM);
@@ -1742,7 +1742,7 @@ i3c_master_register_new_i3c_devs(struct i3c_master_controller *master)
if (desc->dev || !desc->info.dyn_addr || desc == master->this)
continue;
- desc->dev = kzalloc(sizeof(*desc->dev), GFP_KERNEL);
+ desc->dev = kzalloc_obj(*desc->dev, GFP_KERNEL);
if (!desc->dev)
continue;
@@ -1852,7 +1852,8 @@ struct i3c_dma *i3c_master_dma_map_single(struct device *dev, void *buf,
void *bounce __free(kfree) = NULL;
void *dma_buf = buf;
- struct i3c_dma *dma_xfer __free(kfree) = kzalloc(sizeof(*dma_xfer), GFP_KERNEL);
+ struct i3c_dma *dma_xfer __free(kfree) = kzalloc_obj(*dma_xfer,
+ GFP_KERNEL);
if (!dma_xfer)
return NULL;
@@ -2847,7 +2848,7 @@ i3c_generic_ibi_alloc_pool(struct i3c_dev_desc *dev,
unsigned int i;
int ret;
- pool = kzalloc(sizeof(*pool), GFP_KERNEL);
+ pool = kzalloc_obj(*pool, GFP_KERNEL);
if (!pool)
return ERR_PTR(-ENOMEM);
@@ -2855,7 +2856,7 @@ i3c_generic_ibi_alloc_pool(struct i3c_dev_desc *dev,
INIT_LIST_HEAD(&pool->free_slots);
INIT_LIST_HEAD(&pool->pending);
- pool->slots = kcalloc(req->num_slots, sizeof(*slot), GFP_KERNEL);
+ pool->slots = kzalloc_objs(*slot, req->num_slots, GFP_KERNEL);
if (!pool->slots) {
ret = -ENOMEM;
goto err_free_pool;
@@ -3218,7 +3219,7 @@ int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev,
if (dev->ibi)
return -EBUSY;
- ibi = kzalloc(sizeof(*ibi), GFP_KERNEL);
+ ibi = kzalloc_obj(*ibi, GFP_KERNEL);
if (!ibi)
return -ENOMEM;
diff --git a/drivers/i3c/master/adi-i3c-master.c b/drivers/i3c/master/adi-i3c-master.c
index 6380a38e6d29..e60dc306a03e 100644
--- a/drivers/i3c/master/adi-i3c-master.c
+++ b/drivers/i3c/master/adi-i3c-master.c
@@ -187,7 +187,7 @@ static struct adi_i3c_xfer *adi_i3c_master_alloc_xfer(struct adi_i3c_master *mas
{
struct adi_i3c_xfer *xfer;
- xfer = kzalloc(struct_size(xfer, cmds, ncmds), GFP_KERNEL);
+ xfer = kzalloc_flex(*xfer, cmds, ncmds, GFP_KERNEL);
if (!xfer)
return NULL;
@@ -459,7 +459,7 @@ static int adi_i3c_master_attach_i3c_dev(struct i3c_dev_desc *dev)
int slot;
u8 addr;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return -ENOMEM;
@@ -531,7 +531,7 @@ static int adi_i3c_master_attach_i2c_dev(struct i2c_dev_desc *dev)
if (slot < 0)
return slot;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return -ENOMEM;
diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index 7eb09ad10171..e4740cd07c66 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -382,7 +382,7 @@ dw_i3c_master_alloc_xfer(struct dw_i3c_master *master, unsigned int ncmds)
{
struct dw_i3c_xfer *xfer;
- xfer = kzalloc(struct_size(xfer, cmds, ncmds), GFP_KERNEL);
+ xfer = kzalloc_flex(*xfer, cmds, ncmds, GFP_KERNEL);
if (!xfer)
return NULL;
@@ -1044,7 +1044,7 @@ static int dw_i3c_master_attach_i3c_dev(struct i3c_dev_desc *dev)
if (pos < 0)
return pos;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return -ENOMEM;
@@ -1162,7 +1162,7 @@ static int dw_i3c_master_attach_i2c_dev(struct i2c_dev_desc *dev)
if (pos < 0)
return pos;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return -ENOMEM;
diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c
index 8eb76b8ca2b0..2f31e7ef3ea8 100644
--- a/drivers/i3c/master/i3c-master-cdns.c
+++ b/drivers/i3c/master/i3c-master-cdns.c
@@ -498,7 +498,7 @@ cdns_i3c_master_alloc_xfer(struct cdns_i3c_master *master, unsigned int ncmds)
{
struct cdns_i3c_xfer *xfer;
- xfer = kzalloc(struct_size(xfer, cmds, ncmds), GFP_KERNEL);
+ xfer = kzalloc_flex(*xfer, cmds, ncmds, GFP_KERNEL);
if (!xfer)
return NULL;
@@ -940,7 +940,7 @@ static int cdns_i3c_master_attach_i3c_dev(struct i3c_dev_desc *dev)
struct cdns_i3c_i2c_dev_data *data;
int slot;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return -ENOMEM;
@@ -991,7 +991,7 @@ static int cdns_i3c_master_attach_i2c_dev(struct i2c_dev_desc *dev)
if (slot < 0)
return slot;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return -ENOMEM;
diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
index e925584113d1..a527e7305c09 100644
--- a/drivers/i3c/master/mipi-i3c-hci/core.c
+++ b/drivers/i3c/master/mipi-i3c-hci/core.c
@@ -410,7 +410,7 @@ static int i3c_hci_attach_i3c_dev(struct i3c_dev_desc *dev)
struct i3c_hci_dev_data *dev_data;
int ret;
- dev_data = kzalloc(sizeof(*dev_data), GFP_KERNEL);
+ dev_data = kzalloc_obj(*dev_data, GFP_KERNEL);
if (!dev_data)
return -ENOMEM;
if (hci->cmd == &mipi_i3c_hci_cmd_v1) {
@@ -460,7 +460,7 @@ static int i3c_hci_attach_i2c_dev(struct i2c_dev_desc *dev)
if (hci->cmd != &mipi_i3c_hci_cmd_v1)
return 0;
- dev_data = kzalloc(sizeof(*dev_data), GFP_KERNEL);
+ dev_data = kzalloc_obj(*dev_data, GFP_KERNEL);
if (!dev_data)
return -ENOMEM;
ret = mipi_i3c_hci_dat_v1.alloc_entry(hci);
diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c
index 2e5b4974d431..cdba4c9c839d 100644
--- a/drivers/i3c/master/mipi-i3c-hci/dma.c
+++ b/drivers/i3c/master/mipi-i3c-hci/dma.c
@@ -328,7 +328,7 @@ static int hci_dma_init(struct i3c_hci *hci)
}
if (nr_rings > XFER_RINGS)
nr_rings = XFER_RINGS;
- rings = kzalloc(struct_size(rings, headers, nr_rings), GFP_KERNEL);
+ rings = kzalloc_flex(*rings, headers, nr_rings, GFP_KERNEL);
if (!rings)
return -ENOMEM;
hci->io_data = rings;
@@ -363,8 +363,8 @@ static int hci_dma_init(struct i3c_hci *hci)
rh->resp = dma_alloc_coherent(rings->sysdev, resps_sz,
&rh->resp_dma, GFP_KERNEL);
rh->src_xfers =
- kmalloc_array(rh->xfer_entries, sizeof(*rh->src_xfers),
- GFP_KERNEL);
+ kmalloc_objs(*rh->src_xfers, rh->xfer_entries,
+ GFP_KERNEL);
ret = -ENOMEM;
if (!rh->xfer || !rh->resp || !rh->src_xfers)
goto err_out;
@@ -636,7 +636,7 @@ static int hci_dma_request_ibi(struct i3c_hci *hci, struct i3c_dev_desc *dev,
struct i3c_generic_ibi_pool *pool;
struct hci_dma_dev_ibi_data *dev_ibi;
- dev_ibi = kmalloc(sizeof(*dev_ibi), GFP_KERNEL);
+ dev_ibi = kmalloc_obj(*dev_ibi, GFP_KERNEL);
if (!dev_ibi)
return -ENOMEM;
pool = i3c_generic_ibi_alloc_pool(dev, req);
diff --git a/drivers/i3c/master/mipi-i3c-hci/hci.h b/drivers/i3c/master/mipi-i3c-hci/hci.h
index 6035f74212db..7d57ebba0c24 100644
--- a/drivers/i3c/master/mipi-i3c-hci/hci.h
+++ b/drivers/i3c/master/mipi-i3c-hci/hci.h
@@ -107,7 +107,7 @@ struct hci_xfer {
static inline struct hci_xfer *hci_alloc_xfer(unsigned int n)
{
- return kcalloc(n, sizeof(struct hci_xfer), GFP_KERNEL);
+ return kzalloc_objs(struct hci_xfer, n, GFP_KERNEL);
}
static inline void hci_free_xfer(struct hci_xfer *xfer, unsigned int n)
diff --git a/drivers/i3c/master/mipi-i3c-hci/mipi-i3c-hci-pci.c b/drivers/i3c/master/mipi-i3c-hci/mipi-i3c-hci-pci.c
index 0f05a15c14c7..4fa3d5cf14d2 100644
--- a/drivers/i3c/master/mipi-i3c-hci/mipi-i3c-hci-pci.c
+++ b/drivers/i3c/master/mipi-i3c-hci/mipi-i3c-hci-pci.c
@@ -242,7 +242,7 @@ static void mipi_i3c_hci_pci_setup_cell(struct mipi_i3c_hci_pci *hci, int idx,
cell->resources = &data->res;
}
-#define mipi_i3c_hci_pci_alloc(h, x) kcalloc((h)->info->instance_count, sizeof(*(x)), GFP_KERNEL)
+#define mipi_i3c_hci_pci_alloc(h, x) kzalloc_objs(*(x), (h)->info->instance_count, GFP_KERNEL)
static int mipi_i3c_hci_pci_add_instances(struct mipi_i3c_hci_pci *hci)
{
diff --git a/drivers/i3c/master/mipi-i3c-hci/pio.c b/drivers/i3c/master/mipi-i3c-hci/pio.c
index 8e868e81acda..0c333e40378c 100644
--- a/drivers/i3c/master/mipi-i3c-hci/pio.c
+++ b/drivers/i3c/master/mipi-i3c-hci/pio.c
@@ -977,7 +977,7 @@ static int hci_pio_request_ibi(struct i3c_hci *hci, struct i3c_dev_desc *dev,
struct i3c_generic_ibi_pool *pool;
struct hci_pio_dev_ibi_data *dev_ibi;
- dev_ibi = kmalloc(sizeof(*dev_ibi), GFP_KERNEL);
+ dev_ibi = kmalloc_obj(*dev_ibi, GFP_KERNEL);
if (!dev_ibi)
return -ENOMEM;
pool = i3c_generic_ibi_alloc_pool(dev, req);
diff --git a/drivers/i3c/master/renesas-i3c.c b/drivers/i3c/master/renesas-i3c.c
index 528bccc2c68e..a100bbaabf2d 100644
--- a/drivers/i3c/master/renesas-i3c.c
+++ b/drivers/i3c/master/renesas-i3c.c
@@ -345,7 +345,7 @@ static struct renesas_i3c_xfer *renesas_i3c_alloc_xfer(struct renesas_i3c *i3c,
{
struct renesas_i3c_xfer *xfer;
- xfer = kzalloc(struct_size(xfer, cmds, ncmds), GFP_KERNEL);
+ xfer = kzalloc_flex(*xfer, cmds, ncmds, GFP_KERNEL);
if (!xfer)
return NULL;
@@ -874,7 +874,7 @@ static int renesas_i3c_attach_i3c_dev(struct i3c_dev_desc *dev)
if (pos < 0)
return pos;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return -ENOMEM;
@@ -984,7 +984,7 @@ static int renesas_i3c_attach_i2c_dev(struct i2c_dev_desc *dev)
if (pos < 0)
return pos;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return -ENOMEM;
diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c
index 857504d36e18..0e3b1a7be6a4 100644
--- a/drivers/i3c/master/svc-i3c-master.c
+++ b/drivers/i3c/master/svc-i3c-master.c
@@ -900,7 +900,7 @@ static int svc_i3c_master_attach_i3c_dev(struct i3c_dev_desc *dev)
if (slot < 0)
return slot;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data) {
svc_i3c_master_release_slot(master, slot);
return -ENOMEM;
@@ -953,7 +953,7 @@ static int svc_i3c_master_attach_i2c_dev(struct i2c_dev_desc *dev)
if (slot < 0)
return slot;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data) {
svc_i3c_master_release_slot(master, slot);
return -ENOMEM;
@@ -1504,7 +1504,7 @@ svc_i3c_master_alloc_xfer(struct svc_i3c_master *master, unsigned int ncmds)
{
struct svc_i3c_xfer *xfer;
- xfer = kzalloc(struct_size(xfer, cmds, ncmds), GFP_KERNEL);
+ xfer = kzalloc_flex(*xfer, cmds, ncmds, GFP_KERNEL);
if (!xfer)
return NULL;