summaryrefslogtreecommitdiff
path: root/drivers/memstick/core
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/memstick/core
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
downloadlinux-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/memstick/core')
-rw-r--r--drivers/memstick/core/memstick.c3
-rw-r--r--drivers/memstick/core/ms_block.c7
-rw-r--r--drivers/memstick/core/mspro_block.c11
3 files changed, 9 insertions, 12 deletions
diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
index acafc910bbac..d3641ba53bc9 100644
--- a/drivers/memstick/core/memstick.c
+++ b/drivers/memstick/core/memstick.c
@@ -380,8 +380,7 @@ EXPORT_SYMBOL(memstick_set_rw_addr);
static struct memstick_dev *memstick_alloc_card(struct memstick_host *host)
{
- struct memstick_dev *card = kzalloc(sizeof(struct memstick_dev),
- GFP_KERNEL);
+ struct memstick_dev *card = kzalloc_obj(struct memstick_dev, GFP_KERNEL);
struct memstick_dev *old_card = host->card;
struct ms_id_register id_reg;
diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
index 1af157ce0a63..6835849bf309 100644
--- a/drivers/memstick/core/ms_block.c
+++ b/drivers/memstick/core/ms_block.c
@@ -1203,8 +1203,7 @@ static int msb_read_boot_blocks(struct msb_data *msb)
dbg_verbose("Start of a scan for the boot blocks");
if (!msb->boot_page) {
- page = kmalloc_array(2, sizeof(struct ms_boot_page),
- GFP_KERNEL);
+ page = kmalloc_objs(struct ms_boot_page, 2, GFP_KERNEL);
if (!page)
return -ENOMEM;
@@ -2151,7 +2150,7 @@ static int msb_probe(struct memstick_dev *card)
struct msb_data *msb;
int rc = 0;
- msb = kzalloc(sizeof(struct msb_data), GFP_KERNEL);
+ msb = kzalloc_obj(struct msb_data, GFP_KERNEL);
if (!msb)
return -ENOMEM;
memstick_set_drvdata(card, msb);
@@ -2225,7 +2224,7 @@ static int msb_resume(struct memstick_dev *card)
#endif
mutex_lock(&card->host->lock);
- new_msb = kzalloc(sizeof(struct msb_data), GFP_KERNEL);
+ new_msb = kzalloc_obj(struct msb_data, GFP_KERNEL);
if (!new_msb)
goto out;
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index e507bb11c802..57c2b28f88bd 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -939,9 +939,8 @@ static int mspro_block_read_attributes(struct memstick_dev *card)
} else
attr_count = attr->count;
- msb->attr_group.attrs = kcalloc(attr_count + 1,
- sizeof(*msb->attr_group.attrs),
- GFP_KERNEL);
+ msb->attr_group.attrs = kzalloc_objs(*msb->attr_group.attrs,
+ attr_count + 1, GFP_KERNEL);
if (!msb->attr_group.attrs) {
rc = -ENOMEM;
goto out_free_attr;
@@ -955,7 +954,7 @@ static int mspro_block_read_attributes(struct memstick_dev *card)
}
for (cnt = 0; cnt < attr_count; ++cnt) {
- s_attr = kzalloc(sizeof(struct mspro_sys_attr), GFP_KERNEL);
+ s_attr = kzalloc_obj(struct mspro_sys_attr, GFP_KERNEL);
if (!s_attr) {
rc = -ENOMEM;
goto out_free_buffer;
@@ -1211,7 +1210,7 @@ static int mspro_block_probe(struct memstick_dev *card)
struct mspro_block_data *msb;
int rc = 0;
- msb = kzalloc(sizeof(struct mspro_block_data), GFP_KERNEL);
+ msb = kzalloc_obj(struct mspro_block_data, GFP_KERNEL);
if (!msb)
return -ENOMEM;
memstick_set_drvdata(card, msb);
@@ -1298,7 +1297,7 @@ static int mspro_block_resume(struct memstick_dev *card)
unsigned char cnt;
mutex_lock(&host->lock);
- new_msb = kzalloc(sizeof(struct mspro_block_data), GFP_KERNEL);
+ new_msb = kzalloc_obj(struct mspro_block_data, GFP_KERNEL);
if (!new_msb) {
rc = -ENOMEM;
goto out_unlock;