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/cxl | |
| 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 'drivers/cxl')
| -rw-r--r-- | drivers/cxl/acpi.c | 4 | ||||
| -rw-r--r-- | drivers/cxl/core/cdat.c | 18 | ||||
| -rw-r--r-- | drivers/cxl/core/edac.c | 3 | ||||
| -rw-r--r-- | drivers/cxl/core/features.c | 4 | ||||
| -rw-r--r-- | drivers/cxl/core/memdev.c | 4 | ||||
| -rw-r--r-- | drivers/cxl/core/pmem.c | 4 | ||||
| -rw-r--r-- | drivers/cxl/core/pmu.c | 2 | ||||
| -rw-r--r-- | drivers/cxl/core/port.c | 15 | ||||
| -rw-r--r-- | drivers/cxl/core/region.c | 10 | ||||
| -rw-r--r-- | drivers/cxl/pmem.c | 4 |
10 files changed, 33 insertions, 35 deletions
diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c index d78f005bd994..11320e88eb09 100644 --- a/drivers/cxl/acpi.c +++ b/drivers/cxl/acpi.c @@ -336,7 +336,7 @@ static void del_cxl_resource(struct resource *res) static struct resource *alloc_cxl_resource(resource_size_t base, resource_size_t n, int id) { - struct resource *res __free(kfree) = kzalloc(sizeof(*res), GFP_KERNEL); + struct resource *res __free(kfree) = kzalloc_obj(*res, GFP_KERNEL); if (!res) return NULL; @@ -825,7 +825,7 @@ static int add_cxl_resources(struct resource *cxl_res) struct resource *res, *new, *next; for (res = cxl_res->child; res; res = next) { - new = kzalloc(sizeof(*new), GFP_KERNEL); + new = kzalloc_obj(*new, GFP_KERNEL); if (!new) return -ENOMEM; new->name = res->name; diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c index 18f0f2a25113..a024083bae2d 100644 --- a/drivers/cxl/core/cdat.c +++ b/drivers/cxl/core/cdat.c @@ -69,7 +69,7 @@ static int cdat_dsmas_handler(union acpi_subtable_headers *header, void *arg, /* Skip common header */ dsmas = (struct acpi_cdat_dsmas *)(hdr + 1); - dent = kzalloc(sizeof(*dent), GFP_KERNEL); + dent = kzalloc_obj(*dent, GFP_KERNEL); if (!dent) return -ENOMEM; @@ -669,7 +669,7 @@ static int cxl_endpoint_gather_bandwidth(struct cxl_region *cxlr, perf_ctx = xa_load(usp_xa, index); if (!perf_ctx) { struct cxl_perf_ctx *c __free(kfree) = - kzalloc(sizeof(*perf_ctx), GFP_KERNEL); + kzalloc_obj(*perf_ctx, GFP_KERNEL); if (!c) return -ENOMEM; @@ -756,7 +756,7 @@ static struct xarray *cxl_switch_gather_bandwidth(struct cxl_region *cxlr, bool *gp_is_root) { struct xarray *res_xa __free(free_perf_xa) = - kzalloc(sizeof(*res_xa), GFP_KERNEL); + kzalloc_obj(*res_xa, GFP_KERNEL); struct access_coordinate coords[ACCESS_COORDINATE_MAX]; struct cxl_perf_ctx *ctx, *us_ctx; unsigned long index, us_index; @@ -795,7 +795,7 @@ static struct xarray *cxl_switch_gather_bandwidth(struct cxl_region *cxlr, us_ctx = xa_load(res_xa, us_index); if (!us_ctx) { struct cxl_perf_ctx *n __free(kfree) = - kzalloc(sizeof(*n), GFP_KERNEL); + kzalloc_obj(*n, GFP_KERNEL); if (!n) return ERR_PTR(-ENOMEM); @@ -862,7 +862,7 @@ static struct xarray *cxl_switch_gather_bandwidth(struct cxl_region *cxlr, static struct xarray *cxl_rp_gather_bandwidth(struct xarray *xa) { struct xarray *hb_xa __free(free_perf_xa) = - kzalloc(sizeof(*hb_xa), GFP_KERNEL); + kzalloc_obj(*hb_xa, GFP_KERNEL); struct cxl_perf_ctx *ctx; unsigned long index; @@ -879,7 +879,7 @@ static struct xarray *cxl_rp_gather_bandwidth(struct xarray *xa) hb_ctx = xa_load(hb_xa, hb_index); if (!hb_ctx) { struct cxl_perf_ctx *n __free(kfree) = - kzalloc(sizeof(*n), GFP_KERNEL); + kzalloc_obj(*n, GFP_KERNEL); if (!n) return ERR_PTR(-ENOMEM); @@ -906,7 +906,7 @@ static struct xarray *cxl_rp_gather_bandwidth(struct xarray *xa) static struct xarray *cxl_hb_gather_bandwidth(struct xarray *xa) { struct xarray *mw_xa __free(free_perf_xa) = - kzalloc(sizeof(*mw_xa), GFP_KERNEL); + kzalloc_obj(*mw_xa, GFP_KERNEL); struct cxl_perf_ctx *ctx; unsigned long index; @@ -928,7 +928,7 @@ static struct xarray *cxl_hb_gather_bandwidth(struct xarray *xa) mw_ctx = xa_load(mw_xa, mw_index); if (!mw_ctx) { struct cxl_perf_ctx *n __free(kfree) = - kzalloc(sizeof(*n), GFP_KERNEL); + kzalloc_obj(*n, GFP_KERNEL); if (!n) return ERR_PTR(-ENOMEM); @@ -987,7 +987,7 @@ void cxl_region_shared_upstream_bandwidth_update(struct cxl_region *cxlr) lockdep_assert_held(&cxl_rwsem.dpa); struct xarray *usp_xa __free(free_perf_xa) = - kzalloc(sizeof(*usp_xa), GFP_KERNEL); + kzalloc_obj(*usp_xa, GFP_KERNEL); if (!usp_xa) return; diff --git a/drivers/cxl/core/edac.c b/drivers/cxl/core/edac.c index 81160260e26b..7f5457adb26c 100644 --- a/drivers/cxl/core/edac.c +++ b/drivers/cxl/core/edac.c @@ -2009,8 +2009,7 @@ static void err_rec_free(void *_cxlmd) static int devm_cxl_memdev_setup_err_rec(struct cxl_memdev *cxlmd) { - struct cxl_mem_err_rec *array_rec = - kzalloc(sizeof(*array_rec), GFP_KERNEL); + struct cxl_mem_err_rec *array_rec = kzalloc_obj(*array_rec, GFP_KERNEL); if (!array_rec) return -ENOMEM; diff --git a/drivers/cxl/core/features.c b/drivers/cxl/core/features.c index 4bc484b46f43..2007d8ebe1c4 100644 --- a/drivers/cxl/core/features.c +++ b/drivers/cxl/core/features.c @@ -94,7 +94,7 @@ get_supported_features(struct cxl_features_state *cxlfs) return NULL; struct cxl_feat_entries *entries __free(kvfree) = - kvmalloc(struct_size(entries, ent, count), GFP_KERNEL); + kvmalloc_flex(*entries, ent, count, GFP_KERNEL); if (!entries) return NULL; @@ -204,7 +204,7 @@ int devm_cxl_setup_features(struct cxl_dev_state *cxlds) return -ENODEV; struct cxl_features_state *cxlfs __free(kfree) = - kzalloc(sizeof(*cxlfs), GFP_KERNEL); + kzalloc_obj(*cxlfs, GFP_KERNEL); if (!cxlfs) return -ENOMEM; diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index af3d0cc65138..a81df0de4889 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -665,7 +665,7 @@ static struct cxl_memdev *cxl_memdev_alloc(struct cxl_dev_state *cxlds, struct cdev *cdev; int rc; - cxlmd = kzalloc(sizeof(*cxlmd), GFP_KERNEL); + cxlmd = kzalloc_obj(*cxlmd, GFP_KERNEL); if (!cxlmd) return ERR_PTR(-ENOMEM); @@ -831,7 +831,7 @@ static int cxl_mem_abort_fw_xfer(struct cxl_memdev_state *mds) struct cxl_mbox_cmd mbox_cmd; int rc; - transfer = kzalloc(struct_size(transfer, data, 0), GFP_KERNEL); + transfer = kzalloc_flex(*transfer, data, 0, GFP_KERNEL); if (!transfer) return -ENOMEM; diff --git a/drivers/cxl/core/pmem.c b/drivers/cxl/core/pmem.c index e7b1e6fa0ea0..be7538e58b9c 100644 --- a/drivers/cxl/core/pmem.c +++ b/drivers/cxl/core/pmem.c @@ -83,7 +83,7 @@ static struct cxl_nvdimm_bridge *cxl_nvdimm_bridge_alloc(struct cxl_port *port) struct device *dev; int rc; - cxl_nvb = kzalloc(sizeof(*cxl_nvb), GFP_KERNEL); + cxl_nvb = kzalloc_obj(*cxl_nvb, GFP_KERNEL); if (!cxl_nvb) return ERR_PTR(-ENOMEM); @@ -198,7 +198,7 @@ static struct cxl_nvdimm *cxl_nvdimm_alloc(struct cxl_nvdimm_bridge *cxl_nvb, struct cxl_nvdimm *cxl_nvd; struct device *dev; - cxl_nvd = kzalloc(sizeof(*cxl_nvd), GFP_KERNEL); + cxl_nvd = kzalloc_obj(*cxl_nvd, GFP_KERNEL); if (!cxl_nvd) return ERR_PTR(-ENOMEM); diff --git a/drivers/cxl/core/pmu.c b/drivers/cxl/core/pmu.c index b3136d7664ab..8eb175c3ff22 100644 --- a/drivers/cxl/core/pmu.c +++ b/drivers/cxl/core/pmu.c @@ -33,7 +33,7 @@ int devm_cxl_pmu_add(struct device *parent, struct cxl_pmu_regs *regs, struct device *dev; int rc; - pmu = kzalloc(sizeof(*pmu), GFP_KERNEL); + pmu = kzalloc_obj(*pmu, GFP_KERNEL); if (!pmu) return -ENOMEM; diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index fea8d5f5f331..491c7485db60 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -688,11 +688,11 @@ static struct cxl_port *cxl_port_alloc(struct device *uport_dev, /* No parent_dport, root cxl_port */ if (!parent_dport) { - cxl_root = kzalloc(sizeof(*cxl_root), GFP_KERNEL); + cxl_root = kzalloc_obj(*cxl_root, GFP_KERNEL); if (!cxl_root) return ERR_PTR(-ENOMEM); } else { - _port = kzalloc(sizeof(*port), GFP_KERNEL); + _port = kzalloc_obj(*port, GFP_KERNEL); if (!_port) return ERR_PTR(-ENOMEM); } @@ -1184,7 +1184,7 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev, CXL_TARGET_STRLEN) return ERR_PTR(-EINVAL); - dport = kzalloc(sizeof(*dport), GFP_KERNEL); + dport = kzalloc_obj(*dport, GFP_KERNEL); if (!dport) return ERR_PTR(-ENOMEM); @@ -1350,7 +1350,7 @@ static int cxl_add_ep(struct cxl_dport *dport, struct device *ep_dev) struct cxl_ep *ep; int rc; - ep = kzalloc(sizeof(*ep), GFP_KERNEL); + ep = kzalloc_obj(*ep, GFP_KERNEL); if (!ep) return -ENOMEM; @@ -2017,8 +2017,7 @@ struct cxl_root_decoder *cxl_root_decoder_alloc(struct cxl_port *port, if (!is_cxl_root(port)) return ERR_PTR(-EINVAL); - cxlrd = kzalloc(struct_size(cxlrd, cxlsd.target, nr_targets), - GFP_KERNEL); + cxlrd = kzalloc_flex(*cxlrd, cxlsd.target, nr_targets, GFP_KERNEL); if (!cxlrd) return ERR_PTR(-ENOMEM); @@ -2071,7 +2070,7 @@ struct cxl_switch_decoder *cxl_switch_decoder_alloc(struct cxl_port *port, if (is_cxl_root(port) || is_cxl_endpoint(port)) return ERR_PTR(-EINVAL); - cxlsd = kzalloc(struct_size(cxlsd, target, nr_targets), GFP_KERNEL); + cxlsd = kzalloc_flex(*cxlsd, target, nr_targets, GFP_KERNEL); if (!cxlsd) return ERR_PTR(-ENOMEM); @@ -2102,7 +2101,7 @@ struct cxl_endpoint_decoder *cxl_endpoint_decoder_alloc(struct cxl_port *port) if (!is_cxl_endpoint(port)) return ERR_PTR(-EINVAL); - cxled = kzalloc(sizeof(*cxled), GFP_KERNEL); + cxled = kzalloc_obj(*cxled, GFP_KERNEL); if (!cxled) return ERR_PTR(-ENOMEM); diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 08fa3deef70a..288448cff91b 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -998,7 +998,7 @@ alloc_region_ref(struct cxl_port *port, struct cxl_region *cxlr, return ERR_PTR(-EBUSY); } - cxl_rr = kzalloc(sizeof(*cxl_rr), GFP_KERNEL); + cxl_rr = kzalloc_obj(*cxl_rr, GFP_KERNEL); if (!cxl_rr) return ERR_PTR(-ENOMEM); cxl_rr->port = port; @@ -2474,7 +2474,7 @@ static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int i struct cxl_region *cxlr; struct device *dev; - cxlr = kzalloc(sizeof(*cxlr), GFP_KERNEL); + cxlr = kzalloc_obj(*cxlr, GFP_KERNEL); if (!cxlr) { memregion_free(id); return ERR_PTR(-ENOMEM); @@ -3464,7 +3464,7 @@ static int cxl_pmem_region_alloc(struct cxl_region *cxlr) return -ENXIO; struct cxl_pmem_region *cxlr_pmem __free(kfree) = - kzalloc(struct_size(cxlr_pmem, mapping, p->nr_targets), GFP_KERNEL); + kzalloc_flex(*cxlr_pmem, mapping, p->nr_targets, GFP_KERNEL); if (!cxlr_pmem) return -ENOMEM; @@ -3552,7 +3552,7 @@ static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr) if (p->state != CXL_CONFIG_COMMIT) return ERR_PTR(-ENXIO); - cxlr_dax = kzalloc(sizeof(*cxlr_dax), GFP_KERNEL); + cxlr_dax = kzalloc_obj(*cxlr_dax, GFP_KERNEL); if (!cxlr_dax) return ERR_PTR(-ENOMEM); @@ -3835,7 +3835,7 @@ static int __construct_region(struct cxl_region *cxlr, set_bit(CXL_REGION_F_AUTO, &cxlr->flags); cxlr->hpa_range = *hpa_range; - res = kmalloc(sizeof(*res), GFP_KERNEL); + res = kmalloc_obj(*res, GFP_KERNEL); if (!res) return -ENOMEM; diff --git a/drivers/cxl/pmem.c b/drivers/cxl/pmem.c index e197883690ef..ead92ca37a4e 100644 --- a/drivers/cxl/pmem.c +++ b/drivers/cxl/pmem.c @@ -234,7 +234,7 @@ static int cxl_pmem_set_config_data(struct cxl_memdev_state *mds, return -EINVAL; set_lsa = - kvzalloc(struct_size(set_lsa, data, cmd->in_length), GFP_KERNEL); + kvzalloc_flex(*set_lsa, data, cmd->in_length, GFP_KERNEL); if (!set_lsa) return -ENOMEM; @@ -426,7 +426,7 @@ static int cxl_pmem_region_probe(struct device *dev) set_bit(ND_REGION_CXL, &ndr_desc.flags); set_bit(ND_REGION_PERSIST_MEMCTRL, &ndr_desc.flags); - info = kmalloc_array(cxlr_pmem->nr_mappings, sizeof(*info), GFP_KERNEL); + info = kmalloc_objs(*info, cxlr_pmem->nr_mappings, GFP_KERNEL); if (!info) return -ENOMEM; |
