summaryrefslogtreecommitdiff
path: root/drivers/nvmem
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-20 23:49:23 -0800
committerKees Cook <kees@kernel.org>2026-02-21 01:02:28 -0800
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/nvmem
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (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/nvmem')
-rw-r--r--drivers/nvmem/core.c6
-rw-r--r--drivers/nvmem/layouts.c2
2 files changed, 4 insertions, 4 deletions
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index c6180cf1dd91..2c838c0b2b7d 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -650,7 +650,7 @@ int nvmem_add_one_cell(struct nvmem_device *nvmem,
struct nvmem_cell_entry *cell;
int rval;
- cell = kzalloc(sizeof(*cell), GFP_KERNEL);
+ cell = kzalloc_obj(*cell, GFP_KERNEL);
if (!cell)
return -ENOMEM;
@@ -908,7 +908,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
if (!config->reg_read && !config->reg_write)
return ERR_PTR(-EINVAL);
- nvmem = kzalloc(sizeof(*nvmem), GFP_KERNEL);
+ nvmem = kzalloc_obj(*nvmem, GFP_KERNEL);
if (!nvmem)
return ERR_PTR(-ENOMEM);
@@ -1295,7 +1295,7 @@ static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry,
struct nvmem_cell *cell;
const char *name = NULL;
- cell = kzalloc(sizeof(*cell), GFP_KERNEL);
+ cell = kzalloc_obj(*cell, GFP_KERNEL);
if (!cell)
return ERR_PTR(-ENOMEM);
diff --git a/drivers/nvmem/layouts.c b/drivers/nvmem/layouts.c
index 7ebe53249035..13d5b9941059 100644
--- a/drivers/nvmem/layouts.c
+++ b/drivers/nvmem/layouts.c
@@ -96,7 +96,7 @@ static int nvmem_layout_create_device(struct nvmem_device *nvmem,
struct device *dev;
int ret;
- layout = kzalloc(sizeof(*layout), GFP_KERNEL);
+ layout = kzalloc_obj(*layout, GFP_KERNEL);
if (!layout)
return -ENOMEM;