scst: Replace kmalloc with kmalloc_obj for non-scalar types

This is the result of running the Linux kernel Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci against the SCST tree.

This patch doesn't change any functionality.
This commit is contained in:
Gleb Chesnokov
2026-04-12 15:38:24 +03:00
parent 77c1efbc1e
commit 8a3b257c33
42 changed files with 170 additions and 201 deletions
+4 -4
View File
@@ -184,7 +184,7 @@ static int add_session(void __user *ptr)
lockdep_assert_held(&target_mgmt_mutex);
info = kzalloc(sizeof(*info), GFP_KERNEL);
info = kzalloc_obj(*info);
if (!info) {
PRINT_ERROR("Can't alloc info (size %zd)", sizeof(*info));
err = -ENOMEM;
@@ -227,7 +227,7 @@ static int del_session(void __user *ptr)
TRACE_ENTRY();
info = kzalloc(sizeof(*info), GFP_KERNEL);
info = kzalloc_obj(*info);
if (!info) {
PRINT_ERROR("Can't alloc info (size %zd)", sizeof(*info));
err = -ENOMEM;
@@ -522,7 +522,7 @@ int iscsi_add_attr(struct iscsi_target *target, const struct iscsi_kern_attr *at
TRACE_DBG("Adding %s's attr %s with mode %x", name,
attr_info->name, attr_info->mode);
tgt_attr = kzalloc(sizeof(*tgt_attr), GFP_KERNEL);
tgt_attr = kzalloc_obj(*tgt_attr);
if (!tgt_attr) {
PRINT_ERROR("Unable to allocate user (size %zd)",
sizeof(*tgt_attr));
@@ -699,7 +699,7 @@ static int add_target(void __user *ptr)
TRACE_ENTRY();
info = kzalloc(sizeof(*info), GFP_KERNEL);
info = kzalloc_obj(*info);
if (!info) {
PRINT_ERROR("Can't alloc info (size %zd)", sizeof(*info));
err = -ENOMEM;
+1 -1
View File
@@ -4119,7 +4119,7 @@ create:
for (j = 0; j < 2; j++) {
for (i = 0; i < count; i++) {
t = kmalloc(sizeof(*t), GFP_KERNEL);
t = kmalloc_obj(*t);
if (!t) {
res = -ENOMEM;
PRINT_ERROR("Failed to allocate thread (size %zd)",
+2 -3
View File
@@ -49,8 +49,7 @@ static int isert_buf_alloc_pg(struct ib_device *ib_dev,
struct page *page;
isert_buf->sg_cnt = DIV_ROUND_UP(size, PAGE_SIZE);
isert_buf->sg = kmalloc_array(isert_buf->sg_cnt, sizeof(*isert_buf->sg),
GFP_KERNEL);
isert_buf->sg = kmalloc_objs(*isert_buf->sg, isert_buf->sg_cnt);
if (unlikely(!isert_buf->sg)) {
PRINT_ERROR("Failed to allocate buffer SG");
res = -ENOMEM;
@@ -109,7 +108,7 @@ static int isert_buf_malloc(struct ib_device *ib_dev,
int res = 0;
isert_buf->sg_cnt = 1;
isert_buf->sg = kmalloc(sizeof(isert_buf->sg[0]), GFP_KERNEL);
isert_buf->sg = kmalloc_obj(isert_buf->sg[0]);
if (unlikely(!isert_buf->sg)) {
PRINT_ERROR("Failed to allocate buffer SG");
res = -ENOMEM;
+2 -2
View File
@@ -171,14 +171,14 @@ static int isert_alloc_for_rdma(struct isert_cmnd *pdu, int sge_cnt,
int i, ret = 0;
int wr_cnt;
sg_pool = kmalloc_array(sge_cnt, sizeof(*sg_pool), GFP_KERNEL);
sg_pool = kmalloc_objs(*sg_pool, sge_cnt);
if (unlikely(!sg_pool)) {
ret = -ENOMEM;
goto out;
}
wr_cnt = DIV_ROUND_UP(sge_cnt, isert_conn->max_sge);
wr = kmalloc_array(wr_cnt, sizeof(*wr), GFP_KERNEL);
wr = kmalloc_objs(*wr, wr_cnt);
if (unlikely(!wr)) {
ret = -ENOMEM;
goto out_free_sg_pool;
+4 -5
View File
@@ -905,7 +905,7 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev)
TRACE_ENTRY();
isert_dev = kzalloc(sizeof(*isert_dev), GFP_KERNEL);
isert_dev = kzalloc_obj(*isert_dev);
if (unlikely(!isert_dev)) {
PRINT_ERROR("Failed to allocate iser dev");
err = -ENOMEM;
@@ -924,9 +924,8 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev)
isert_dev->num_cqs = blk_mq_num_online_queues(ib_dev->num_comp_vectors);
isert_dev->cq_qps = kcalloc(isert_dev->num_cqs,
sizeof(*isert_dev->cq_qps),
GFP_KERNEL);
isert_dev->cq_qps = kzalloc_objs(*isert_dev->cq_qps,
isert_dev->num_cqs);
if (unlikely(!isert_dev->cq_qps)) {
PRINT_ERROR("Failed to allocate %d iser cq_qps",
isert_dev->num_cqs);
@@ -1780,7 +1779,7 @@ struct isert_portal *isert_portal_create(struct sockaddr *sa, size_t addr_len)
goto out;
}
portal = kzalloc(sizeof(*portal), GFP_KERNEL);
portal = kzalloc_obj(*portal);
if (unlikely(!portal)) {
PRINT_ERROR("Unable to allocate struct portal");
portal = ERR_PTR(-ENOMEM);
+1 -2
View File
@@ -990,8 +990,7 @@ int __init isert_init_login_devs(unsigned int ndevs)
* allocate the devices -- we can't have them static, as the number
* can be specified at load time
*/
isert_conn_devices = kcalloc(n_devs, sizeof(struct isert_conn_dev),
GFP_KERNEL);
isert_conn_devices = kzalloc_objs(struct isert_conn_dev, n_devs);
if (unlikely(!isert_conn_devices)) {
res = -ENOMEM;
goto fail; /* Make this more graceful */
+1 -1
View File
@@ -156,7 +156,7 @@ int __add_session(struct iscsi_target *target, struct iscsi_kern_session_info *i
goto out_err_unlock;
}
params_info = kmalloc(sizeof(*params_info), GFP_KERNEL);
params_info = kmalloc_obj(*params_info);
if (!params_info) {
PRINT_ERROR("Unable to allocate params info (size %zd)",
sizeof(*params_info));
+2 -2
View File
@@ -84,7 +84,7 @@ static int iscsi_target_create(struct iscsi_kern_target_info *info, u32 tid,
goto out;
}
target = kzalloc(sizeof(*target), GFP_KERNEL);
target = kzalloc_obj(*target);
if (!target) {
err = -ENOMEM;
goto out_put;
@@ -157,7 +157,7 @@ int __add_target(struct iscsi_kern_target_info *info)
goto out;
}
add_info = kmalloc(sizeof(*add_info), GFP_KERNEL);
add_info = kmalloc_obj(*add_info);
if (!add_info) {
PRINT_ERROR("Unable to allocate additional info (size %zd)",
sizeof(*add_info));