summaryrefslogtreecommitdiff
path: root/drivers/rapidio
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/rapidio
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/rapidio')
-rw-r--r--drivers/rapidio/devices/rio_mport_cdev.c19
-rw-r--r--drivers/rapidio/devices/tsi721.c4
-rw-r--r--drivers/rapidio/devices/tsi721_dma.c3
-rw-r--r--drivers/rapidio/rio.c18
-rw-r--r--drivers/rapidio/rio_cm.c16
5 files changed, 29 insertions, 31 deletions
diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c
index 995cfeca972b..10277dff206e 100644
--- a/drivers/rapidio/devices/rio_mport_cdev.c
+++ b/drivers/rapidio/devices/rio_mport_cdev.c
@@ -348,7 +348,7 @@ rio_mport_create_outbound_mapping(struct mport_dev *md, struct file *filp,
rmcd_debug(OBW, "did=%d ra=0x%llx sz=0x%x", rioid, raddr, size);
- map = kzalloc(sizeof(*map), GFP_KERNEL);
+ map = kzalloc_obj(*map, GFP_KERNEL);
if (map == NULL)
return -ENOMEM;
@@ -800,7 +800,7 @@ rio_dma_transfer(struct file *filp, u32 transfer_mode,
if (xfer->length == 0)
return -EINVAL;
- req = kzalloc(sizeof(*req), GFP_KERNEL);
+ req = kzalloc_obj(*req, GFP_KERNEL);
if (!req)
return -ENOMEM;
@@ -835,8 +835,7 @@ rio_dma_transfer(struct file *filp, u32 transfer_mode,
offset = lower_32_bits(offset_in_page(xfer->loc_addr));
nr_pages = PAGE_ALIGN(xfer->length + offset) >> PAGE_SHIFT;
- page_list = kmalloc_array(nr_pages,
- sizeof(*page_list), GFP_KERNEL);
+ page_list = kmalloc_objs(*page_list, nr_pages, GFP_KERNEL);
if (page_list == NULL) {
ret = -ENOMEM;
goto err_req;
@@ -1070,7 +1069,7 @@ static int rio_mport_create_dma_mapping(struct mport_dev *md, struct file *filp,
{
struct rio_mport_mapping *map;
- map = kzalloc(sizeof(*map), GFP_KERNEL);
+ map = kzalloc_obj(*map, GFP_KERNEL);
if (map == NULL)
return -ENOMEM;
@@ -1190,7 +1189,7 @@ rio_mport_create_inbound_mapping(struct mport_dev *md, struct file *filp,
if (size > 0xffffffff)
return -EINVAL;
- map = kzalloc(sizeof(*map), GFP_KERNEL);
+ map = kzalloc_obj(*map, GFP_KERNEL);
if (map == NULL)
return -ENOMEM;
@@ -1432,7 +1431,7 @@ static int rio_mport_add_db_filter(struct mport_cdev_priv *priv,
return ret;
}
- db_filter = kzalloc(sizeof(*db_filter), GFP_KERNEL);
+ db_filter = kzalloc_obj(*db_filter, GFP_KERNEL);
if (db_filter == NULL) {
rio_release_inb_dbell(md->mport, filter.low, filter.high);
return -ENOMEM;
@@ -1540,7 +1539,7 @@ static int rio_mport_add_pw_filter(struct mport_cdev_priv *priv,
if (copy_from_user(&filter, arg, sizeof(filter)))
return -EFAULT;
- pw_filter = kzalloc(sizeof(*pw_filter), GFP_KERNEL);
+ pw_filter = kzalloc_obj(*pw_filter, GFP_KERNEL);
if (pw_filter == NULL)
return -ENOMEM;
@@ -1879,7 +1878,7 @@ static int mport_cdev_open(struct inode *inode, struct file *filp)
get_device(&chdev->dev);
- priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+ priv = kzalloc_obj(*priv, GFP_KERNEL);
if (!priv) {
put_device(&chdev->dev);
return -ENOMEM;
@@ -2349,7 +2348,7 @@ static struct mport_dev *mport_cdev_add(struct rio_mport *mport)
struct mport_dev *md;
struct rio_mport_attr attr;
- md = kzalloc(sizeof(*md), GFP_KERNEL);
+ md = kzalloc_obj(*md, GFP_KERNEL);
if (!md) {
rmcd_error("Unable allocate a device object");
return NULL;
diff --git a/drivers/rapidio/devices/tsi721.c b/drivers/rapidio/devices/tsi721.c
index 4b84270a8906..9d3f2577bccb 100644
--- a/drivers/rapidio/devices/tsi721.c
+++ b/drivers/rapidio/devices/tsi721.c
@@ -1145,7 +1145,7 @@ static int tsi721_rio_map_inb_mem(struct rio_mport *mport, dma_addr_t lstart,
loc_start = ibw_start;
- map = kzalloc(sizeof(struct tsi721_ib_win_mapping), GFP_ATOMIC);
+ map = kzalloc_obj(struct tsi721_ib_win_mapping, GFP_ATOMIC);
if (map == NULL)
return -ENOMEM;
@@ -2774,7 +2774,7 @@ static int tsi721_probe(struct pci_dev *pdev,
struct tsi721_device *priv;
int err;
- priv = kzalloc(sizeof(struct tsi721_device), GFP_KERNEL);
+ priv = kzalloc_obj(struct tsi721_device, GFP_KERNEL);
if (!priv) {
err = -ENOMEM;
goto err_exit;
diff --git a/drivers/rapidio/devices/tsi721_dma.c b/drivers/rapidio/devices/tsi721_dma.c
index f77f75172bdc..52749f1d2a11 100644
--- a/drivers/rapidio/devices/tsi721_dma.c
+++ b/drivers/rapidio/devices/tsi721_dma.c
@@ -739,8 +739,7 @@ static int tsi721_alloc_chan_resources(struct dma_chan *dchan)
}
/* Allocate queue of transaction descriptors */
- desc = kcalloc(dma_txqueue_sz, sizeof(struct tsi721_tx_desc),
- GFP_ATOMIC);
+ desc = kzalloc_objs(struct tsi721_tx_desc, dma_txqueue_sz, GFP_ATOMIC);
if (!desc) {
tsi721_bdma_ch_free(bdma_chan);
return -ENOMEM;
diff --git a/drivers/rapidio/rio.c b/drivers/rapidio/rio.c
index 46daf32ea13b..c811cc3ebc5d 100644
--- a/drivers/rapidio/rio.c
+++ b/drivers/rapidio/rio.c
@@ -107,7 +107,7 @@ EXPORT_SYMBOL(rio_query_mport);
*/
struct rio_net *rio_alloc_net(struct rio_mport *mport)
{
- struct rio_net *net = kzalloc(sizeof(*net), GFP_KERNEL);
+ struct rio_net *net = kzalloc_obj(*net, GFP_KERNEL);
if (net) {
INIT_LIST_HEAD(&net->node);
@@ -242,7 +242,7 @@ int rio_request_inb_mbox(struct rio_mport *mport,
if (!mport->ops->open_inb_mbox)
goto out;
- res = kzalloc(sizeof(*res), GFP_KERNEL);
+ res = kzalloc_obj(*res, GFP_KERNEL);
if (res) {
rio_init_mbox_res(res, mbox, mbox);
@@ -326,7 +326,7 @@ int rio_request_outb_mbox(struct rio_mport *mport,
if (!mport->ops->open_outb_mbox)
goto out;
- res = kzalloc(sizeof(*res), GFP_KERNEL);
+ res = kzalloc_obj(*res, GFP_KERNEL);
if (res) {
rio_init_mbox_res(res, mbox, mbox);
@@ -403,7 +403,7 @@ rio_setup_inb_dbell(struct rio_mport *mport, void *dev_id, struct resource *res,
void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src, u16 dst,
u16 info))
{
- struct rio_dbell *dbell = kmalloc(sizeof(*dbell), GFP_KERNEL);
+ struct rio_dbell *dbell = kmalloc_obj(*dbell, GFP_KERNEL);
if (!dbell)
return -ENOMEM;
@@ -438,7 +438,7 @@ int rio_request_inb_dbell(struct rio_mport *mport,
u16 dst, u16 info))
{
int rc;
- struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL);
+ struct resource *res = kzalloc_obj(*res, GFP_KERNEL);
if (res) {
rio_init_dbell_res(res, start, end);
@@ -515,7 +515,7 @@ EXPORT_SYMBOL_GPL(rio_release_inb_dbell);
struct resource *rio_request_outb_dbell(struct rio_dev *rdev, u16 start,
u16 end)
{
- struct resource *res = kzalloc(sizeof(struct resource), GFP_KERNEL);
+ struct resource *res = kzalloc_obj(struct resource, GFP_KERNEL);
if (res) {
rio_init_dbell_res(res, start, end);
@@ -563,7 +563,7 @@ int rio_add_mport_pw_handler(struct rio_mport *mport, void *context,
int (*pwcback)(struct rio_mport *mport,
void *context, union rio_pw_msg *msg, int step))
{
- struct rio_pwrite *pwrite = kzalloc(sizeof(*pwrite), GFP_KERNEL);
+ struct rio_pwrite *pwrite = kzalloc_obj(*pwrite, GFP_KERNEL);
if (!pwrite)
return -ENOMEM;
@@ -1865,7 +1865,7 @@ int rio_register_scan(int mport_id, struct rio_scan *scan_ops)
/*
* Allocate and initialize new scan registration node.
*/
- scan = kzalloc(sizeof(*scan), GFP_KERNEL);
+ scan = kzalloc_obj(*scan, GFP_KERNEL);
if (!scan) {
rc = -ENOMEM;
goto err_out;
@@ -2000,7 +2000,7 @@ int rio_init_mports(void)
goto no_disc;
}
- work = kcalloc(n, sizeof *work, GFP_KERNEL);
+ work = kzalloc_objs(*work, n, GFP_KERNEL);
if (!work) {
destroy_workqueue(rio_wq);
goto no_disc;
diff --git a/drivers/rapidio/rio_cm.c b/drivers/rapidio/rio_cm.c
index 66464674223f..d01c749de5fd 100644
--- a/drivers/rapidio/rio_cm.c
+++ b/drivers/rapidio/rio_cm.c
@@ -389,7 +389,7 @@ static int riocm_req_handler(struct cm_dev *cm, void *req_data)
return -EINVAL;
}
- req = kzalloc(sizeof(*req), GFP_KERNEL);
+ req = kzalloc_obj(*req, GFP_KERNEL);
if (!req) {
riocm_put_channel(ch);
return -ENOMEM;
@@ -702,7 +702,7 @@ static int riocm_queue_req(struct cm_dev *cm, struct rio_dev *rdev,
unsigned long flags;
struct tx_req *treq;
- treq = kzalloc(sizeof(*treq), GFP_KERNEL);
+ treq = kzalloc_obj(*treq, GFP_KERNEL);
if (treq == NULL)
return -ENOMEM;
@@ -965,7 +965,7 @@ static int riocm_ch_connect(u16 loc_ch, struct cm_dev *cm,
* Send connect request to the remote RapidIO device
*/
- hdr = kzalloc(sizeof(*hdr), GFP_KERNEL);
+ hdr = kzalloc_obj(*hdr, GFP_KERNEL);
if (hdr == NULL) {
ret = -ENOMEM;
goto conn_done;
@@ -1022,7 +1022,7 @@ static int riocm_send_ack(struct rio_channel *ch)
struct rio_ch_chan_hdr *hdr;
int ret;
- hdr = kzalloc(sizeof(*hdr), GFP_KERNEL);
+ hdr = kzalloc_obj(*hdr, GFP_KERNEL);
if (hdr == NULL)
return -ENOMEM;
@@ -1283,7 +1283,7 @@ static struct rio_channel *riocm_ch_alloc(u16 ch_num)
int start, end;
struct rio_channel *ch;
- ch = kzalloc(sizeof(*ch), GFP_KERNEL);
+ ch = kzalloc_obj(*ch, GFP_KERNEL);
if (!ch)
return ERR_PTR(-ENOMEM);
@@ -1396,7 +1396,7 @@ static int riocm_send_close(struct rio_channel *ch)
* Send CH_CLOSE notification to the remote RapidIO device
*/
- hdr = kzalloc(sizeof(*hdr), GFP_KERNEL);
+ hdr = kzalloc_obj(*hdr, GFP_KERNEL);
if (hdr == NULL)
return -ENOMEM;
@@ -1952,7 +1952,7 @@ static int riocm_add_dev(struct device *dev, struct subsys_interface *sif)
riocm_debug(RDEV, "(%s)", rio_name(rdev));
- peer = kmalloc(sizeof(*peer), GFP_KERNEL);
+ peer = kmalloc_obj(*peer, GFP_KERNEL);
if (!peer)
return -ENOMEM;
@@ -2099,7 +2099,7 @@ static int riocm_add_mport(struct device *dev)
riocm_debug(MPORT, "add mport %s", mport->name);
- cm = kzalloc(sizeof(*cm), GFP_KERNEL);
+ cm = kzalloc_obj(*cm, GFP_KERNEL);
if (!cm)
return -ENOMEM;