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 /drivers/nvme/target | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
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/nvme/target')
| -rw-r--r-- | drivers/nvme/target/admin-cmd.c | 23 | ||||
| -rw-r--r-- | drivers/nvme/target/configfs.c | 16 | ||||
| -rw-r--r-- | drivers/nvme/target/core.c | 17 | ||||
| -rw-r--r-- | drivers/nvme/target/discovery.c | 2 | ||||
| -rw-r--r-- | drivers/nvme/target/fabrics-cmd.c | 4 | ||||
| -rw-r--r-- | drivers/nvme/target/fc.c | 14 | ||||
| -rw-r--r-- | drivers/nvme/target/fcloop.c | 12 | ||||
| -rw-r--r-- | drivers/nvme/target/io-cmd-file.c | 3 | ||||
| -rw-r--r-- | drivers/nvme/target/loop.c | 6 | ||||
| -rw-r--r-- | drivers/nvme/target/passthru.c | 4 | ||||
| -rw-r--r-- | drivers/nvme/target/pci-epf.c | 13 | ||||
| -rw-r--r-- | drivers/nvme/target/pr.c | 12 | ||||
| -rw-r--r-- | drivers/nvme/target/rdma.c | 21 | ||||
| -rw-r--r-- | drivers/nvme/target/tcp.c | 9 | ||||
| -rw-r--r-- | drivers/nvme/target/zns.c | 4 |
15 files changed, 77 insertions, 83 deletions
diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c index 5e366502fb75..431702ff21fb 100644 --- a/drivers/nvme/target/admin-cmd.c +++ b/drivers/nvme/target/admin-cmd.c @@ -203,7 +203,7 @@ static void nvmet_execute_get_supported_log_pages(struct nvmet_req *req) struct nvme_supported_log *logs; u16 status; - logs = kzalloc(sizeof(*logs), GFP_KERNEL); + logs = kzalloc_obj(*logs, GFP_KERNEL); if (!logs) { status = NVME_SC_INTERNAL; goto out; @@ -308,7 +308,7 @@ static void nvmet_execute_get_log_page_rmi(struct nvmet_req *req) goto out; } - log = kzalloc(sizeof(*log), GFP_KERNEL); + log = kzalloc_obj(*log, GFP_KERNEL); if (!log) goto out; @@ -334,7 +334,7 @@ static void nvmet_execute_get_log_page_smart(struct nvmet_req *req) if (req->transfer_len != sizeof(*log)) goto out; - log = kzalloc(sizeof(*log), GFP_KERNEL); + log = kzalloc_obj(*log, GFP_KERNEL); if (!log) goto out; @@ -409,7 +409,7 @@ static void nvmet_execute_get_log_cmd_effects_ns(struct nvmet_req *req) struct nvme_effects_log *log; u16 status = NVME_SC_SUCCESS; - log = kzalloc(sizeof(*log), GFP_KERNEL); + log = kzalloc_obj(*log, GFP_KERNEL); if (!log) { status = NVME_SC_INTERNAL; goto out; @@ -504,7 +504,7 @@ static void nvmet_execute_get_log_page_endgrp(struct nvmet_req *req) if (status) goto out; - log = kzalloc(sizeof(*log), GFP_KERNEL); + log = kzalloc_obj(*log, GFP_KERNEL); if (!log) { status = NVME_SC_INTERNAL; goto out; @@ -542,8 +542,7 @@ static void nvmet_execute_get_log_page_ana(struct nvmet_req *req) u16 status; status = NVME_SC_INTERNAL; - desc = kmalloc(struct_size(desc, nsids, NVMET_MAX_NAMESPACES), - GFP_KERNEL); + desc = kmalloc_flex(*desc, nsids, NVMET_MAX_NAMESPACES, GFP_KERNEL); if (!desc) goto out; @@ -581,7 +580,7 @@ static void nvmet_execute_get_log_page_features(struct nvmet_req *req) struct nvme_supported_features_log *features; u16 status; - features = kzalloc(sizeof(*features), GFP_KERNEL); + features = kzalloc_obj(*features, GFP_KERNEL); if (!features) { status = NVME_SC_INTERNAL; goto out; @@ -660,7 +659,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req) mutex_unlock(&subsys->lock); } - id = kzalloc(sizeof(*id), GFP_KERNEL); + id = kzalloc_obj(*id, GFP_KERNEL); if (!id) { status = NVME_SC_INTERNAL; goto out; @@ -809,7 +808,7 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req) goto out; } - id = kzalloc(sizeof(*id), GFP_KERNEL); + id = kzalloc_obj(*id, GFP_KERNEL); if (!id) { status = NVME_SC_INTERNAL; goto out; @@ -1053,7 +1052,7 @@ static void nvme_execute_identify_ns_nvm(struct nvmet_req *req) if (status) goto out; - id = kzalloc(sizeof(*id), GFP_KERNEL); + id = kzalloc_obj(*id, GFP_KERNEL); if (!id) { status = NVME_SC_INTERNAL; goto out; @@ -1073,7 +1072,7 @@ static void nvmet_execute_id_cs_indep(struct nvmet_req *req) if (status) goto out; - id = kzalloc(sizeof(*id), GFP_KERNEL); + id = kzalloc_obj(*id, GFP_KERNEL); if (!id) { status = NVME_SC_INTERNAL; goto out; diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c index 127dae51fec1..6df2844dcec1 100644 --- a/drivers/nvme/target/configfs.c +++ b/drivers/nvme/target/configfs.c @@ -1040,7 +1040,7 @@ static int nvmet_port_subsys_allow_link(struct config_item *parent, return -EINVAL; } subsys = to_subsys(target); - link = kmalloc(sizeof(*link), GFP_KERNEL); + link = kmalloc_obj(*link, GFP_KERNEL); if (!link) return -ENOMEM; link->subsys = subsys; @@ -1120,7 +1120,7 @@ static int nvmet_allowed_hosts_allow_link(struct config_item *parent, } host = to_host(target); - link = kmalloc(sizeof(*link), GFP_KERNEL); + link = kmalloc_obj(*link, GFP_KERNEL); if (!link) return -ENOMEM; link->host = host; @@ -1825,7 +1825,7 @@ static struct config_group *nvmet_referral_make( { struct nvmet_port *port; - port = kzalloc(sizeof(*port), GFP_KERNEL); + port = kzalloc_obj(*port, GFP_KERNEL); if (!port) return ERR_PTR(-ENOMEM); @@ -1943,7 +1943,7 @@ static struct config_group *nvmet_ana_groups_make_group( goto out; ret = -ENOMEM; - grp = kzalloc(sizeof(*grp), GFP_KERNEL); + grp = kzalloc_obj(*grp, GFP_KERNEL); if (!grp) goto out; grp->port = port; @@ -2022,12 +2022,12 @@ static struct config_group *nvmet_ports_make(struct config_group *group, if (kstrtou16(name, 0, &portid)) return ERR_PTR(-EINVAL); - port = kzalloc(sizeof(*port), GFP_KERNEL); + port = kzalloc_obj(*port, GFP_KERNEL); if (!port) return ERR_PTR(-ENOMEM); - port->ana_state = kcalloc(NVMET_MAX_ANAGRPS + 1, - sizeof(*port->ana_state), GFP_KERNEL); + port->ana_state = kzalloc_objs(*port->ana_state, NVMET_MAX_ANAGRPS + 1, + GFP_KERNEL); if (!port->ana_state) { kfree(port); return ERR_PTR(-ENOMEM); @@ -2257,7 +2257,7 @@ static struct config_group *nvmet_hosts_make_group(struct config_group *group, { struct nvmet_host *host; - host = kzalloc(sizeof(*host), GFP_KERNEL); + host = kzalloc_obj(*host, GFP_KERNEL); if (!host) return ERR_PTR(-ENOMEM); diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index eab3e4fc0f74..255a6c9b2548 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -194,7 +194,7 @@ void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type, { struct nvmet_async_event *aen; - aen = kmalloc(sizeof(*aen), GFP_KERNEL); + aen = kmalloc_obj(*aen, GFP_KERNEL); if (!aen) return; @@ -693,7 +693,7 @@ struct nvmet_ns *nvmet_ns_alloc(struct nvmet_subsys *subsys, u32 nsid) if (subsys->nr_namespaces == NVMET_MAX_NAMESPACES) goto out_unlock; - ns = kzalloc(sizeof(*ns), GFP_KERNEL); + ns = kzalloc_obj(*ns, GFP_KERNEL); if (!ns) goto out_unlock; @@ -1609,7 +1609,7 @@ struct nvmet_ctrl *nvmet_alloc_ctrl(struct nvmet_alloc_ctrl_args *args) up_read(&nvmet_config_sem); args->status = NVME_SC_INTERNAL; - ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); + ctrl = kzalloc_obj(*ctrl, GFP_KERNEL); if (!ctrl) goto out_put_subsystem; mutex_init(&ctrl->lock); @@ -1642,14 +1642,13 @@ struct nvmet_ctrl *nvmet_alloc_ctrl(struct nvmet_alloc_ctrl_args *args) if (!ctrl->changed_ns_list) goto out_free_ctrl; - ctrl->sqs = kcalloc(subsys->max_qid + 1, - sizeof(struct nvmet_sq *), - GFP_KERNEL); + ctrl->sqs = kzalloc_objs(struct nvmet_sq *, subsys->max_qid + 1, + GFP_KERNEL); if (!ctrl->sqs) goto out_free_changed_ns_list; - ctrl->cqs = kcalloc(subsys->max_qid + 1, sizeof(struct nvmet_cq *), - GFP_KERNEL); + ctrl->cqs = kzalloc_objs(struct nvmet_cq *, subsys->max_qid + 1, + GFP_KERNEL); if (!ctrl->cqs) goto out_free_sqs; @@ -1829,7 +1828,7 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn, char serial[NVMET_SN_MAX_SIZE / 2]; int ret; - subsys = kzalloc(sizeof(*subsys), GFP_KERNEL); + subsys = kzalloc_obj(*subsys, GFP_KERNEL); if (!subsys) return ERR_PTR(-ENOMEM); diff --git a/drivers/nvme/target/discovery.c b/drivers/nvme/target/discovery.c index c06f3e04296c..8a4a33f82177 100644 --- a/drivers/nvme/target/discovery.c +++ b/drivers/nvme/target/discovery.c @@ -263,7 +263,7 @@ static void nvmet_execute_disc_identify(struct nvmet_req *req) goto out; } - id = kzalloc(sizeof(*id), GFP_KERNEL); + id = kzalloc_obj(*id, GFP_KERNEL); if (!id) { status = NVME_SC_INTERNAL; goto out; diff --git a/drivers/nvme/target/fabrics-cmd.c b/drivers/nvme/target/fabrics-cmd.c index 7b8d8b397802..5c0a1a3dd5b6 100644 --- a/drivers/nvme/target/fabrics-cmd.c +++ b/drivers/nvme/target/fabrics-cmd.c @@ -280,7 +280,7 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req) if (!nvmet_check_transfer_len(req, sizeof(struct nvmf_connect_data))) return; - d = kmalloc(sizeof(*d), GFP_KERNEL); + d = kmalloc_obj(*d, GFP_KERNEL); if (!d) { args.status = NVME_SC_INTERNAL; goto complete; @@ -344,7 +344,7 @@ static void nvmet_execute_io_connect(struct nvmet_req *req) if (!nvmet_check_transfer_len(req, sizeof(struct nvmf_connect_data))) return; - d = kmalloc(sizeof(*d), GFP_KERNEL); + d = kmalloc_obj(*d, GFP_KERNEL); if (!d) { status = NVME_SC_INTERNAL; goto complete; diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c index 0d9784004c9b..69ab0830313d 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -528,8 +528,8 @@ nvmet_fc_alloc_ls_iodlist(struct nvmet_fc_tgtport *tgtport) struct nvmet_fc_ls_iod *iod; int i; - iod = kcalloc(NVMET_LS_CTX_COUNT, sizeof(struct nvmet_fc_ls_iod), - GFP_KERNEL); + iod = kzalloc_objs(struct nvmet_fc_ls_iod, NVMET_LS_CTX_COUNT, + GFP_KERNEL); if (!iod) return -ENOMEM; @@ -789,7 +789,7 @@ nvmet_fc_alloc_target_queue(struct nvmet_fc_tgt_assoc *assoc, if (qid > NVMET_NR_QUEUES) return NULL; - queue = kzalloc(struct_size(queue, fod, sqsize), GFP_KERNEL); + queue = kzalloc_flex(*queue, fod, sqsize, GFP_KERNEL); if (!queue) return NULL; @@ -1034,7 +1034,7 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle) if (match) return match; - newhost = kzalloc(sizeof(*newhost), GFP_KERNEL); + newhost = kzalloc_obj(*newhost, GFP_KERNEL); if (!newhost) return ERR_PTR(-ENOMEM); @@ -1116,7 +1116,7 @@ nvmet_fc_alloc_target_assoc(struct nvmet_fc_tgtport *tgtport, void *hosthandle) if (!tgtport->pe) return NULL; - assoc = kzalloc(sizeof(*assoc), GFP_KERNEL); + assoc = kzalloc_obj(*assoc, GFP_KERNEL); if (!assoc) return NULL; @@ -2717,7 +2717,7 @@ nvmet_fc_rcv_fcp_req(struct nvmet_fc_target_port *target_port, spin_unlock_irqrestore(&queue->qlock, flags); /* Now we need to dynamically allocate one */ - deferfcp = kmalloc(sizeof(*deferfcp), GFP_KERNEL); + deferfcp = kmalloc_obj(*deferfcp, GFP_KERNEL); if (!deferfcp) { /* release the queue lookup reference */ nvmet_fc_tgt_q_put(queue); @@ -2882,7 +2882,7 @@ nvmet_fc_add_port(struct nvmet_port *port) if (ret) return ret; - pe = kzalloc(sizeof(*pe), GFP_KERNEL); + pe = kzalloc_obj(*pe, GFP_KERNEL); if (!pe) return -ENOMEM; diff --git a/drivers/nvme/target/fcloop.c b/drivers/nvme/target/fcloop.c index c30e9a3e014f..8473e41e5856 100644 --- a/drivers/nvme/target/fcloop.c +++ b/drivers/nvme/target/fcloop.c @@ -559,7 +559,7 @@ fcloop_tgt_discovery_evt(struct nvmet_fc_target_port *tgtport) { struct fcloop_rscn *tgt_rscn; - tgt_rscn = kzalloc(sizeof(*tgt_rscn), GFP_KERNEL); + tgt_rscn = kzalloc_obj(*tgt_rscn, GFP_KERNEL); if (!tgt_rscn) return; @@ -766,7 +766,7 @@ fcloop_fcp_req(struct nvme_fc_local_port *localport, if (!rport->targetport) return -ECONNREFUSED; - tfcp_req = kzalloc(sizeof(*tfcp_req), GFP_ATOMIC); + tfcp_req = kzalloc_obj(*tfcp_req, GFP_ATOMIC); if (!tfcp_req) return -ENOMEM; @@ -1194,11 +1194,11 @@ fcloop_create_local_port(struct device *dev, struct device_attribute *attr, unsigned long flags; int ret = -ENOMEM; - lport = kzalloc(sizeof(*lport), GFP_KERNEL); + lport = kzalloc_obj(*lport, GFP_KERNEL); if (!lport) return -ENOMEM; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) goto out_free_lport; @@ -1345,7 +1345,7 @@ fcloop_alloc_nport(const char *buf, size_t count, bool remoteport) u32 opts_mask = (remoteport) ? RPORT_OPTS : TGTPORT_OPTS; int ret; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return NULL; @@ -1357,7 +1357,7 @@ fcloop_alloc_nport(const char *buf, size_t count, bool remoteport) if ((opts->mask & opts_mask) != opts_mask) goto out_free_opts; - newnport = kzalloc(sizeof(*newnport), GFP_KERNEL); + newnport = kzalloc_obj(*newnport, GFP_KERNEL); if (!newnport) goto out_free_opts; diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c index 2d068439b129..6e810a91e6c5 100644 --- a/drivers/nvme/target/io-cmd-file.c +++ b/drivers/nvme/target/io-cmd-file.c @@ -228,8 +228,7 @@ static void nvmet_file_execute_rw(struct nvmet_req *req) } if (nr_bvec > NVMET_MAX_INLINE_BIOVEC) - req->f.bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), - GFP_KERNEL); + req->f.bvec = kmalloc_objs(struct bio_vec, nr_bvec, GFP_KERNEL); else req->f.bvec = req->inline_bvec; diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c index fc8e7c9ad858..575c5c31ea29 100644 --- a/drivers/nvme/target/loop.c +++ b/drivers/nvme/target/loop.c @@ -565,7 +565,7 @@ static struct nvme_ctrl *nvme_loop_create_ctrl(struct device *dev, struct nvme_loop_ctrl *ctrl; int ret; - ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); + ctrl = kzalloc_obj(*ctrl, GFP_KERNEL); if (!ctrl) return ERR_PTR(-ENOMEM); ctrl->ctrl.opts = opts; @@ -592,8 +592,8 @@ static struct nvme_ctrl *nvme_loop_create_ctrl(struct device *dev, ctrl->ctrl.kato = opts->kato; ctrl->port = nvme_loop_find_port(&ctrl->ctrl); - ctrl->queues = kcalloc(opts->nr_io_queues + 1, sizeof(*ctrl->queues), - GFP_KERNEL); + ctrl->queues = kzalloc_objs(*ctrl->queues, opts->nr_io_queues + 1, + GFP_KERNEL); if (!ctrl->queues) goto out_uninit_ctrl; diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c index 5d541c2a46a5..bac8b8f864ce 100644 --- a/drivers/nvme/target/passthru.c +++ b/drivers/nvme/target/passthru.c @@ -86,7 +86,7 @@ static u16 nvmet_passthru_override_id_ctrl(struct nvmet_req *req) unsigned int max_hw_sectors; int page_shift; - id = kzalloc(sizeof(*id), GFP_KERNEL); + id = kzalloc_obj(*id, GFP_KERNEL); if (!id) return NVME_SC_INTERNAL; @@ -178,7 +178,7 @@ static u16 nvmet_passthru_override_id_ns(struct nvmet_req *req) struct nvme_id_ns *id; int i; - id = kzalloc(sizeof(*id), GFP_KERNEL); + id = kzalloc_obj(*id, GFP_KERNEL); if (!id) return NVME_SC_INTERNAL; diff --git a/drivers/nvme/target/pci-epf.c b/drivers/nvme/target/pci-epf.c index f858a6c9d7cb..f51a7de9f16a 100644 --- a/drivers/nvme/target/pci-epf.c +++ b/drivers/nvme/target/pci-epf.c @@ -502,9 +502,8 @@ static inline int nvmet_pci_epf_transfer(struct nvmet_pci_epf_ctrl *ctrl, static int nvmet_pci_epf_alloc_irq_vectors(struct nvmet_pci_epf_ctrl *ctrl) { - ctrl->irq_vectors = kcalloc(ctrl->nr_queues, - sizeof(struct nvmet_pci_epf_irq_vector), - GFP_KERNEL); + ctrl->irq_vectors = kzalloc_objs(struct nvmet_pci_epf_irq_vector, + ctrl->nr_queues, GFP_KERNEL); if (!ctrl->irq_vectors) return -ENOMEM; @@ -1563,13 +1562,13 @@ static int nvmet_pci_epf_alloc_queues(struct nvmet_pci_epf_ctrl *ctrl) { unsigned int qid; - ctrl->sq = kcalloc(ctrl->nr_queues, - sizeof(struct nvmet_pci_epf_queue), GFP_KERNEL); + ctrl->sq = kzalloc_objs(struct nvmet_pci_epf_queue, ctrl->nr_queues, + GFP_KERNEL); if (!ctrl->sq) return -ENOMEM; - ctrl->cq = kcalloc(ctrl->nr_queues, - sizeof(struct nvmet_pci_epf_queue), GFP_KERNEL); + ctrl->cq = kzalloc_objs(struct nvmet_pci_epf_queue, ctrl->nr_queues, + GFP_KERNEL); if (!ctrl->cq) { kfree(ctrl->sq); ctrl->sq = NULL; diff --git a/drivers/nvme/target/pr.c b/drivers/nvme/target/pr.c index cd22d8333314..254960a844ac 100644 --- a/drivers/nvme/target/pr.c +++ b/drivers/nvme/target/pr.c @@ -230,7 +230,7 @@ static u16 nvmet_pr_register(struct nvmet_req *req, u16 status = NVME_SC_SUCCESS; u64 nrkey = le64_to_cpu(d->nrkey); - new = kmalloc(sizeof(*new), GFP_KERNEL); + new = kmalloc_obj(*new, GFP_KERNEL); if (!new) return NVME_SC_INTERNAL; @@ -331,7 +331,7 @@ static u16 nvmet_pr_update_reg_attr(struct nvmet_pr *pr, return NVME_SC_SUCCESS; } - new = kmalloc(sizeof(*new), GFP_ATOMIC); + new = kmalloc_obj(*new, GFP_ATOMIC); if (!new) return NVME_SC_INTERNAL; @@ -380,7 +380,7 @@ static void nvmet_execute_pr_register(struct nvmet_req *req) u8 reg_act = cdw10 & 0x07; /* Reservation Register Action, bit 02:00 */ u16 status; - d = kmalloc(sizeof(*d), GFP_KERNEL); + d = kmalloc_obj(*d, GFP_KERNEL); if (!d) { status = NVME_SC_INTERNAL; goto out; @@ -662,7 +662,7 @@ static void nvmet_execute_pr_acquire(struct nvmet_req *req) goto out; } - d = kmalloc(sizeof(*d), GFP_KERNEL); + d = kmalloc_obj(*d, GFP_KERNEL); if (!d) { status = NVME_SC_INTERNAL; goto out; @@ -773,7 +773,7 @@ static void nvmet_execute_pr_release(struct nvmet_req *req) goto out; } - d = kmalloc(sizeof(*d), GFP_KERNEL); + d = kmalloc_obj(*d, GFP_KERNEL); if (!d) { status = NVME_SC_INTERNAL; goto out; @@ -1013,7 +1013,7 @@ static int nvmet_pr_alloc_and_insert_pc_ref(struct nvmet_ns *ns, struct nvmet_pr_per_ctrl_ref *pc_ref; int ret; - pc_ref = kmalloc(sizeof(*pc_ref), GFP_ATOMIC); + pc_ref = kmalloc_obj(*pc_ref, GFP_ATOMIC); if (!pc_ref) return -ENOMEM; diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c index 9c12b2361a6d..ae2e27d9cc07 100644 --- a/drivers/nvme/target/rdma.c +++ b/drivers/nvme/target/rdma.c @@ -222,7 +222,7 @@ nvmet_rdma_get_rsp(struct nvmet_rdma_queue *queue) if (unlikely(!rsp)) { int ret; - rsp = kzalloc(sizeof(*rsp), GFP_KERNEL); + rsp = kzalloc_obj(*rsp, GFP_KERNEL); if (unlikely(!rsp)) return NULL; ret = nvmet_rdma_alloc_rsp(queue->dev, rsp, @@ -317,7 +317,7 @@ static int nvmet_rdma_alloc_cmd(struct nvmet_rdma_device *ndev, struct nvmet_rdma_cmd *c, bool admin) { /* NVMe command / RDMA RECV */ - c->nvme_cmd = kmalloc(sizeof(*c->nvme_cmd), GFP_KERNEL); + c->nvme_cmd = kmalloc_obj(*c->nvme_cmd, GFP_KERNEL); if (!c->nvme_cmd) goto out; @@ -367,7 +367,7 @@ nvmet_rdma_alloc_cmds(struct nvmet_rdma_device *ndev, struct nvmet_rdma_cmd *cmds; int ret = -EINVAL, i; - cmds = kvcalloc(nr_cmds, sizeof(struct nvmet_rdma_cmd), GFP_KERNEL); + cmds = kvzalloc_objs(struct nvmet_rdma_cmd, nr_cmds, GFP_KERNEL); if (!cmds) goto out; @@ -401,7 +401,7 @@ static int nvmet_rdma_alloc_rsp(struct nvmet_rdma_device *ndev, struct nvmet_rdma_rsp *r, int tag) { /* NVMe CQE / RDMA SEND */ - r->req.cqe = kmalloc(sizeof(*r->req.cqe), GFP_KERNEL); + r->req.cqe = kmalloc_obj(*r->req.cqe, GFP_KERNEL); if (!r->req.cqe) goto out; @@ -455,8 +455,7 @@ nvmet_rdma_alloc_rsps(struct nvmet_rdma_queue *queue) NUMA_NO_NODE, false, true)) goto out; - queue->rsps = kvcalloc(nr_rsps, sizeof(struct nvmet_rdma_rsp), - GFP_KERNEL); + queue->rsps = kvzalloc_objs(struct nvmet_rdma_rsp, nr_rsps, GFP_KERNEL); if (!queue->rsps) goto out_free_sbitmap; @@ -1096,7 +1095,7 @@ nvmet_rdma_init_srq(struct nvmet_rdma_device *ndev) struct ib_srq *srq; int ret, i; - nsrq = kzalloc(sizeof(*nsrq), GFP_KERNEL); + nsrq = kzalloc_obj(*nsrq, GFP_KERNEL); if (!nsrq) return ERR_PTR(-ENOMEM); @@ -1155,7 +1154,7 @@ static int nvmet_rdma_init_srqs(struct nvmet_rdma_device *ndev) ndev->srq_count = min(ndev->device->num_comp_vectors, ndev->device->attrs.max_srq); - ndev->srqs = kcalloc(ndev->srq_count, sizeof(*ndev->srqs), GFP_KERNEL); + ndev->srqs = kzalloc_objs(*ndev->srqs, ndev->srq_count, GFP_KERNEL); if (!ndev->srqs) return -ENOMEM; @@ -1208,7 +1207,7 @@ nvmet_rdma_find_get_device(struct rdma_cm_id *cm_id) goto out_unlock; } - ndev = kzalloc(sizeof(*ndev), GFP_KERNEL); + ndev = kzalloc_obj(*ndev, GFP_KERNEL); if (!ndev) goto out_err; @@ -1430,7 +1429,7 @@ nvmet_rdma_alloc_queue(struct nvmet_rdma_device *ndev, struct nvmet_rdma_queue *queue; int ret; - queue = kzalloc(sizeof(*queue), GFP_KERNEL); + queue = kzalloc_obj(*queue, GFP_KERNEL); if (!queue) { ret = NVME_RDMA_CM_NO_RSC; goto out_reject; @@ -1924,7 +1923,7 @@ static int nvmet_rdma_add_port(struct nvmet_port *nport) __kernel_sa_family_t af; int ret; - port = kzalloc(sizeof(*port), GFP_KERNEL); + port = kzalloc_obj(*port, GFP_KERNEL); if (!port) return -ENOMEM; diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index bda816d66846..ac0a44bfa386 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -439,8 +439,7 @@ static int nvmet_tcp_map_data(struct nvmet_tcp_cmd *cmd) cmd->cur_sg = cmd->req.sg; if (nvmet_tcp_has_data_in(cmd)) { - cmd->iov = kmalloc_array(cmd->req.sg_cnt, - sizeof(*cmd->iov), GFP_KERNEL); + cmd->iov = kmalloc_objs(*cmd->iov, cmd->req.sg_cnt, GFP_KERNEL); if (!cmd->iov) goto err; } @@ -1513,7 +1512,7 @@ static int nvmet_tcp_alloc_cmds(struct nvmet_tcp_queue *queue) struct nvmet_tcp_cmd *cmds; int i, ret = -EINVAL, nr_cmds = queue->nr_cmds; - cmds = kvcalloc(nr_cmds, sizeof(struct nvmet_tcp_cmd), GFP_KERNEL); + cmds = kvzalloc_objs(struct nvmet_tcp_cmd, nr_cmds, GFP_KERNEL); if (!cmds) goto out; @@ -1901,7 +1900,7 @@ static void nvmet_tcp_alloc_queue(struct nvmet_tcp_port *port, struct file *sock_file = NULL; int ret; - queue = kzalloc(sizeof(*queue), GFP_KERNEL); + queue = kzalloc_obj(*queue, GFP_KERNEL); if (!queue) { ret = -ENOMEM; goto out_release; @@ -2037,7 +2036,7 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport) __kernel_sa_family_t af; int ret; - port = kzalloc(sizeof(*port), GFP_KERNEL); + port = kzalloc_obj(*port, GFP_KERNEL); if (!port) return -ENOMEM; diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c index 15a579cf528c..e895f6b3a308 100644 --- a/drivers/nvme/target/zns.c +++ b/drivers/nvme/target/zns.c @@ -73,7 +73,7 @@ void nvmet_execute_identify_ctrl_zns(struct nvmet_req *req) struct nvme_id_ctrl_zns *id; u16 status; - id = kzalloc(sizeof(*id), GFP_KERNEL); + id = kzalloc_obj(*id, GFP_KERNEL); if (!id) { status = NVME_SC_INTERNAL; goto out; @@ -104,7 +104,7 @@ void nvmet_execute_identify_ns_zns(struct nvmet_req *req) goto out; } - id_zns = kzalloc(sizeof(*id_zns), GFP_KERNEL); + id_zns = kzalloc_obj(*id_zns, GFP_KERNEL); if (!id_zns) { status = NVME_SC_INTERNAL; goto out; |
