summaryrefslogtreecommitdiff
path: root/net/rds
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-21 10:49:23 +0300
committerKees Cook <kees@kernel.org>2026-02-21 12:02:28 +0300
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /net/rds
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
downloadlinux-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.xz
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')
-rw-r--r--net/rds/cong.c2
-rw-r--r--net/rds/connection.c2
-rw-r--r--net/rds/ib.c5
-rw-r--r--net/rds/ib_cm.c2
-rw-r--r--net/rds/ib_rdma.c6
-rw-r--r--net/rds/info.c2
-rw-r--r--net/rds/loop.c2
-rw-r--r--net/rds/message.c2
-rw-r--r--net/rds/rdma.c20
9 files changed, 20 insertions, 23 deletions
diff --git a/net/rds/cong.c b/net/rds/cong.c
index ac1f120c10f9..e7f019c3a625 100644
--- a/net/rds/cong.c
+++ b/net/rds/cong.c
@@ -143,7 +143,7 @@ static struct rds_cong_map *rds_cong_from_addr(const struct in6_addr *addr)
unsigned long i;
unsigned long flags;
- map = kzalloc(sizeof(struct rds_cong_map), GFP_KERNEL);
+ map = kzalloc_obj(struct rds_cong_map, GFP_KERNEL);
if (!map)
return NULL;
diff --git a/net/rds/connection.c b/net/rds/connection.c
index 185f73b01694..e23fd9a628ac 100644
--- a/net/rds/connection.c
+++ b/net/rds/connection.c
@@ -197,7 +197,7 @@ static struct rds_connection *__rds_conn_create(struct net *net,
conn = ERR_PTR(-ENOMEM);
goto out;
}
- conn->c_path = kcalloc(npaths, sizeof(struct rds_conn_path), gfp);
+ conn->c_path = kzalloc_objs(struct rds_conn_path, npaths, gfp);
if (!conn->c_path) {
kmem_cache_free(rds_conn_slab, conn);
conn = ERR_PTR(-ENOMEM);
diff --git a/net/rds/ib.c b/net/rds/ib.c
index 9826fe7f9d00..8457ec7c3ab8 100644
--- a/net/rds/ib.c
+++ b/net/rds/ib.c
@@ -172,9 +172,8 @@ static int rds_ib_add_one(struct ib_device *device)
rds_ibdev->max_initiator_depth = device->attrs.max_qp_init_rd_atom;
rds_ibdev->max_responder_resources = device->attrs.max_qp_rd_atom;
- rds_ibdev->vector_load = kcalloc(device->num_comp_vectors,
- sizeof(int),
- GFP_KERNEL);
+ rds_ibdev->vector_load = kzalloc_objs(int, device->num_comp_vectors,
+ GFP_KERNEL);
if (!rds_ibdev->vector_load) {
pr_err("RDS/IB: %s failed to allocate vector memory\n",
__func__);
diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
index 26b069e1999d..0c64c504f79d 100644
--- a/net/rds/ib_cm.c
+++ b/net/rds/ib_cm.c
@@ -1203,7 +1203,7 @@ int rds_ib_conn_alloc(struct rds_connection *conn, gfp_t gfp)
int ret;
/* XXX too lazy? */
- ic = kzalloc(sizeof(struct rds_ib_connection), gfp);
+ ic = kzalloc_obj(struct rds_ib_connection, gfp);
if (!ic)
return -ENOMEM;
diff --git a/net/rds/ib_rdma.c b/net/rds/ib_rdma.c
index 6585164c7059..651f658a6a0a 100644
--- a/net/rds/ib_rdma.c
+++ b/net/rds/ib_rdma.c
@@ -67,7 +67,7 @@ static int rds_ib_add_ipaddr(struct rds_ib_device *rds_ibdev, __be32 ipaddr)
{
struct rds_ib_ipaddr *i_ipaddr;
- i_ipaddr = kmalloc(sizeof *i_ipaddr, GFP_KERNEL);
+ i_ipaddr = kmalloc_obj(*i_ipaddr, GFP_KERNEL);
if (!i_ipaddr)
return -ENOMEM;
@@ -585,7 +585,7 @@ void *rds_ib_get_mr(struct scatterlist *sg, unsigned long nents,
if (key_ret)
*key_ret = ib_mr->rkey;
- ibmr = kzalloc(sizeof(*ibmr), GFP_KERNEL);
+ ibmr = kzalloc_obj(*ibmr, GFP_KERNEL);
if (!ibmr) {
ib_dereg_mr(ib_mr);
ret = -ENOMEM;
@@ -641,7 +641,7 @@ struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *rds_ibdev,
{
struct rds_ib_mr_pool *pool;
- pool = kzalloc(sizeof(*pool), GFP_KERNEL);
+ pool = kzalloc_obj(*pool, GFP_KERNEL);
if (!pool)
return ERR_PTR(-ENOMEM);
diff --git a/net/rds/info.c b/net/rds/info.c
index b6b46a8214a0..696e957c41a9 100644
--- a/net/rds/info.c
+++ b/net/rds/info.c
@@ -187,7 +187,7 @@ int rds_info_getsockopt(struct socket *sock, int optname, char __user *optval,
nr_pages = (PAGE_ALIGN(start + len) - (start & PAGE_MASK))
>> PAGE_SHIFT;
- pages = kmalloc_array(nr_pages, sizeof(struct page *), GFP_KERNEL);
+ pages = kmalloc_objs(struct page *, nr_pages, GFP_KERNEL);
if (!pages) {
ret = -ENOMEM;
goto out;
diff --git a/net/rds/loop.c b/net/rds/loop.c
index 1d73ad79c847..ac9295a766b1 100644
--- a/net/rds/loop.c
+++ b/net/rds/loop.c
@@ -137,7 +137,7 @@ static int rds_loop_conn_alloc(struct rds_connection *conn, gfp_t gfp)
struct rds_loop_connection *lc;
unsigned long flags;
- lc = kzalloc(sizeof(struct rds_loop_connection), gfp);
+ lc = kzalloc_obj(struct rds_loop_connection, gfp);
if (!lc)
return -ENOMEM;
diff --git a/net/rds/message.c b/net/rds/message.c
index 54fd000806ea..e367ca4f4f31 100644
--- a/net/rds/message.c
+++ b/net/rds/message.c
@@ -415,7 +415,7 @@ static int rds_message_zcopy_from_user(struct rds_message *rm, struct iov_iter *
*/
sg = rm->data.op_sg;
- info = kzalloc(sizeof(*info), GFP_KERNEL);
+ info = kzalloc_obj(*info, GFP_KERNEL);
if (!info)
return -ENOMEM;
INIT_LIST_HEAD(&info->rs_zcookie_next);
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;