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 /net/9p | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | linux-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz linux-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.bz2 linux-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 'net/9p')
| -rw-r--r-- | net/9p/client.c | 8 | ||||
| -rw-r--r-- | net/9p/protocol.c | 5 | ||||
| -rw-r--r-- | net/9p/trans_fd.c | 5 | ||||
| -rw-r--r-- | net/9p/trans_rdma.c | 6 | ||||
| -rw-r--r-- | net/9p/trans_usbg.c | 6 | ||||
| -rw-r--r-- | net/9p/trans_virtio.c | 7 | ||||
| -rw-r--r-- | net/9p/trans_xen.c | 5 |
7 files changed, 19 insertions, 23 deletions
diff --git a/net/9p/client.c b/net/9p/client.c index 1b475525ac5b..3e8de85c7f7f 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -730,7 +730,7 @@ static struct p9_fid *p9_fid_create(struct p9_client *clnt) struct p9_fid *fid; p9_debug(P9_DEBUG_FID, "clnt %p\n", clnt); - fid = kzalloc(sizeof(*fid), GFP_KERNEL); + fid = kzalloc_obj(*fid, GFP_KERNEL); if (!fid) return NULL; @@ -859,7 +859,7 @@ struct p9_client *p9_client_create(struct fs_context *fc) char *client_id; char *cache_name; - clnt = kmalloc(sizeof(*clnt), GFP_KERNEL); + clnt = kmalloc_obj(*clnt, GFP_KERNEL); if (!clnt) return ERR_PTR(-ENOMEM); @@ -1615,7 +1615,7 @@ struct p9_wstat *p9_client_stat(struct p9_fid *fid) p9_debug(P9_DEBUG_9P, ">>> TSTAT fid %d\n", fid->fid); - ret = kmalloc(sizeof(*ret), GFP_KERNEL); + ret = kmalloc_obj(*ret, GFP_KERNEL); if (!ret) return ERR_PTR(-ENOMEM); @@ -1667,7 +1667,7 @@ struct p9_stat_dotl *p9_client_getattr_dotl(struct p9_fid *fid, p9_debug(P9_DEBUG_9P, ">>> TGETATTR fid %d, request_mask %lld\n", fid->fid, request_mask); - ret = kmalloc(sizeof(*ret), GFP_KERNEL); + ret = kmalloc_obj(*ret, GFP_KERNEL); if (!ret) return ERR_PTR(-ENOMEM); diff --git a/net/9p/protocol.c b/net/9p/protocol.c index 0e6603b1ec90..67b0586d807f 100644 --- a/net/9p/protocol.c +++ b/net/9p/protocol.c @@ -451,9 +451,8 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, p9pdu_readf(pdu, proto_version, "w", nwqid); if (!errcode) { *wqids = - kmalloc_array(*nwqid, - sizeof(struct p9_qid), - GFP_NOFS); + kmalloc_objs(struct p9_qid, *nwqid, + GFP_NOFS); if (*wqids == NULL) errcode = -ENOMEM; } diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index 0e331c1b2112..4e0f4a382ac4 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -719,8 +719,7 @@ static int p9_fd_show_options(struct seq_file *m, struct p9_client *clnt) static int p9_fd_open(struct p9_client *client, int rfd, int wfd) { - struct p9_trans_fd *ts = kzalloc(sizeof(struct p9_trans_fd), - GFP_KERNEL); + struct p9_trans_fd *ts = kzalloc_obj(struct p9_trans_fd, GFP_KERNEL); if (!ts) return -ENOMEM; @@ -764,7 +763,7 @@ static int p9_socket_open(struct p9_client *client, struct socket *csocket) struct p9_trans_fd *p; struct file *file; - p = kzalloc(sizeof(struct p9_trans_fd), GFP_KERNEL); + p = kzalloc_obj(struct p9_trans_fd, GFP_KERNEL); if (!p) { sock_release(csocket); return -ENOMEM; diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c index 4d406479f83b..c8e27c08a3a2 100644 --- a/net/9p/trans_rdma.c +++ b/net/9p/trans_rdma.c @@ -334,7 +334,7 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req) } /* Allocate an fcall for the reply */ - rpl_context = kmalloc(sizeof *rpl_context, GFP_NOFS); + rpl_context = kmalloc_obj(*rpl_context, GFP_NOFS); if (!rpl_context) { err = -ENOMEM; goto recv_error; @@ -363,7 +363,7 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req) dont_need_post_recv: /* Post the request */ - c = kmalloc(sizeof *c, GFP_NOFS); + c = kmalloc_obj(*c, GFP_NOFS); if (!c) { err = -ENOMEM; goto send_error; @@ -460,7 +460,7 @@ static struct p9_trans_rdma *alloc_rdma(struct p9_rdma_opts *opts) { struct p9_trans_rdma *rdma; - rdma = kzalloc(sizeof(struct p9_trans_rdma), GFP_KERNEL); + rdma = kzalloc_obj(struct p9_trans_rdma, GFP_KERNEL); if (!rdma) return NULL; diff --git a/net/9p/trans_usbg.c b/net/9p/trans_usbg.c index 93547637deae..e167f9f23d65 100644 --- a/net/9p/trans_usbg.c +++ b/net/9p/trans_usbg.c @@ -757,7 +757,7 @@ static struct usb_function *usb9pfs_alloc(struct usb_function_instance *fi) struct f_usb9pfs_opts *usb9pfs_opts; struct f_usb9pfs *usb9pfs; - usb9pfs = kzalloc(sizeof(*usb9pfs), GFP_KERNEL); + usb9pfs = kzalloc_obj(*usb9pfs, GFP_KERNEL); if (!usb9pfs) return ERR_PTR(-ENOMEM); @@ -910,7 +910,7 @@ static struct usb_function_instance *usb9pfs_alloc_instance(void) struct f_usb9pfs_opts *usb9pfs_opts; struct f_usb9pfs_dev *dev; - usb9pfs_opts = kzalloc(sizeof(*usb9pfs_opts), GFP_KERNEL); + usb9pfs_opts = kzalloc_obj(*usb9pfs_opts, GFP_KERNEL); if (!usb9pfs_opts) return ERR_PTR(-ENOMEM); @@ -921,7 +921,7 @@ static struct usb_function_instance *usb9pfs_alloc_instance(void) usb9pfs_opts->buflen = DEFAULT_BUFLEN; - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + dev = kzalloc_obj(*dev, GFP_KERNEL); if (!dev) { kfree(usb9pfs_opts); return ERR_PTR(-ENOMEM); diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index 370f4f37dcec..0577bdcb67bf 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c @@ -358,8 +358,7 @@ static int p9_get_mapped_pages(struct virtio_chan *chan, nr_pages = DIV_ROUND_UP((unsigned long)p + len, PAGE_SIZE) - (unsigned long)p / PAGE_SIZE; - *pages = kmalloc_array(nr_pages, sizeof(struct page *), - GFP_NOFS); + *pages = kmalloc_objs(struct page *, nr_pages, GFP_NOFS); if (!*pages) return -ENOMEM; @@ -602,7 +601,7 @@ static int p9_virtio_probe(struct virtio_device *vdev) return -EINVAL; } - chan = kmalloc(sizeof(struct virtio_chan), GFP_KERNEL); + chan = kmalloc_obj(struct virtio_chan, GFP_KERNEL); if (!chan) { pr_err("Failed to allocate virtio 9P channel\n"); err = -ENOMEM; @@ -642,7 +641,7 @@ static int p9_virtio_probe(struct virtio_device *vdev) if (err) { goto out_free_tag; } - chan->vc_wq = kmalloc(sizeof(wait_queue_head_t), GFP_KERNEL); + chan->vc_wq = kmalloc_obj(wait_queue_head_t, GFP_KERNEL); if (!chan->vc_wq) { err = -ENOMEM; goto out_remove_file; diff --git a/net/9p/trans_xen.c b/net/9p/trans_xen.c index dde9cbf1426c..fd6ac8658549 100644 --- a/net/9p/trans_xen.c +++ b/net/9p/trans_xen.c @@ -417,12 +417,11 @@ static int xen_9pfs_front_init(struct xenbus_device *dev) if (p9_xen_trans.maxsize > XEN_FLEX_RING_SIZE(max_ring_order)) p9_xen_trans.maxsize = XEN_FLEX_RING_SIZE(max_ring_order) / 2; - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = kzalloc_obj(*priv, GFP_KERNEL); if (!priv) return -ENOMEM; priv->dev = dev; - priv->rings = kcalloc(XEN_9PFS_NUM_RINGS, sizeof(*priv->rings), - GFP_KERNEL); + priv->rings = kzalloc_objs(*priv->rings, XEN_9PFS_NUM_RINGS, GFP_KERNEL); if (!priv->rings) { kfree(priv); return -ENOMEM; |
