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/rds/rdma.c | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | linux-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 'net/rds/rdma.c')
| -rw-r--r-- | net/rds/rdma.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/net/rds/rdma.c b/net/rds/rdma.c index 00dbcd4d28e6..0015531aff05 100644 --- a/net/rds/rdma.c +++ b/net/rds/rdma.c @@ -228,13 +228,13 @@ static int __rds_rdma_map(struct rds_sock *rs, struct rds_get_mr_args *args, args->vec.addr, args->vec.bytes, nr_pages); /* XXX clamp nr_pages to limit the size of this alloc? */ - pages = kcalloc(nr_pages, sizeof(struct page *), GFP_KERNEL); + pages = kzalloc_objs(struct page *, nr_pages, GFP_KERNEL); if (!pages) { ret = -ENOMEM; goto out; } - mr = kzalloc(sizeof(struct rds_mr), GFP_KERNEL); + mr = kzalloc_obj(struct rds_mr, GFP_KERNEL); if (!mr) { ret = -ENOMEM; goto out; @@ -269,7 +269,7 @@ static int __rds_rdma_map(struct rds_sock *rs, struct rds_get_mr_args *args, goto out; } else { nents = ret; - sg = kmalloc_array(nents, sizeof(*sg), GFP_KERNEL); + sg = kmalloc_objs(*sg, nents, GFP_KERNEL); if (!sg) { ret = -ENOMEM; goto out; @@ -571,9 +571,7 @@ int rds_rdma_extra_size(struct rds_rdma_args *args, if (args->nr_local > UIO_MAXIOV) return -EMSGSIZE; - iov->iov = kcalloc(args->nr_local, - sizeof(struct rds_iovec), - GFP_KERNEL); + iov->iov = kzalloc_objs(struct rds_iovec, args->nr_local, GFP_KERNEL); if (!iov->iov) return -ENOMEM; @@ -654,7 +652,7 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm, goto out_ret; } - pages = kcalloc(nr_pages, sizeof(struct page *), GFP_KERNEL); + pages = kzalloc_objs(struct page *, nr_pages, GFP_KERNEL); if (!pages) { ret = -ENOMEM; goto out_ret; @@ -681,7 +679,7 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm, * would have to use GFP_ATOMIC there, and don't want to deal * with failed allocations. */ - op->op_notifier = kmalloc(sizeof(struct rds_notifier), GFP_KERNEL); + op->op_notifier = kmalloc_obj(struct rds_notifier, GFP_KERNEL); if (!op->op_notifier) { ret = -ENOMEM; goto out_pages; @@ -730,8 +728,7 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm, ret = -EOPNOTSUPP; goto out_pages; } - local_odp_mr = - kzalloc(sizeof(*local_odp_mr), GFP_KERNEL); + local_odp_mr = kzalloc_obj(*local_odp_mr, GFP_KERNEL); if (!local_odp_mr) { ret = -ENOMEM; goto out_pages; @@ -937,7 +934,8 @@ int rds_cmsg_atomic(struct rds_sock *rs, struct rds_message *rm, * would have to use GFP_ATOMIC there, and don't want to deal * with failed allocations. */ - rm->atomic.op_notifier = kmalloc(sizeof(*rm->atomic.op_notifier), GFP_KERNEL); + rm->atomic.op_notifier = kmalloc_obj(*rm->atomic.op_notifier, + GFP_KERNEL); if (!rm->atomic.op_notifier) { ret = -ENOMEM; goto err; |
