summaryrefslogtreecommitdiff
path: root/drivers/mtd
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/mtd
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/mtd')
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0001.c15
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0002.c9
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0020.c7
-rw-r--r--drivers/mtd/chips/cfi_probe.c3
-rw-r--r--drivers/mtd/chips/gen_probe.c2
-rw-r--r--drivers/mtd/chips/jedec_probe.c3
-rw-r--r--drivers/mtd/chips/map_absent.c2
-rw-r--r--drivers/mtd/chips/map_ram.c2
-rw-r--r--drivers/mtd/chips/map_rom.c2
-rw-r--r--drivers/mtd/devices/block2mtd.c2
-rw-r--r--drivers/mtd/devices/docg3.c4
-rw-r--r--drivers/mtd/devices/ms02-nv.c12
-rw-r--r--drivers/mtd/devices/mtd_dataflash.c2
-rw-r--r--drivers/mtd/devices/mtd_intel_dg.c4
-rw-r--r--drivers/mtd/devices/mtdram.c2
-rw-r--r--drivers/mtd/devices/phram.c2
-rw-r--r--drivers/mtd/devices/pmc551.c4
-rw-r--r--drivers/mtd/devices/slram.c6
-rw-r--r--drivers/mtd/ftl.c12
-rw-r--r--drivers/mtd/inftlcore.c2
-rw-r--r--drivers/mtd/lpddr/lpddr_cmds.c5
-rw-r--r--drivers/mtd/lpddr/qinfo_probe.c5
-rw-r--r--drivers/mtd/maps/amd76xrom.c2
-rw-r--r--drivers/mtd/maps/ck804xrom.c2
-rw-r--r--drivers/mtd/maps/esb2rom.c2
-rw-r--r--drivers/mtd/maps/ichxrom.c2
-rw-r--r--drivers/mtd/maps/pci.c2
-rw-r--r--drivers/mtd/maps/pcmciamtd.c2
-rw-r--r--drivers/mtd/maps/pismo.c2
-rw-r--r--drivers/mtd/maps/plat-ram.c2
-rw-r--r--drivers/mtd/maps/pxa2xx-flash.c2
-rw-r--r--drivers/mtd/maps/sa1100-flash.c4
-rw-r--r--drivers/mtd/maps/sun_uflash.c2
-rw-r--r--drivers/mtd/maps/vmu-flash.c14
-rw-r--r--drivers/mtd/mtd_blkdevs.c2
-rw-r--r--drivers/mtd/mtdblock.c2
-rw-r--r--drivers/mtd/mtdblock_ro.c2
-rw-r--r--drivers/mtd/mtdchar.c6
-rw-r--r--drivers/mtd/mtdconcat.c7
-rw-r--r--drivers/mtd/mtdpart.c2
-rw-r--r--drivers/mtd/mtdswap.c4
-rw-r--r--drivers/mtd/nand/ecc-sw-bch.c2
-rw-r--r--drivers/mtd/nand/ecc-sw-hamming.c2
-rw-r--r--drivers/mtd/nand/onenand/generic.c2
-rw-r--r--drivers/mtd/nand/onenand/onenand_base.c5
-rw-r--r--drivers/mtd/nand/onenand/onenand_bbt.c2
-rw-r--r--drivers/mtd/nand/qpic_common.c4
-rw-r--r--drivers/mtd/nand/raw/au1550nd.c2
-rw-r--r--drivers/mtd/nand/raw/cafe_nand.c2
-rw-r--r--drivers/mtd/nand/raw/cs553x_nand.c2
-rw-r--r--drivers/mtd/nand/raw/fsl_elbc_nand.c4
-rw-r--r--drivers/mtd/nand/raw/fsl_ifc_nand.c2
-rw-r--r--drivers/mtd/nand/raw/nand_base.c6
-rw-r--r--drivers/mtd/nand/raw/nand_bbt.c2
-rw-r--r--drivers/mtd/nand/raw/nand_hynix.c2
-rw-r--r--drivers/mtd/nand/raw/nand_jedec.c2
-rw-r--r--drivers/mtd/nand/raw/nand_micron.c2
-rw-r--r--drivers/mtd/nand/raw/nand_onfi.c2
-rw-r--r--drivers/mtd/nand/raw/nandsim.c8
-rw-r--r--drivers/mtd/nand/raw/pasemi_nand.c2
-rw-r--r--drivers/mtd/nand/raw/r852.c4
-rw-r--r--drivers/mtd/nand/raw/sharpsl.c2
-rw-r--r--drivers/mtd/nand/raw/txx9ndfmc.c3
-rw-r--r--drivers/mtd/nand/spi/core.c2
-rw-r--r--drivers/mtd/nand/spi/gigadevice.c2
-rw-r--r--drivers/mtd/nand/spi/macronix.c2
-rw-r--r--drivers/mtd/nftlcore.c2
-rw-r--r--drivers/mtd/parsers/bcm47xxpart.c4
-rw-r--r--drivers/mtd/parsers/brcm_u-boot.c2
-rw-r--r--drivers/mtd/parsers/ofpart_core.c4
-rw-r--r--drivers/mtd/parsers/parser_trx.c4
-rw-r--r--drivers/mtd/parsers/qcomsmempart.c2
-rw-r--r--drivers/mtd/parsers/redboot.c2
-rw-r--r--drivers/mtd/parsers/scpart.c6
-rw-r--r--drivers/mtd/parsers/sharpslpart.c5
-rw-r--r--drivers/mtd/parsers/tplink_safeloader.c2
-rw-r--r--drivers/mtd/rfd_ftl.c8
-rw-r--r--drivers/mtd/sm_ftl.c15
-rw-r--r--drivers/mtd/spi-nor/core.c2
-rw-r--r--drivers/mtd/spi-nor/sfdp.c2
-rw-r--r--drivers/mtd/ssfdc.c2
-rw-r--r--drivers/mtd/tests/stresstest.c2
-rw-r--r--drivers/mtd/ubi/attach.c4
-rw-r--r--drivers/mtd/ubi/block.c2
-rw-r--r--drivers/mtd/ubi/build.c2
-rw-r--r--drivers/mtd/ubi/cdev.c6
-rw-r--r--drivers/mtd/ubi/eba.c21
-rw-r--r--drivers/mtd/ubi/fastmap-wl.c2
-rw-r--r--drivers/mtd/ubi/fastmap.c8
-rw-r--r--drivers/mtd/ubi/gluebi.c2
-rw-r--r--drivers/mtd/ubi/kapi.c2
-rw-r--r--drivers/mtd/ubi/nvmem.c2
-rw-r--r--drivers/mtd/ubi/ubi.h2
-rw-r--r--drivers/mtd/ubi/vmt.c2
-rw-r--r--drivers/mtd/ubi/vtbl.c4
-rw-r--r--drivers/mtd/ubi/wl.c4
96 files changed, 175 insertions, 192 deletions
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index c10693ba265b..9a54e390cd44 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -501,7 +501,7 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
struct mtd_info *mtd;
int i;
- mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
+ mtd = kzalloc_obj(*mtd, GFP_KERNEL);
if (!mtd)
return NULL;
mtd->priv = map;
@@ -627,9 +627,8 @@ static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
mtd->size = devsize * cfi->numchips;
mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips;
- mtd->eraseregions = kcalloc(mtd->numeraseregions,
- sizeof(struct mtd_erase_region_info),
- GFP_KERNEL);
+ mtd->eraseregions = kzalloc_objs(struct mtd_erase_region_info,
+ mtd->numeraseregions, GFP_KERNEL);
if (!mtd->eraseregions)
goto setup_err;
@@ -777,13 +776,11 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
}
numvirtchips = cfi->numchips * numparts;
- newcfi = kmalloc(struct_size(newcfi, chips, numvirtchips),
- GFP_KERNEL);
+ newcfi = kmalloc_flex(*newcfi, chips, numvirtchips, GFP_KERNEL);
if (!newcfi)
return -ENOMEM;
- shared = kmalloc_array(cfi->numchips,
- sizeof(struct flchip_shared),
- GFP_KERNEL);
+ shared = kmalloc_objs(struct flchip_shared, cfi->numchips,
+ GFP_KERNEL);
if (!shared) {
kfree(newcfi);
return -ENOMEM;
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index 7c91429a670b..efb3ba02432e 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -604,7 +604,7 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
struct mtd_info *mtd;
int i;
- mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
+ mtd = kzalloc_obj(*mtd, GFP_KERNEL);
if (!mtd)
return NULL;
mtd->priv = map;
@@ -776,9 +776,8 @@ static struct mtd_info *cfi_amdstd_setup(struct mtd_info *mtd)
mtd->size = devsize * cfi->numchips;
mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips;
- mtd->eraseregions = kmalloc_array(mtd->numeraseregions,
- sizeof(struct mtd_erase_region_info),
- GFP_KERNEL);
+ mtd->eraseregions = kmalloc_objs(struct mtd_erase_region_info,
+ mtd->numeraseregions, GFP_KERNEL);
if (!mtd->eraseregions)
goto setup_err;
@@ -2819,7 +2818,7 @@ static int __maybe_unused cfi_ppb_unlock(struct mtd_info *mtd, loff_t ofs,
for (i = 0; i < mtd->numeraseregions; i++)
max_sectors += regions[i].numblocks;
- sect = kcalloc(max_sectors, sizeof(struct ppb_lock), GFP_KERNEL);
+ sect = kzalloc_objs(struct ppb_lock, max_sectors, GFP_KERNEL);
if (!sect)
return -ENOMEM;
diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index 5e5266e2c2e1..5665d3b72da1 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -172,7 +172,7 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
int i,j;
unsigned long devsize = (1<<cfi->cfiq->DevSize) * cfi->interleave;
- mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
+ mtd = kzalloc_obj(*mtd, GFP_KERNEL);
//printk(KERN_DEBUG "number of CFI chips: %d\n", cfi->numchips);
if (!mtd) {
@@ -185,9 +185,8 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
mtd->size = devsize * cfi->numchips;
mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips;
- mtd->eraseregions = kmalloc_array(mtd->numeraseregions,
- sizeof(struct mtd_erase_region_info),
- GFP_KERNEL);
+ mtd->eraseregions = kmalloc_objs(struct mtd_erase_region_info,
+ mtd->numeraseregions, GFP_KERNEL);
if (!mtd->eraseregions) {
kfree(cfi->cmdset_priv);
kfree(mtd);
diff --git a/drivers/mtd/chips/cfi_probe.c b/drivers/mtd/chips/cfi_probe.c
index e254f9cd2796..926bf7b61e59 100644
--- a/drivers/mtd/chips/cfi_probe.c
+++ b/drivers/mtd/chips/cfi_probe.c
@@ -208,7 +208,8 @@ static int __xipram cfi_chip_setup(struct map_info *map,
if (!num_erase_regions)
return 0;
- cfi->cfiq = kmalloc(struct_size(cfi->cfiq, EraseRegionInfo, num_erase_regions), GFP_KERNEL);
+ cfi->cfiq = kmalloc_flex(*cfi->cfiq, EraseRegionInfo, num_erase_regions,
+ GFP_KERNEL);
if (!cfi->cfiq)
return 0;
diff --git a/drivers/mtd/chips/gen_probe.c b/drivers/mtd/chips/gen_probe.c
index 9e53fcd7600d..ebf653ba8f6a 100644
--- a/drivers/mtd/chips/gen_probe.c
+++ b/drivers/mtd/chips/gen_probe.c
@@ -134,7 +134,7 @@ static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chi
* our caller, and copy the appropriate data into them.
*/
- retcfi = kmalloc(struct_size(retcfi, chips, cfi.numchips), GFP_KERNEL);
+ retcfi = kmalloc_flex(*retcfi, chips, cfi.numchips, GFP_KERNEL);
if (!retcfi) {
kfree(cfi.cfiq);
diff --git a/drivers/mtd/chips/jedec_probe.c b/drivers/mtd/chips/jedec_probe.c
index 3c631608f6d6..d7acf0425e4f 100644
--- a/drivers/mtd/chips/jedec_probe.c
+++ b/drivers/mtd/chips/jedec_probe.c
@@ -1985,7 +1985,8 @@ static int cfi_jedec_setup(struct map_info *map, struct cfi_private *cfi, int in
num_erase_regions = jedec_table[index].nr_regions;
- cfi->cfiq = kmalloc(struct_size(cfi->cfiq, EraseRegionInfo, num_erase_regions), GFP_KERNEL);
+ cfi->cfiq = kmalloc_flex(*cfi->cfiq, EraseRegionInfo, num_erase_regions,
+ GFP_KERNEL);
if (!cfi->cfiq) {
//xx printk(KERN_WARNING "%s: kmalloc failed for CFI ident structure\n", map->name);
return 0;
diff --git a/drivers/mtd/chips/map_absent.c b/drivers/mtd/chips/map_absent.c
index fc68557f49c0..6a9bd84a6def 100644
--- a/drivers/mtd/chips/map_absent.c
+++ b/drivers/mtd/chips/map_absent.c
@@ -46,7 +46,7 @@ static struct mtd_info *map_absent_probe(struct map_info *map)
{
struct mtd_info *mtd;
- mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
+ mtd = kzalloc_obj(*mtd, GFP_KERNEL);
if (!mtd) {
return NULL;
}
diff --git a/drivers/mtd/chips/map_ram.c b/drivers/mtd/chips/map_ram.c
index f9d3e32ef8e9..f94d20672423 100644
--- a/drivers/mtd/chips/map_ram.c
+++ b/drivers/mtd/chips/map_ram.c
@@ -57,7 +57,7 @@ static struct mtd_info *map_ram_probe(struct map_info *map)
#endif
/* OK. It seems to be RAM. */
- mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
+ mtd = kzalloc_obj(*mtd, GFP_KERNEL);
if (!mtd)
return NULL;
diff --git a/drivers/mtd/chips/map_rom.c b/drivers/mtd/chips/map_rom.c
index 0823b15aaadb..644ef8d62cc8 100644
--- a/drivers/mtd/chips/map_rom.c
+++ b/drivers/mtd/chips/map_rom.c
@@ -45,7 +45,7 @@ static struct mtd_info *map_rom_probe(struct map_info *map)
{
struct mtd_info *mtd;
- mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
+ mtd = kzalloc_obj(*mtd, GFP_KERNEL);
if (!mtd)
return NULL;
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index b06c8dd51562..41b1c1348efe 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -271,7 +271,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size,
if (!devname)
return NULL;
- dev = kzalloc(sizeof(struct block2mtd_dev), GFP_KERNEL);
+ dev = kzalloc_obj(struct block2mtd_dev, GFP_KERNEL);
if (!dev)
return NULL;
diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
index c93769c233d9..8db760b2c900 100644
--- a/drivers/mtd/devices/docg3.c
+++ b/drivers/mtd/devices/docg3.c
@@ -1810,10 +1810,10 @@ doc_probe_device(struct docg3_cascade *cascade, int floor, struct device *dev)
struct mtd_info *mtd;
ret = -ENOMEM;
- docg3 = kzalloc(sizeof(struct docg3), GFP_KERNEL);
+ docg3 = kzalloc_obj(struct docg3, GFP_KERNEL);
if (!docg3)
goto nomem1;
- mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
+ mtd = kzalloc_obj(struct mtd_info, GFP_KERNEL);
if (!mtd)
goto nomem2;
mtd->priv = docg3;
diff --git a/drivers/mtd/devices/ms02-nv.c b/drivers/mtd/devices/ms02-nv.c
index 08f76ff839a7..0a5d6ca1fe2f 100644
--- a/drivers/mtd/devices/ms02-nv.c
+++ b/drivers/mtd/devices/ms02-nv.c
@@ -117,7 +117,7 @@ static int __init ms02nv_init_one(ulong addr)
int ret = -ENODEV;
/* The module decodes 8MiB of address space. */
- mod_res = kzalloc(sizeof(*mod_res), GFP_KERNEL);
+ mod_res = kzalloc_obj(*mod_res, GFP_KERNEL);
if (!mod_res)
return -ENOMEM;
@@ -138,10 +138,10 @@ static int __init ms02nv_init_one(ulong addr)
}
ret = -ENOMEM;
- mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
+ mtd = kzalloc_obj(*mtd, GFP_KERNEL);
if (!mtd)
goto err_out_mod_res_rel;
- mp = kzalloc(sizeof(*mp), GFP_KERNEL);
+ mp = kzalloc_obj(*mp, GFP_KERNEL);
if (!mp)
goto err_out_mtd;
@@ -149,7 +149,7 @@ static int __init ms02nv_init_one(ulong addr)
mp->resource.module = mod_res;
/* Firmware's diagnostic NVRAM area. */
- diag_res = kzalloc(sizeof(*diag_res), GFP_KERNEL);
+ diag_res = kzalloc_obj(*diag_res, GFP_KERNEL);
if (!diag_res)
goto err_out_mp;
@@ -162,7 +162,7 @@ static int __init ms02nv_init_one(ulong addr)
mp->resource.diag_ram = diag_res;
/* User-available general-purpose NVRAM area. */
- user_res = kzalloc(sizeof(*user_res), GFP_KERNEL);
+ user_res = kzalloc_obj(*user_res, GFP_KERNEL);
if (!user_res)
goto err_out_diag_res;
@@ -175,7 +175,7 @@ static int __init ms02nv_init_one(ulong addr)
mp->resource.user_ram = user_res;
/* Control and status register. */
- csr_res = kzalloc(sizeof(*csr_res), GFP_KERNEL);
+ csr_res = kzalloc_obj(*csr_res, GFP_KERNEL);
if (!csr_res)
goto err_out_user_res;
diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c
index ec52277e3dd5..3eebca290f50 100644
--- a/drivers/mtd/devices/mtd_dataflash.c
+++ b/drivers/mtd/devices/mtd_dataflash.c
@@ -627,7 +627,7 @@ static int add_dataflash_otp(struct spi_device *spi, char *name, int nr_pages,
char *otp_tag = "";
int err = 0;
- priv = kzalloc(sizeof *priv, GFP_KERNEL);
+ priv = kzalloc_obj(*priv, GFP_KERNEL);
if (!priv)
return -ENOMEM;
diff --git a/drivers/mtd/devices/mtd_intel_dg.c b/drivers/mtd/devices/mtd_intel_dg.c
index 7f751c48a76d..ed5a07459012 100644
--- a/drivers/mtd/devices/mtd_intel_dg.c
+++ b/drivers/mtd/devices/mtd_intel_dg.c
@@ -720,7 +720,7 @@ static int intel_dg_nvm_init_mtd(struct intel_dg_nvm *nvm, struct device *device
nvm->mtd.erasesize = SZ_4K; /* 4K bytes granularity */
nvm->mtd.size = nvm->size;
- parts = kcalloc(nvm->nregions, sizeof(*parts), GFP_KERNEL);
+ parts = kzalloc_objs(*parts, nvm->nregions, GFP_KERNEL);
if (!parts)
return -ENOMEM;
@@ -764,7 +764,7 @@ static int intel_dg_mtd_probe(struct auxiliary_device *aux_dev,
return -ENODEV;
}
- nvm = kzalloc(struct_size(nvm, regions, nregions), GFP_KERNEL);
+ nvm = kzalloc_flex(*nvm, regions, nregions, GFP_KERNEL);
if (!nvm)
return -ENOMEM;
diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index 1c97fabc4bf9..5418cfcfb1d9 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -158,7 +158,7 @@ static int __init init_mtdram(void)
return -EINVAL;
/* Allocate some memory */
- mtd_info = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
+ mtd_info = kmalloc_obj(struct mtd_info, GFP_KERNEL);
if (!mtd_info)
return -ENOMEM;
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index fd9ec165e61a..d35f43dec8e3 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -130,7 +130,7 @@ static int register_device(struct platform_device *pdev, const char *name,
struct phram_mtd_list *new;
int ret = -ENOMEM;
- new = kzalloc(sizeof(*new), GFP_KERNEL);
+ new = kzalloc_obj(*new, GFP_KERNEL);
if (!new)
goto out0;
diff --git a/drivers/mtd/devices/pmc551.c b/drivers/mtd/devices/pmc551.c
index 6597fc2aad34..1d793bf7ad71 100644
--- a/drivers/mtd/devices/pmc551.c
+++ b/drivers/mtd/devices/pmc551.c
@@ -715,11 +715,11 @@ static int __init init_pmc551(void)
msize = length;
}
- mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
+ mtd = kzalloc_obj(struct mtd_info, GFP_KERNEL);
if (!mtd)
break;
- priv = kzalloc(sizeof(struct mypriv), GFP_KERNEL);
+ priv = kzalloc_obj(struct mypriv, GFP_KERNEL);
if (!priv) {
kfree(mtd);
break;
diff --git a/drivers/mtd/devices/slram.c b/drivers/mtd/devices/slram.c
index 8297b366a066..1ac94e837f26 100644
--- a/drivers/mtd/devices/slram.c
+++ b/drivers/mtd/devices/slram.c
@@ -135,17 +135,17 @@ static int register_device(char *name, unsigned long start, unsigned long length
curmtd = &(*curmtd)->next;
}
- *curmtd = kmalloc(sizeof(slram_mtd_list_t), GFP_KERNEL);
+ *curmtd = kmalloc_obj(slram_mtd_list_t, GFP_KERNEL);
if (!(*curmtd)) {
E("slram: Cannot allocate new MTD device.\n");
return(-ENOMEM);
}
- (*curmtd)->mtdinfo = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
+ (*curmtd)->mtdinfo = kzalloc_obj(struct mtd_info, GFP_KERNEL);
(*curmtd)->next = NULL;
if ((*curmtd)->mtdinfo) {
(*curmtd)->mtdinfo->priv =
- kzalloc(sizeof(slram_priv_t), GFP_KERNEL);
+ kzalloc_obj(slram_priv_t, GFP_KERNEL);
if (!(*curmtd)->mtdinfo->priv) {
kfree((*curmtd)->mtdinfo);
diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index 59a901549257..bc372a0c040d 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -201,16 +201,14 @@ static int build_maps(partition_t *part)
/* Set up erase unit maps */
part->DataUnits = le16_to_cpu(part->header.NumEraseUnits) -
part->header.NumTransferUnits;
- part->EUNInfo = kmalloc_array(part->DataUnits, sizeof(struct eun_info_t),
- GFP_KERNEL);
+ part->EUNInfo = kmalloc_objs(struct eun_info_t, part->DataUnits, GFP_KERNEL);
if (!part->EUNInfo)
goto out;
for (i = 0; i < part->DataUnits; i++)
part->EUNInfo[i].Offset = 0xffffffff;
part->XferInfo =
- kmalloc_array(part->header.NumTransferUnits,
- sizeof(struct xfer_info_t),
- GFP_KERNEL);
+ kmalloc_objs(struct xfer_info_t, part->header.NumTransferUnits,
+ GFP_KERNEL);
if (!part->XferInfo)
goto out_EUNInfo;
@@ -339,7 +337,7 @@ static int erase_xfer(partition_t *part,
/* Is there a free erase slot? Always in MTD. */
- erase=kmalloc(sizeof(struct erase_info), GFP_KERNEL);
+ erase=kmalloc_obj(struct erase_info, GFP_KERNEL);
if (!erase)
return -ENOMEM;
@@ -1007,7 +1005,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
{
partition_t *partition;
- partition = kzalloc(sizeof(partition_t), GFP_KERNEL);
+ partition = kzalloc_obj(partition_t, GFP_KERNEL);
if (!partition) {
printk(KERN_WARNING "No memory to scan for FTL on %s\n",
diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
index 58c6e1743f5c..cde1e3f52a49 100644
--- a/drivers/mtd/inftlcore.c
+++ b/drivers/mtd/inftlcore.c
@@ -52,7 +52,7 @@ static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
pr_debug("INFTL: add_mtd for %s\n", mtd->name);
- inftl = kzalloc(sizeof(*inftl), GFP_KERNEL);
+ inftl = kzalloc_obj(*inftl, GFP_KERNEL);
if (!inftl)
return;
diff --git a/drivers/mtd/lpddr/lpddr_cmds.c b/drivers/mtd/lpddr/lpddr_cmds.c
index cd37d58abacb..97f960af44b4 100644
--- a/drivers/mtd/lpddr/lpddr_cmds.c
+++ b/drivers/mtd/lpddr/lpddr_cmds.c
@@ -41,7 +41,7 @@ struct mtd_info *lpddr_cmdset(struct map_info *map)
int numchips;
int i, j;
- mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
+ mtd = kzalloc_obj(*mtd, GFP_KERNEL);
if (!mtd)
return NULL;
mtd->priv = map;
@@ -65,8 +65,7 @@ struct mtd_info *lpddr_cmdset(struct map_info *map)
mtd->erasesize = 1 << lpddr->qinfo->UniformBlockSizeShift;
mtd->writesize = 1 << lpddr->qinfo->BufSizeShift;
- shared = kmalloc_array(lpddr->numchips, sizeof(struct flchip_shared),
- GFP_KERNEL);
+ shared = kmalloc_objs(struct flchip_shared, lpddr->numchips, GFP_KERNEL);
if (!shared) {
kfree(mtd);
return NULL;
diff --git a/drivers/mtd/lpddr/qinfo_probe.c b/drivers/mtd/lpddr/qinfo_probe.c
index 42281e460c62..9339da9f09a1 100644
--- a/drivers/mtd/lpddr/qinfo_probe.c
+++ b/drivers/mtd/lpddr/qinfo_probe.c
@@ -120,7 +120,7 @@ out:
static int lpddr_chip_setup(struct map_info *map, struct lpddr_private *lpddr)
{
- lpddr->qinfo = kzalloc(sizeof(struct qinfo_chip), GFP_KERNEL);
+ lpddr->qinfo = kzalloc_obj(struct qinfo_chip, GFP_KERNEL);
if (!lpddr->qinfo)
return 0;
@@ -167,8 +167,7 @@ static struct lpddr_private *lpddr_probe_chip(struct map_info *map)
lpddr.numchips = 1;
numvirtchips = lpddr.numchips * lpddr.qinfo->HWPartsNum;
- retlpddr = kzalloc(struct_size(retlpddr, chips, numvirtchips),
- GFP_KERNEL);
+ retlpddr = kzalloc_flex(*retlpddr, chips, numvirtchips, GFP_KERNEL);
if (!retlpddr)
return NULL;
diff --git a/drivers/mtd/maps/amd76xrom.c b/drivers/mtd/maps/amd76xrom.c
index 281fcbaa74e7..1825f8e2898f 100644
--- a/drivers/mtd/maps/amd76xrom.c
+++ b/drivers/mtd/maps/amd76xrom.c
@@ -188,7 +188,7 @@ static int amd76xrom_init_one(struct pci_dev *pdev,
int i;
if (!map) {
- map = kmalloc(sizeof(*map), GFP_KERNEL);
+ map = kmalloc_obj(*map, GFP_KERNEL);
if (!map)
goto out;
}
diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c
index c0216bc740cc..0ac4b26b1dd7 100644
--- a/drivers/mtd/maps/ck804xrom.c
+++ b/drivers/mtd/maps/ck804xrom.c
@@ -218,7 +218,7 @@ static int __init ck804xrom_init_one(struct pci_dev *pdev,
int i;
if (!map) {
- map = kmalloc(sizeof(*map), GFP_KERNEL);
+ map = kmalloc_obj(*map, GFP_KERNEL);
if (!map)
goto out;
}
diff --git a/drivers/mtd/maps/esb2rom.c b/drivers/mtd/maps/esb2rom.c
index 15d5b76ff504..14d050a5629f 100644
--- a/drivers/mtd/maps/esb2rom.c
+++ b/drivers/mtd/maps/esb2rom.c
@@ -278,7 +278,7 @@ static int __init esb2rom_init_one(struct pci_dev *pdev,
int i;
if (!map) {
- map = kmalloc(sizeof(*map), GFP_KERNEL);
+ map = kmalloc_obj(*map, GFP_KERNEL);
if (!map)
goto out;
}
diff --git a/drivers/mtd/maps/ichxrom.c b/drivers/mtd/maps/ichxrom.c
index c8b2793691db..b940beb70b65 100644
--- a/drivers/mtd/maps/ichxrom.c
+++ b/drivers/mtd/maps/ichxrom.c
@@ -212,7 +212,7 @@ static int __init ichxrom_init_one(struct pci_dev *pdev,
int i;
if (!map) {
- map = kmalloc(sizeof(*map), GFP_KERNEL);
+ map = kmalloc_obj(*map, GFP_KERNEL);
if (!map)
goto out;
}
diff --git a/drivers/mtd/maps/pci.c b/drivers/mtd/maps/pci.c
index ca00d211e73e..b70b8edceb1b 100644
--- a/drivers/mtd/maps/pci.c
+++ b/drivers/mtd/maps/pci.c
@@ -264,7 +264,7 @@ static int mtd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
if (err)
goto out;
- map = kmalloc(sizeof(*map), GFP_KERNEL);
+ map = kmalloc_obj(*map, GFP_KERNEL);
err = -ENOMEM;
if (!map)
goto release;
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index 206a3c463e6e..8b7192ff6f04 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -674,7 +674,7 @@ static int pcmciamtd_probe(struct pcmcia_device *link)
struct pcmciamtd_dev *dev;
/* Create new memory card device */
- dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ dev = kzalloc_obj(*dev, GFP_KERNEL);
if (!dev) return -ENOMEM;
pr_debug("dev=0x%p\n", dev);
diff --git a/drivers/mtd/maps/pismo.c b/drivers/mtd/maps/pismo.c
index ecf68922da73..30b95fd3352d 100644
--- a/drivers/mtd/maps/pismo.c
+++ b/drivers/mtd/maps/pismo.c
@@ -218,7 +218,7 @@ static int pismo_probe(struct i2c_client *client)
return -EIO;
}
- pismo = kzalloc(sizeof(*pismo), GFP_KERNEL);
+ pismo = kzalloc_obj(*pismo, GFP_KERNEL);
if (!pismo)
return -ENOMEM;
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index 1c541eaf477a..d0f9b81ad7c5 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -109,7 +109,7 @@ static int platram_probe(struct platform_device *pdev)
pdata = dev_get_platdata(&pdev->dev);
- info = kzalloc(sizeof(*info), GFP_KERNEL);
+ info = kzalloc_obj(*info, GFP_KERNEL);
if (info == NULL) {
err = -ENOMEM;
goto exit_error;
diff --git a/drivers/mtd/maps/pxa2xx-flash.c b/drivers/mtd/maps/pxa2xx-flash.c
index f27c25db6778..5ad7ae7a311c 100644
--- a/drivers/mtd/maps/pxa2xx-flash.c
+++ b/drivers/mtd/maps/pxa2xx-flash.c
@@ -51,7 +51,7 @@ static int pxa2xx_flash_probe(struct platform_device *pdev)
if (!res)
return -ENODEV;
- info = kzalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL);
+ info = kzalloc_obj(struct pxa2xx_flash_info, GFP_KERNEL);
if (!info)
return -ENOMEM;
diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
index 6a54a84d0d9c..ed69df084352 100644
--- a/drivers/mtd/maps/sa1100-flash.c
+++ b/drivers/mtd/maps/sa1100-flash.c
@@ -170,7 +170,7 @@ static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,
/*
* Allocate the map_info structs in one go.
*/
- info = kzalloc(struct_size(info, subdev, nr), GFP_KERNEL);
+ info = kzalloc_flex(*info, subdev, nr, GFP_KERNEL);
if (!info) {
ret = -ENOMEM;
goto out;
@@ -222,7 +222,7 @@ static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,
} else if (info->num_subdev > 1) {
struct mtd_info **cdev;
- cdev = kmalloc_array(nr, sizeof(*cdev), GFP_KERNEL);
+ cdev = kmalloc_objs(*cdev, nr, GFP_KERNEL);
if (!cdev) {
ret = -ENOMEM;
goto err;
diff --git a/drivers/mtd/maps/sun_uflash.c b/drivers/mtd/maps/sun_uflash.c
index ea3aa026b55b..aebbf2931f1c 100644
--- a/drivers/mtd/maps/sun_uflash.c
+++ b/drivers/mtd/maps/sun_uflash.c
@@ -61,7 +61,7 @@ static int uflash_devinit(struct platform_device *op, struct device_node *dp)
return -ENODEV;
}
- up = kzalloc(sizeof(struct uflash_dev), GFP_KERNEL);
+ up = kzalloc_obj(struct uflash_dev, GFP_KERNEL);
if (!up)
return -ENOMEM;
diff --git a/drivers/mtd/maps/vmu-flash.c b/drivers/mtd/maps/vmu-flash.c
index 53019d313db7..bd4ebcde51db 100644
--- a/drivers/mtd/maps/vmu-flash.c
+++ b/drivers/mtd/maps/vmu-flash.c
@@ -73,7 +73,7 @@ static struct vmu_block *ofs_to_block(unsigned long src_ofs,
if (num > card->parts[partition].numblocks)
goto failed;
- vblock = kmalloc(sizeof(struct vmu_block), GFP_KERNEL);
+ vblock = kmalloc_obj(struct vmu_block, GFP_KERNEL);
if (!vblock)
goto failed;
@@ -539,7 +539,7 @@ static void vmu_queryblocks(struct mapleq *mq)
mtd_cur->_sync = vmu_flash_sync;
mtd_cur->writesize = card->blocklen;
- mpart = kmalloc(sizeof(struct mdev_part), GFP_KERNEL);
+ mpart = kmalloc_obj(struct mdev_part, GFP_KERNEL);
if (!mpart)
goto fail_mpart;
@@ -548,7 +548,7 @@ static void vmu_queryblocks(struct mapleq *mq)
mtd_cur->priv = mpart;
mtd_cur->owner = THIS_MODULE;
- pcache = kzalloc(sizeof(struct vmu_cache), GFP_KERNEL);
+ pcache = kzalloc_obj(struct vmu_cache, GFP_KERNEL);
if (!pcache)
goto fail_cache_create;
part_cur->pcache = pcache;
@@ -609,7 +609,7 @@ static int vmu_connect(struct maple_device *mdev)
basic_flash_data = be32_to_cpu(mdev->devinfo.function_data[c - 1]);
- card = kmalloc(sizeof(struct memcard), GFP_KERNEL);
+ card = kmalloc_obj(struct memcard, GFP_KERNEL);
if (!card) {
error = -ENOMEM;
goto fail_nomem;
@@ -627,15 +627,13 @@ static int vmu_connect(struct maple_device *mdev)
* Not sure there are actually any multi-partition devices in the
* real world, but the hardware supports them, so, so will we
*/
- card->parts = kmalloc_array(card->partitions, sizeof(struct vmupart),
- GFP_KERNEL);
+ card->parts = kmalloc_objs(struct vmupart, card->partitions, GFP_KERNEL);
if (!card->parts) {
error = -ENOMEM;
goto fail_partitions;
}
- card->mtd = kmalloc_array(card->partitions, sizeof(struct mtd_info),
- GFP_KERNEL);
+ card->mtd = kmalloc_objs(struct mtd_info, card->partitions, GFP_KERNEL);
if (!card->mtd) {
error = -ENOMEM;
goto fail_mtd_info;
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 28e09d080440..470a838cbab7 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -324,7 +324,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
new->readonly = 1;
ret = -ENOMEM;
- new->tag_set = kzalloc(sizeof(*new->tag_set), GFP_KERNEL);
+ new->tag_set = kzalloc_obj(*new->tag_set, GFP_KERNEL);
if (!new->tag_set)
goto out_list_del;
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index 9751416c2a91..80614f218228 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -316,7 +316,7 @@ static int mtdblock_flush(struct mtd_blktrans_dev *dev)
static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
{
- struct mtdblk_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ struct mtdblk_dev *dev = kzalloc_obj(*dev, GFP_KERNEL);
if (!dev)
return;
diff --git a/drivers/mtd/mtdblock_ro.c b/drivers/mtd/mtdblock_ro.c
index ef6299af60e4..e82f27eec5ae 100644
--- a/drivers/mtd/mtdblock_ro.c
+++ b/drivers/mtd/mtdblock_ro.c
@@ -36,7 +36,7 @@ static int mtdblock_writesect(struct mtd_blktrans_dev *dev,
static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
{
- struct mtd_blktrans_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ struct mtd_blktrans_dev *dev = kzalloc_obj(*dev, GFP_KERNEL);
if (!dev)
return;
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 335c702633ff..35b31fea77f3 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -72,7 +72,7 @@ static int mtdchar_open(struct inode *inode, struct file *file)
goto out1;
}
- mfi = kzalloc(sizeof(*mfi), GFP_KERNEL);
+ mfi = kzalloc_obj(*mfi, GFP_KERNEL);
if (!mfi) {
ret = -ENOMEM;
goto out1;
@@ -923,7 +923,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
{
struct erase_info *erase;
- erase=kzalloc(sizeof(struct erase_info),GFP_KERNEL);
+ erase=kzalloc_obj(struct erase_info, GFP_KERNEL);
if (!erase)
ret = -ENOMEM;
else {
@@ -1162,7 +1162,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
if (!master->ooblayout)
return -EOPNOTSUPP;
- usrlay = kmalloc(sizeof(*usrlay), GFP_KERNEL);
+ usrlay = kmalloc_obj(*usrlay, GFP_KERNEL);
if (!usrlay)
return -ENOMEM;
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index f56f44aa8625..c4145ba218df 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -416,7 +416,7 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
}
/* make a local copy of instr to avoid modifying the caller's struct */
- erase = kmalloc(sizeof (struct erase_info), GFP_KERNEL);
+ erase = kmalloc_obj(struct erase_info, GFP_KERNEL);
if (!erase)
return -ENOMEM;
@@ -823,9 +823,8 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
concat->mtd.erasesize = max_erasesize;
concat->mtd.numeraseregions = num_erase_region;
concat->mtd.eraseregions = erase_region_p =
- kmalloc_array(num_erase_region,
- sizeof(struct mtd_erase_region_info),
- GFP_KERNEL);
+ kmalloc_objs(struct mtd_erase_region_info, num_erase_region,
+ GFP_KERNEL);
if (!erase_region_p) {
kfree(concat);
printk
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 2876501a7814..2c0be153a96e 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -53,7 +53,7 @@ static struct mtd_info *allocate_partition(struct mtd_info *parent,
u64 tmp;
/* allocate the partition structure */
- child = kzalloc(sizeof(*child), GFP_KERNEL);
+ child = kzalloc_obj(*child, GFP_KERNEL);
name = kstrdup(part->name, GFP_KERNEL);
if (!name || !child) {
printk(KERN_ERR"memory allocation error while creating partitions for \"%s\"\n",
diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c
index d8f2e5be2d31..a2d072da1bbe 100644
--- a/drivers/mtd/mtdswap.c
+++ b/drivers/mtd/mtdswap.c
@@ -1413,11 +1413,11 @@ static void mtdswap_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
"%u spare, %u bad blocks\n",
MTDSWAP_PREFIX, part, swap_size / 1024, spare_cnt, bad_blocks);
- d = kzalloc(sizeof(struct mtdswap_dev), GFP_KERNEL);
+ d = kzalloc_obj(struct mtdswap_dev, GFP_KERNEL);
if (!d)
return;
- mbd_dev = kzalloc(sizeof(struct mtd_blktrans_dev), GFP_KERNEL);
+ mbd_dev = kzalloc_obj(struct mtd_blktrans_dev, GFP_KERNEL);
if (!mbd_dev) {
kfree(d);
return;
diff --git a/drivers/mtd/nand/ecc-sw-bch.c b/drivers/mtd/nand/ecc-sw-bch.c
index 0d9310dd6f52..8ed20f176521 100644
--- a/drivers/mtd/nand/ecc-sw-bch.c
+++ b/drivers/mtd/nand/ecc-sw-bch.c
@@ -227,7 +227,7 @@ int nand_ecc_sw_bch_init_ctx(struct nand_device *nand)
return -EINVAL;
}
- engine_conf = kzalloc(sizeof(*engine_conf), GFP_KERNEL);
+ engine_conf = kzalloc_obj(*engine_conf, GFP_KERNEL);
if (!engine_conf)
return -ENOMEM;
diff --git a/drivers/mtd/nand/ecc-sw-hamming.c b/drivers/mtd/nand/ecc-sw-hamming.c
index bc62a71f9fdd..65fe971a409d 100644
--- a/drivers/mtd/nand/ecc-sw-hamming.c
+++ b/drivers/mtd/nand/ecc-sw-hamming.c
@@ -496,7 +496,7 @@ int nand_ecc_sw_hamming_init_ctx(struct nand_device *nand)
if (conf->step_size != 256 && conf->step_size != 512)
conf->step_size = 256;
- engine_conf = kzalloc(sizeof(*engine_conf), GFP_KERNEL);
+ engine_conf = kzalloc_obj(*engine_conf, GFP_KERNEL);
if (!engine_conf)
return -ENOMEM;
diff --git a/drivers/mtd/nand/onenand/generic.c b/drivers/mtd/nand/onenand/generic.c
index 4e6fd1c34484..69ca617985c8 100644
--- a/drivers/mtd/nand/onenand/generic.c
+++ b/drivers/mtd/nand/onenand/generic.c
@@ -37,7 +37,7 @@ static int generic_onenand_probe(struct platform_device *pdev)
unsigned long size = resource_size(res);
int err;
- info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
+ info = kzalloc_obj(struct onenand_info, GFP_KERNEL);
if (!info)
return -ENOMEM;
diff --git a/drivers/mtd/nand/onenand/onenand_base.c b/drivers/mtd/nand/onenand/onenand_base.c
index 0dc2ea4fc857..e69f46ff2b11 100644
--- a/drivers/mtd/nand/onenand/onenand_base.c
+++ b/drivers/mtd/nand/onenand/onenand_base.c
@@ -3728,9 +3728,8 @@ static int onenand_probe(struct mtd_info *mtd)
/* Maximum possible erase regions */
mtd->numeraseregions = this->dies << 1;
mtd->eraseregions =
- kcalloc(this->dies << 1,
- sizeof(struct mtd_erase_region_info),
- GFP_KERNEL);
+ kzalloc_objs(struct mtd_erase_region_info,
+ this->dies << 1, GFP_KERNEL);
if (!mtd->eraseregions)
return -ENOMEM;
}
diff --git a/drivers/mtd/nand/onenand/onenand_bbt.c b/drivers/mtd/nand/onenand/onenand_bbt.c
index d7fe35bc45cb..380e5051595f 100644
--- a/drivers/mtd/nand/onenand/onenand_bbt.c
+++ b/drivers/mtd/nand/onenand/onenand_bbt.c
@@ -231,7 +231,7 @@ int onenand_default_bbt(struct mtd_info *mtd)
struct onenand_chip *this = mtd->priv;
struct bbm_info *bbm;
- this->bbm = kzalloc(sizeof(struct bbm_info), GFP_KERNEL);
+ this->bbm = kzalloc_obj(struct bbm_info, GFP_KERNEL);
if (!this->bbm)
return -ENOMEM;
diff --git a/drivers/mtd/nand/qpic_common.c b/drivers/mtd/nand/qpic_common.c
index db6c46a6fe01..0acd6c65f326 100644
--- a/drivers/mtd/nand/qpic_common.c
+++ b/drivers/mtd/nand/qpic_common.c
@@ -156,7 +156,7 @@ int qcom_prepare_bam_async_desc(struct qcom_nand_controller *nandc,
enum dma_transfer_direction dir_eng;
struct dma_async_tx_descriptor *dma_desc;
- desc = kzalloc(sizeof(*desc), GFP_KERNEL);
+ desc = kzalloc_obj(*desc, GFP_KERNEL);
if (!desc)
return -ENOMEM;
@@ -364,7 +364,7 @@ int qcom_prep_adm_dma_desc(struct qcom_nand_controller *nandc, bool read,
struct scatterlist *sgl;
int ret;
- desc = kzalloc(sizeof(*desc), GFP_KERNEL);
+ desc = kzalloc_obj(*desc, GFP_KERNEL);
if (!desc)
return -ENOMEM;
diff --git a/drivers/mtd/nand/raw/au1550nd.c b/drivers/mtd/nand/raw/au1550nd.c
index 04d64724c400..6b09eb643ed2 100644
--- a/drivers/mtd/nand/raw/au1550nd.c
+++ b/drivers/mtd/nand/raw/au1550nd.c
@@ -266,7 +266,7 @@ static int au1550nd_probe(struct platform_device *pdev)
return -ENODEV;
}
- ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+ ctx = kzalloc_obj(*ctx, GFP_KERNEL);
if (!ctx)
return -ENOMEM;
diff --git a/drivers/mtd/nand/raw/cafe_nand.c b/drivers/mtd/nand/raw/cafe_nand.c
index 66385c4fb994..b05a41ce2e35 100644
--- a/drivers/mtd/nand/raw/cafe_nand.c
+++ b/drivers/mtd/nand/raw/cafe_nand.c
@@ -678,7 +678,7 @@ static int cafe_nand_probe(struct pci_dev *pdev,
pci_set_master(pdev);
- cafe = kzalloc(sizeof(*cafe), GFP_KERNEL);
+ cafe = kzalloc_obj(*cafe, GFP_KERNEL);
if (!cafe) {
err = -ENOMEM;
goto out_disable_device;
diff --git a/drivers/mtd/nand/raw/cs553x_nand.c b/drivers/mtd/nand/raw/cs553x_nand.c
index ec95d787001b..ca2a7e16b5d8 100644
--- a/drivers/mtd/nand/raw/cs553x_nand.c
+++ b/drivers/mtd/nand/raw/cs553x_nand.c
@@ -273,7 +273,7 @@ static int __init cs553x_init_one(int cs, int mmio, unsigned long adr)
}
/* Allocate memory for MTD device structure and private data */
- controller = kzalloc(sizeof(*controller), GFP_KERNEL);
+ controller = kzalloc_obj(*controller, GFP_KERNEL);
if (!controller) {
err = -ENOMEM;
goto out;
diff --git a/drivers/mtd/nand/raw/fsl_elbc_nand.c b/drivers/mtd/nand/raw/fsl_elbc_nand.c
index 03dbe37df021..fdca096d74ba 100644
--- a/drivers/mtd/nand/raw/fsl_elbc_nand.c
+++ b/drivers/mtd/nand/raw/fsl_elbc_nand.c
@@ -895,13 +895,13 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev)
return -ENODEV;
}
- priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+ priv = kzalloc_obj(*priv, GFP_KERNEL);
if (!priv)
return -ENOMEM;
mutex_lock(&fsl_elbc_nand_mutex);
if (!fsl_lbc_ctrl_dev->nand) {
- elbc_fcm_ctrl = kzalloc(sizeof(*elbc_fcm_ctrl), GFP_KERNEL);
+ elbc_fcm_ctrl = kzalloc_obj(*elbc_fcm_ctrl, GFP_KERNEL);
if (!elbc_fcm_ctrl) {
mutex_unlock(&fsl_elbc_nand_mutex);
ret = -ENOMEM;
diff --git a/drivers/mtd/nand/raw/fsl_ifc_nand.c b/drivers/mtd/nand/raw/fsl_ifc_nand.c
index 7be95d0be248..6eb507f6a204 100644
--- a/drivers/mtd/nand/raw/fsl_ifc_nand.c
+++ b/drivers/mtd/nand/raw/fsl_ifc_nand.c
@@ -1018,7 +1018,7 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)
mutex_lock(&fsl_ifc_nand_mutex);
if (!fsl_ifc_ctrl_dev->nand) {
- ifc_nand_ctrl = kzalloc(sizeof(*ifc_nand_ctrl), GFP_KERNEL);
+ ifc_nand_ctrl = kzalloc_obj(*ifc_nand_ctrl, GFP_KERNEL);
if (!ifc_nand_ctrl) {
mutex_unlock(&fsl_ifc_nand_mutex);
return -ENOMEM;
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index f2322de93ab4..29f603fb2d8f 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -1062,7 +1062,7 @@ static int nand_choose_interface_config(struct nand_chip *chip)
if (!nand_controller_can_setup_interface(chip))
return 0;
- iface = kzalloc(sizeof(*iface), GFP_KERNEL);
+ iface = kzalloc_obj(*iface, GFP_KERNEL);
if (!iface)
return -ENOMEM;
@@ -5429,8 +5429,8 @@ static int of_get_nand_secure_regions(struct nand_chip *chip)
return nr_elem;
chip->nr_secure_regions = nr_elem / 2;
- chip->secure_regions = kcalloc(chip->nr_secure_regions, sizeof(*chip->secure_regions),
- GFP_KERNEL);
+ chip->secure_regions = kzalloc_objs(*chip->secure_regions,
+ chip->nr_secure_regions, GFP_KERNEL);
if (!chip->secure_regions)
return -ENOMEM;
diff --git a/drivers/mtd/nand/raw/nand_bbt.c b/drivers/mtd/nand/raw/nand_bbt.c
index 3050ab7e6eb6..5e500bf2a3c2 100644
--- a/drivers/mtd/nand/raw/nand_bbt.c
+++ b/drivers/mtd/nand/raw/nand_bbt.c
@@ -1375,7 +1375,7 @@ static int nand_create_badblock_pattern(struct nand_chip *this)
pr_warn("Bad block pattern already allocated; not replacing\n");
return -EINVAL;
}
- bd = kzalloc(sizeof(*bd), GFP_KERNEL);
+ bd = kzalloc_obj(*bd, GFP_KERNEL);
if (!bd)
return -ENOMEM;
bd->options = this->bbt_options & BADBLOCK_SCAN_MASK;
diff --git a/drivers/mtd/nand/raw/nand_hynix.c b/drivers/mtd/nand/raw/nand_hynix.c
index b663659b2f49..12f4e5d1038e 100644
--- a/drivers/mtd/nand/raw/nand_hynix.c
+++ b/drivers/mtd/nand/raw/nand_hynix.c
@@ -705,7 +705,7 @@ static int hynix_nand_init(struct nand_chip *chip)
else
chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE;
- hynix = kzalloc(sizeof(*hynix), GFP_KERNEL);
+ hynix = kzalloc_obj(*hynix, GFP_KERNEL);
if (!hynix)
return -ENOMEM;
diff --git a/drivers/mtd/nand/raw/nand_jedec.c b/drivers/mtd/nand/raw/nand_jedec.c
index 89e6dd8ed1a8..8b2725863fbf 100644
--- a/drivers/mtd/nand/raw/nand_jedec.c
+++ b/drivers/mtd/nand/raw/nand_jedec.c
@@ -42,7 +42,7 @@ int nand_jedec_detect(struct nand_chip *chip)
return 0;
/* JEDEC chip: allocate a buffer to hold its parameter page */
- p = kzalloc(sizeof(*p), GFP_KERNEL);
+ p = kzalloc_obj(*p, GFP_KERNEL);
if (!p)
return -ENOMEM;
diff --git a/drivers/mtd/nand/raw/nand_micron.c b/drivers/mtd/nand/raw/nand_micron.c
index c0192881906b..b97a2bd606ae 100644
--- a/drivers/mtd/nand/raw/nand_micron.c
+++ b/drivers/mtd/nand/raw/nand_micron.c
@@ -484,7 +484,7 @@ static int micron_nand_init(struct nand_chip *chip)
int ondie;
int ret;
- micron = kzalloc(sizeof(*micron), GFP_KERNEL);
+ micron = kzalloc_obj(*micron, GFP_KERNEL);
if (!micron)
return -ENOMEM;
diff --git a/drivers/mtd/nand/raw/nand_onfi.c b/drivers/mtd/nand/raw/nand_onfi.c
index 11954440e4de..c4e7304372f1 100644
--- a/drivers/mtd/nand/raw/nand_onfi.c
+++ b/drivers/mtd/nand/raw/nand_onfi.c
@@ -306,7 +306,7 @@ int nand_onfi_detect(struct nand_chip *chip)
if (le16_to_cpu(p->opt_cmd) & ONFI_OPT_CMD_READ_CACHE)
chip->parameters.supports_read_cache = true;
- onfi = kzalloc(sizeof(*onfi), GFP_KERNEL);
+ onfi = kzalloc_obj(*onfi, GFP_KERNEL);
if (!onfi) {
ret = -ENOMEM;
goto free_model;
diff --git a/drivers/mtd/nand/raw/nandsim.c b/drivers/mtd/nand/raw/nandsim.c
index 84942e7e528f..4e7ea6c11a15 100644
--- a/drivers/mtd/nand/raw/nandsim.c
+++ b/drivers/mtd/nand/raw/nandsim.c
@@ -851,7 +851,7 @@ static int ns_parse_weakblocks(void)
}
if (*w == ',')
w += 1;
- wb = kzalloc(sizeof(*wb), GFP_KERNEL);
+ wb = kzalloc_obj(*wb, GFP_KERNEL);
if (!wb) {
NS_ERR("unable to allocate memory.\n");
return -ENOMEM;
@@ -902,7 +902,7 @@ static int ns_parse_weakpages(void)
}
if (*w == ',')
w += 1;
- wp = kzalloc(sizeof(*wp), GFP_KERNEL);
+ wp = kzalloc_obj(*wp, GFP_KERNEL);
if (!wp) {
NS_ERR("unable to allocate memory.\n");
return -ENOMEM;
@@ -953,7 +953,7 @@ static int ns_parse_gravepages(void)
}
if (*g == ',')
g += 1;
- gp = kzalloc(sizeof(*gp), GFP_KERNEL);
+ gp = kzalloc_obj(*gp, GFP_KERNEL);
if (!gp) {
NS_ERR("unable to allocate memory.\n");
return -ENOMEM;
@@ -2268,7 +2268,7 @@ static int __init ns_init_module(void)
return -EINVAL;
}
- ns = kzalloc(sizeof(struct nandsim), GFP_KERNEL);
+ ns = kzalloc_obj(struct nandsim, GFP_KERNEL);
if (!ns) {
NS_ERR("unable to allocate core structures.\n");
return -ENOMEM;
diff --git a/drivers/mtd/nand/raw/pasemi_nand.c b/drivers/mtd/nand/raw/pasemi_nand.c
index 0b1f7670660e..05d3e58c50dc 100644
--- a/drivers/mtd/nand/raw/pasemi_nand.c
+++ b/drivers/mtd/nand/raw/pasemi_nand.c
@@ -113,7 +113,7 @@ static int pasemi_nand_probe(struct platform_device *ofdev)
dev_dbg(dev, "pasemi_nand at %pR\n", &res);
/* Allocate memory for MTD device structure and private data */
- ddata = kzalloc(sizeof(*ddata), GFP_KERNEL);
+ ddata = kzalloc_obj(*ddata, GFP_KERNEL);
if (!ddata) {
err = -ENOMEM;
goto out;
diff --git a/drivers/mtd/nand/raw/r852.c b/drivers/mtd/nand/raw/r852.c
index 918974d088cf..24e702919b87 100644
--- a/drivers/mtd/nand/raw/r852.c
+++ b/drivers/mtd/nand/raw/r852.c
@@ -867,7 +867,7 @@ static int r852_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
error = -ENOMEM;
/* init nand chip, but register it only on card insert */
- chip = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
+ chip = kzalloc_obj(struct nand_chip, GFP_KERNEL);
if (!chip)
goto error4;
@@ -883,7 +883,7 @@ static int r852_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
chip->legacy.write_buf = r852_write_buf;
/* init our device structure */
- dev = kzalloc(sizeof(struct r852_device), GFP_KERNEL);
+ dev = kzalloc_obj(struct r852_device, GFP_KERNEL);
if (!dev)
goto error5;
diff --git a/drivers/mtd/nand/raw/sharpsl.c b/drivers/mtd/nand/raw/sharpsl.c
index 142e93b200a3..d74097783036 100644
--- a/drivers/mtd/nand/raw/sharpsl.c
+++ b/drivers/mtd/nand/raw/sharpsl.c
@@ -132,7 +132,7 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
}
/* Allocate memory for MTD device structure and private data */
- sharpsl = kzalloc(sizeof(struct sharpsl_nand), GFP_KERNEL);
+ sharpsl = kzalloc_obj(struct sharpsl_nand, GFP_KERNEL);
if (!sharpsl)
return -ENOMEM;
diff --git a/drivers/mtd/nand/raw/txx9ndfmc.c b/drivers/mtd/nand/raw/txx9ndfmc.c
index 907fb5de4269..e49c38abef68 100644
--- a/drivers/mtd/nand/raw/txx9ndfmc.c
+++ b/drivers/mtd/nand/raw/txx9ndfmc.c
@@ -319,8 +319,7 @@ static int txx9ndfmc_probe(struct platform_device *dev)
if (!(plat->ch_mask & (1 << i)))
continue;
- txx9_priv = kzalloc(sizeof(struct txx9ndfmc_priv),
- GFP_KERNEL);
+ txx9_priv = kzalloc_obj(struct txx9ndfmc_priv, GFP_KERNEL);
if (!txx9_priv)
continue;
chip = &txx9_priv->chip;
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 29fb2ac19569..86dee7d13a38 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -350,7 +350,7 @@ static int spinand_ondie_ecc_init_ctx(struct nand_device *nand)
nand->ecc.ctx.conf.step_size = nand->ecc.requirements.step_size;
nand->ecc.ctx.conf.strength = nand->ecc.requirements.strength;
- engine_conf = kzalloc(sizeof(*engine_conf), GFP_KERNEL);
+ engine_conf = kzalloc_obj(*engine_conf, GFP_KERNEL);
if (!engine_conf)
return -ENOMEM;
diff --git a/drivers/mtd/nand/spi/gigadevice.c b/drivers/mtd/nand/spi/gigadevice.c
index e4380208edd0..137571093ec0 100644
--- a/drivers/mtd/nand/spi/gigadevice.c
+++ b/drivers/mtd/nand/spi/gigadevice.c
@@ -642,7 +642,7 @@ static int gd5fxgm9_spinand_init(struct spinand_device *spinand)
{
struct gigadevice_priv *priv;
- priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+ priv = kzalloc_obj(*priv, GFP_KERNEL);
if (!priv)
return -ENOMEM;
diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c
index 84be5e0402b5..2e6b9be9c58b 100644
--- a/drivers/mtd/nand/spi/macronix.c
+++ b/drivers/mtd/nand/spi/macronix.c
@@ -499,7 +499,7 @@ static int macronix_spinand_init(struct spinand_device *spinand)
{
struct macronix_priv *priv;
- priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+ priv = kzalloc_obj(*priv, GFP_KERNEL);
if (!priv)
return -ENOMEM;
diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
index 868aa3d35d09..9f3c193fb0c4 100644
--- a/drivers/mtd/nftlcore.c
+++ b/drivers/mtd/nftlcore.c
@@ -45,7 +45,7 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
pr_debug("NFTL: add_mtd for %s\n", mtd->name);
- nftl = kzalloc(sizeof(struct NFTLrecord), GFP_KERNEL);
+ nftl = kzalloc_obj(struct NFTLrecord, GFP_KERNEL);
if (!nftl)
return;
diff --git a/drivers/mtd/parsers/bcm47xxpart.c b/drivers/mtd/parsers/bcm47xxpart.c
index 49c8e7f27f21..b8ba7d2f22e1 100644
--- a/drivers/mtd/parsers/bcm47xxpart.c
+++ b/drivers/mtd/parsers/bcm47xxpart.c
@@ -106,8 +106,8 @@ static int bcm47xxpart_parse(struct mtd_info *master,
blocksize = 0x1000;
/* Alloc */
- parts = kcalloc(BCM47XXPART_MAX_PARTS, sizeof(struct mtd_partition),
- GFP_KERNEL);
+ parts = kzalloc_objs(struct mtd_partition, BCM47XXPART_MAX_PARTS,
+ GFP_KERNEL);
if (!parts)
return -ENOMEM;
diff --git a/drivers/mtd/parsers/brcm_u-boot.c b/drivers/mtd/parsers/brcm_u-boot.c
index 984f98923446..168cd629c277 100644
--- a/drivers/mtd/parsers/brcm_u-boot.c
+++ b/drivers/mtd/parsers/brcm_u-boot.c
@@ -37,7 +37,7 @@ static int brcm_u_boot_parse(struct mtd_info *mtd,
int err;
int i = 0;
- parts = kcalloc(BRCM_U_BOOT_MAX_PARTS, sizeof(*parts), GFP_KERNEL);
+ parts = kzalloc_objs(*parts, BRCM_U_BOOT_MAX_PARTS, GFP_KERNEL);
if (!parts)
return -ENOMEM;
diff --git a/drivers/mtd/parsers/ofpart_core.c b/drivers/mtd/parsers/ofpart_core.c
index 599adb69eba6..02cf6a539e3f 100644
--- a/drivers/mtd/parsers/ofpart_core.c
+++ b/drivers/mtd/parsers/ofpart_core.c
@@ -102,7 +102,7 @@ static int parse_fixed_partitions(struct mtd_info *master,
return 0;
}
- parts = kcalloc(nr_parts, sizeof(*parts), GFP_KERNEL);
+ parts = kzalloc_objs(*parts, nr_parts, GFP_KERNEL);
if (!parts) {
if (dedicated)
of_node_put(ofpart_node);
@@ -249,7 +249,7 @@ static int parse_ofoldpart_partitions(struct mtd_info *master,
nr_parts = plen / sizeof(part[0]);
- parts = kcalloc(nr_parts, sizeof(*parts), GFP_KERNEL);
+ parts = kzalloc_objs(*parts, nr_parts, GFP_KERNEL);
if (!parts)
return -ENOMEM;
diff --git a/drivers/mtd/parsers/parser_trx.c b/drivers/mtd/parsers/parser_trx.c
index 4814cf218e17..cfd9ab8caff5 100644
--- a/drivers/mtd/parsers/parser_trx.c
+++ b/drivers/mtd/parsers/parser_trx.c
@@ -65,8 +65,8 @@ static int parser_trx_parse(struct mtd_info *mtd,
if (err != 0 && err != -EINVAL)
pr_err("failed to parse \"brcm,trx-magic\" DT attribute, using default: %d\n", err);
- parts = kcalloc(TRX_PARSER_MAX_PARTS, sizeof(struct mtd_partition),
- GFP_KERNEL);
+ parts = kzalloc_objs(struct mtd_partition, TRX_PARSER_MAX_PARTS,
+ GFP_KERNEL);
if (!parts)
return -ENOMEM;
diff --git a/drivers/mtd/parsers/qcomsmempart.c b/drivers/mtd/parsers/qcomsmempart.c
index 4311b89d8df0..dd595387946b 100644
--- a/drivers/mtd/parsers/qcomsmempart.c
+++ b/drivers/mtd/parsers/qcomsmempart.c
@@ -123,7 +123,7 @@ static int parse_qcomsmem_part(struct mtd_info *mtd,
numparts++;
}
- parts = kcalloc(numparts, sizeof(*parts), GFP_KERNEL);
+ parts = kzalloc_objs(*parts, numparts, GFP_KERNEL);
if (!parts)
return -ENOMEM;
diff --git a/drivers/mtd/parsers/redboot.c b/drivers/mtd/parsers/redboot.c
index 3b55b676ca6b..4f3f5145ea83 100644
--- a/drivers/mtd/parsers/redboot.c
+++ b/drivers/mtd/parsers/redboot.c
@@ -203,7 +203,7 @@ nogood:
if (!redboot_checksum(&buf[i]))
break;
- new_fl = kmalloc(sizeof(struct fis_list), GFP_KERNEL);
+ new_fl = kmalloc_obj(struct fis_list, GFP_KERNEL);
namelen += strlen(buf[i].name) + 1;
if (!new_fl) {
ret = -ENOMEM;
diff --git a/drivers/mtd/parsers/scpart.c b/drivers/mtd/parsers/scpart.c
index 6e5e11c37078..84b89499b200 100644
--- a/drivers/mtd/parsers/scpart.c
+++ b/drivers/mtd/parsers/scpart.c
@@ -80,7 +80,7 @@ static int scpart_scan_partmap(struct mtd_info *master, loff_t partmap_offs,
if (cnt > 0) {
int bytes = cnt * sizeof(*pdesc);
- pdesc = kcalloc(cnt, sizeof(*pdesc), GFP_KERNEL);
+ pdesc = kzalloc_objs(*pdesc, cnt, GFP_KERNEL);
if (!pdesc) {
res = -ENOMEM;
goto free;
@@ -171,8 +171,8 @@ static int scpart_parse(struct mtd_info *master,
goto free;
}
- parts = kcalloc(of_get_child_count(ofpart_node), sizeof(*parts),
- GFP_KERNEL);
+ parts = kzalloc_objs(*parts, of_get_child_count(ofpart_node),
+ GFP_KERNEL);
if (!parts) {
res = -ENOMEM;
goto free;
diff --git a/drivers/mtd/parsers/sharpslpart.c b/drivers/mtd/parsers/sharpslpart.c
index 671a61845bd5..ce1e255b707d 100644
--- a/drivers/mtd/parsers/sharpslpart.c
+++ b/drivers/mtd/parsers/sharpslpart.c
@@ -362,9 +362,8 @@ static int sharpsl_parse_mtd_partitions(struct mtd_info *master,
return err;
}
- sharpsl_nand_parts = kcalloc(SHARPSL_NAND_PARTS,
- sizeof(*sharpsl_nand_parts),
- GFP_KERNEL);
+ sharpsl_nand_parts = kzalloc_objs(*sharpsl_nand_parts,
+ SHARPSL_NAND_PARTS, GFP_KERNEL);
if (!sharpsl_nand_parts)
return -ENOMEM;
diff --git a/drivers/mtd/parsers/tplink_safeloader.c b/drivers/mtd/parsers/tplink_safeloader.c
index 4fcaf92d22e4..3a4e9b84277f 100644
--- a/drivers/mtd/parsers/tplink_safeloader.c
+++ b/drivers/mtd/parsers/tplink_safeloader.c
@@ -82,7 +82,7 @@ static int mtd_parser_tplink_safeloader_parse(struct mtd_info *mtd,
int idx;
int err;
- parts = kcalloc(TPLINK_SAFELOADER_MAX_PARTS, sizeof(*parts), GFP_KERNEL);
+ parts = kzalloc_objs(*parts, TPLINK_SAFELOADER_MAX_PARTS, GFP_KERNEL);
if (!parts) {
err = -ENOMEM;
goto err_out;
diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index be26cc67a1c4..f7d5591e8858 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -185,8 +185,8 @@ static int scan_header(struct partition *part)
if (!part->header_cache)
goto err;
- part->blocks = kcalloc(part->total_blocks, sizeof(struct block),
- GFP_KERNEL);
+ part->blocks = kzalloc_objs(struct block, part->total_blocks,
+ GFP_KERNEL);
if (!part->blocks)
goto err;
@@ -270,7 +270,7 @@ static int erase_block(struct partition *part, int block)
struct erase_info *erase;
int rc;
- erase = kmalloc(sizeof(struct erase_info), GFP_KERNEL);
+ erase = kmalloc_obj(struct erase_info, GFP_KERNEL);
if (!erase)
return -ENOMEM;
@@ -752,7 +752,7 @@ static void rfd_ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
mtd->size > UINT_MAX)
return;
- part = kzalloc(sizeof(struct partition), GFP_KERNEL);
+ part = kzalloc_obj(struct partition, GFP_KERNEL);
if (!part)
return;
diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
index 5988cba30eb3..5da82a4612b6 100644
--- a/drivers/mtd/sm_ftl.c
+++ b/drivers/mtd/sm_ftl.c
@@ -64,7 +64,7 @@ static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
/* Initialize sysfs attributes */
vendor_attribute =
- kzalloc(sizeof(struct sm_sysfs_attribute), GFP_KERNEL);
+ kzalloc_obj(struct sm_sysfs_attribute, GFP_KERNEL);
if (!vendor_attribute)
goto error2;
@@ -78,14 +78,14 @@ static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
/* Create array of pointers to the attributes */
- attributes = kcalloc(NUM_ATTRIBUTES + 1, sizeof(struct attribute *),
- GFP_KERNEL);
+ attributes = kzalloc_objs(struct attribute *, NUM_ATTRIBUTES + 1,
+ GFP_KERNEL);
if (!attributes)
goto error3;
attributes[0] = &vendor_attribute->dev_attr.attr;
/* Finally create the attribute group */
- attr_group = kzalloc(sizeof(struct attribute_group), GFP_KERNEL);
+ attr_group = kzalloc_obj(struct attribute_group, GFP_KERNEL);
if (!attr_group)
goto error4;
attr_group->attrs = attributes;
@@ -1134,7 +1134,7 @@ static void sm_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
struct sm_ftl *ftl;
/* Allocate & initialize our private structure */
- ftl = kzalloc(sizeof(struct sm_ftl), GFP_KERNEL);
+ ftl = kzalloc_obj(struct sm_ftl, GFP_KERNEL);
if (!ftl)
goto error1;
@@ -1156,8 +1156,7 @@ static void sm_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
goto error2;
/* Allocate zone array, it will be initialized on demand */
- ftl->zones = kcalloc(ftl->zone_count, sizeof(struct ftl_zone),
- GFP_KERNEL);
+ ftl->zones = kzalloc_objs(struct ftl_zone, ftl->zone_count, GFP_KERNEL);
if (!ftl->zones)
goto error3;
@@ -1171,7 +1170,7 @@ static void sm_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
/* Allocate upper layer structure and initialize it */
- trans = kzalloc(sizeof(struct mtd_blktrans_dev), GFP_KERNEL);
+ trans = kzalloc_obj(struct mtd_blktrans_dev, GFP_KERNEL);
if (!trans)
goto error5;
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index d3f8a78efd3b..d48170eceec6 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1553,7 +1553,7 @@ spi_nor_init_erase_cmd(const struct spi_nor_erase_region *region,
{
struct spi_nor_erase_command *cmd;
- cmd = kmalloc(sizeof(*cmd), GFP_KERNEL);
+ cmd = kmalloc_obj(*cmd, GFP_KERNEL);
if (!cmd)
return ERR_PTR(-ENOMEM);
diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c
index a8324c2da0ac..1514f21c8557 100644
--- a/drivers/mtd/spi-nor/sfdp.c
+++ b/drivers/mtd/spi-nor/sfdp.c
@@ -760,7 +760,7 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt,
u8 read_data_mask, map_id;
/* Use a kmalloc'ed bounce buffer to guarantee it is DMA-able. */
- buf = kmalloc(sizeof(*buf), GFP_KERNEL);
+ buf = kmalloc_obj(*buf, GFP_KERNEL);
if (!buf)
return ERR_PTR(-ENOMEM);
diff --git a/drivers/mtd/ssfdc.c b/drivers/mtd/ssfdc.c
index 46c01fa2ec46..b4e9a1c11c54 100644
--- a/drivers/mtd/ssfdc.c
+++ b/drivers/mtd/ssfdc.c
@@ -295,7 +295,7 @@ static void ssfdcr_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
if (cis_sector == -1)
return;
- ssfdc = kzalloc(sizeof(*ssfdc), GFP_KERNEL);
+ ssfdc = kzalloc_obj(*ssfdc, GFP_KERNEL);
if (!ssfdc)
return;
diff --git a/drivers/mtd/tests/stresstest.c b/drivers/mtd/tests/stresstest.c
index 8062098930d6..ec5d7bd93b77 100644
--- a/drivers/mtd/tests/stresstest.c
+++ b/drivers/mtd/tests/stresstest.c
@@ -178,7 +178,7 @@ static int __init mtd_stresstest_init(void)
err = -ENOMEM;
readbuf = vmalloc(bufsize);
writebuf = vmalloc(bufsize);
- offsets = kmalloc_array(ebcnt, sizeof(int), GFP_KERNEL);
+ offsets = kmalloc_objs(int, ebcnt, GFP_KERNEL);
if (!readbuf || !writebuf || !offsets)
goto out;
for (i = 0; i < ebcnt; i++)
diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index 884171871d0e..9823e0bd7a51 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -131,7 +131,7 @@ static struct ubi_ainf_volume *find_or_add_av(struct ubi_attach_info *ai,
return NULL;
/* The volume is absent - add it */
- av = kzalloc(sizeof(*av), GFP_KERNEL);
+ av = kzalloc_obj(*av, GFP_KERNEL);
if (!av)
return ERR_PTR(-ENOMEM);
@@ -1451,7 +1451,7 @@ static struct ubi_attach_info *alloc_ai(const char *slab_name)
{
struct ubi_attach_info *ai;
- ai = kzalloc(sizeof(struct ubi_attach_info), GFP_KERNEL);
+ ai = kzalloc_obj(struct ubi_attach_info, GFP_KERNEL);
if (!ai)
return ai;
diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
index b53fd147fa65..4428486fb287 100644
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
@@ -368,7 +368,7 @@ int ubiblock_create(struct ubi_volume_info *vi)
goto out_unlock;
}
- dev = kzalloc(sizeof(struct ubiblock), GFP_KERNEL);
+ dev = kzalloc_obj(struct ubiblock, GFP_KERNEL);
if (!dev) {
ret = -ENOMEM;
goto out_unlock;
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index ef6a22f372f9..d7493b61bee4 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -930,7 +930,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
}
}
- ubi = kzalloc(sizeof(struct ubi_device), GFP_KERNEL);
+ ubi = kzalloc_obj(struct ubi_device, GFP_KERNEL);
if (!ubi)
return -ENOMEM;
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index b700a0efaa93..0b233b6a2d9c 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -727,7 +727,7 @@ static int rename_volumes(struct ubi_device *ubi,
int name_len = req->ents[i].name_len;
const char *name = req->ents[i].name;
- re = kzalloc(sizeof(struct ubi_rename_entry), GFP_KERNEL);
+ re = kzalloc_obj(struct ubi_rename_entry, GFP_KERNEL);
if (!re) {
err = -ENOMEM;
goto out_free;
@@ -801,7 +801,7 @@ static int rename_volumes(struct ubi_device *ubi,
goto out_free;
}
- re1 = kzalloc(sizeof(struct ubi_rename_entry), GFP_KERNEL);
+ re1 = kzalloc_obj(struct ubi_rename_entry, GFP_KERNEL);
if (!re1) {
err = -ENOMEM;
ubi_close_volume(desc);
@@ -1007,7 +1007,7 @@ static long ubi_cdev_ioctl(struct file *file, unsigned int cmd,
struct ubi_rnvol_req *req;
dbg_gen("re-name volumes");
- req = kmalloc(sizeof(struct ubi_rnvol_req), GFP_KERNEL);
+ req = kmalloc_obj(struct ubi_rnvol_req, GFP_KERNEL);
if (!req) {
err = -ENOMEM;
break;
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index c7ba7a15c9f7..dbc448e2b7a6 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -124,12 +124,11 @@ struct ubi_eba_table *ubi_eba_create_table(struct ubi_volume *vol,
int err = -ENOMEM;
int i;
- tbl = kzalloc(sizeof(*tbl), GFP_KERNEL);
+ tbl = kzalloc_obj(*tbl, GFP_KERNEL);
if (!tbl)
return ERR_PTR(-ENOMEM);
- tbl->entries = kmalloc_array(nentries, sizeof(*tbl->entries),
- GFP_KERNEL);
+ tbl->entries = kmalloc_objs(*tbl->entries, nentries, GFP_KERNEL);
if (!tbl->entries)
goto err;
@@ -248,7 +247,7 @@ static struct ubi_ltree_entry *ltree_add_entry(struct ubi_device *ubi,
{
struct ubi_ltree_entry *le, *le1, *le_free;
- le = kmalloc(sizeof(struct ubi_ltree_entry), GFP_NOFS);
+ le = kmalloc_obj(struct ubi_ltree_entry, GFP_NOFS);
if (!le)
return ERR_PTR(-ENOMEM);
@@ -1536,11 +1535,11 @@ int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
num_volumes = ubi->vtbl_slots + UBI_INT_VOL_COUNT;
- scan_eba = kmalloc_array(num_volumes, sizeof(*scan_eba), GFP_KERNEL);
+ scan_eba = kmalloc_objs(*scan_eba, num_volumes, GFP_KERNEL);
if (!scan_eba)
return -ENOMEM;
- fm_eba = kmalloc_array(num_volumes, sizeof(*fm_eba), GFP_KERNEL);
+ fm_eba = kmalloc_objs(*fm_eba, num_volumes, GFP_KERNEL);
if (!fm_eba) {
kfree(scan_eba);
return -ENOMEM;
@@ -1551,17 +1550,15 @@ int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
if (!vol)
continue;
- scan_eba[i] = kmalloc_array(vol->reserved_pebs,
- sizeof(**scan_eba),
- GFP_KERNEL);
+ scan_eba[i] = kmalloc_objs(**scan_eba, vol->reserved_pebs,
+ GFP_KERNEL);
if (!scan_eba[i]) {
ret = -ENOMEM;
goto out_free;
}
- fm_eba[i] = kmalloc_array(vol->reserved_pebs,
- sizeof(**fm_eba),
- GFP_KERNEL);
+ fm_eba[i] = kmalloc_objs(**fm_eba, vol->reserved_pebs,
+ GFP_KERNEL);
if (!fm_eba[i]) {
ret = -ENOMEM;
kfree(scan_eba[i]);
diff --git a/drivers/mtd/ubi/fastmap-wl.c b/drivers/mtd/ubi/fastmap-wl.c
index e2bc1122bfd3..a0f750411f9d 100644
--- a/drivers/mtd/ubi/fastmap-wl.c
+++ b/drivers/mtd/ubi/fastmap-wl.c
@@ -466,7 +466,7 @@ int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
ubi->wl_scheduled = 1;
spin_unlock(&ubi->wl_lock);
- wrk = kmalloc(sizeof(struct ubi_work), GFP_NOFS);
+ wrk = kmalloc_obj(struct ubi_work, GFP_NOFS);
if (!wrk) {
spin_lock(&ubi->wl_lock);
ubi->wl_scheduled = 0;
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 9a4940874be5..30953ff2ff52 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -889,13 +889,13 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
down_write(&ubi->fm_protect);
memset(ubi->fm_buf, 0, ubi->fm_size);
- fmsb = kmalloc(sizeof(*fmsb), GFP_KERNEL);
+ fmsb = kmalloc_obj(*fmsb, GFP_KERNEL);
if (!fmsb) {
ret = -ENOMEM;
goto out;
}
- fm = kzalloc(sizeof(*fm), GFP_KERNEL);
+ fm = kzalloc_obj(*fm, GFP_KERNEL);
if (!fm) {
ret = -ENOMEM;
kfree(fmsb);
@@ -1416,7 +1416,7 @@ static int invalidate_fastmap(struct ubi_device *ubi)
ubi->fm = NULL;
ret = -ENOMEM;
- fm = kzalloc(sizeof(*fm), GFP_NOFS);
+ fm = kzalloc_obj(*fm, GFP_NOFS);
if (!fm)
goto out;
@@ -1501,7 +1501,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
return 0;
}
- new_fm = kzalloc(sizeof(*new_fm), GFP_NOFS);
+ new_fm = kzalloc_obj(*new_fm, GFP_NOFS);
if (!new_fm) {
up_write(&ubi->fm_eba_sem);
up_write(&ubi->work_sem);
diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c
index 1b980d15d9fb..e56b4172264c 100644
--- a/drivers/mtd/ubi/gluebi.c
+++ b/drivers/mtd/ubi/gluebi.c
@@ -281,7 +281,7 @@ static int gluebi_create(struct ubi_device_info *di,
struct gluebi_device *gluebi, *g;
struct mtd_info *mtd;
- gluebi = kzalloc(sizeof(struct gluebi_device), GFP_KERNEL);
+ gluebi = kzalloc_obj(struct gluebi_device, GFP_KERNEL);
if (!gluebi)
return -ENOMEM;
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index df0a5a57b072..7cc239245e42 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -140,7 +140,7 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)
goto out_put_ubi;
}
- desc = kmalloc(sizeof(struct ubi_volume_desc), GFP_KERNEL);
+ desc = kmalloc_obj(struct ubi_volume_desc, GFP_KERNEL);
if (!desc) {
err = -ENOMEM;
goto out_put_ubi;
diff --git a/drivers/mtd/ubi/nvmem.c b/drivers/mtd/ubi/nvmem.c
index 34f8c1d3cdee..bc2cfb355d5c 100644
--- a/drivers/mtd/ubi/nvmem.c
+++ b/drivers/mtd/ubi/nvmem.c
@@ -75,7 +75,7 @@ static int ubi_nvmem_add(struct ubi_volume_info *vi)
WARN_ON_ONCE(vi->size <= 0))
return -EINVAL;
- unv = kzalloc(sizeof(struct ubi_nvmem), GFP_KERNEL);
+ unv = kzalloc_obj(struct ubi_nvmem, GFP_KERNEL);
if (!unv)
return -ENOMEM;
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 44803d3329f4..af466cd83ae0 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -1100,7 +1100,7 @@ ubi_alloc_vid_buf(const struct ubi_device *ubi, gfp_t gfp_flags)
struct ubi_vid_io_buf *vidb;
void *buf;
- vidb = kzalloc(sizeof(*vidb), gfp_flags);
+ vidb = kzalloc_obj(*vidb, gfp_flags);
if (!vidb)
return NULL;
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index e5cf3bdca3b0..ffec2c649698 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -172,7 +172,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
if (ubi->ro_mode)
return -EROFS;
- vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL);
+ vol = kzalloc_obj(struct ubi_volume, GFP_KERNEL);
if (!vol)
return -ENOMEM;
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 6e5489e233dd..74427a03e896 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -531,7 +531,7 @@ static int init_volumes(struct ubi_device *ubi,
if (be32_to_cpu(vtbl[i].reserved_pebs) == 0)
continue; /* Empty record */
- vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL);
+ vol = kzalloc_obj(struct ubi_volume, GFP_KERNEL);
if (!vol)
return -ENOMEM;
@@ -623,7 +623,7 @@ static int init_volumes(struct ubi_device *ubi,
}
/* And add the layout volume */
- vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL);
+ vol = kzalloc_obj(struct ubi_volume, GFP_KERNEL);
if (!vol)
return -ENOMEM;
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index fbd399cf6503..e3705db8e570 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -602,7 +602,7 @@ static int schedule_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,
dbg_wl("schedule erasure of PEB %d, EC %d, torture %d",
e->pnum, e->ec, torture);
- wl_wrk = kmalloc(sizeof(struct ubi_work), GFP_NOFS);
+ wl_wrk = kmalloc_obj(struct ubi_work, GFP_NOFS);
if (!wl_wrk)
return -ENOMEM;
@@ -1071,7 +1071,7 @@ static int ensure_wear_leveling(struct ubi_device *ubi, int nested)
ubi->wl_scheduled = 1;
spin_unlock(&ubi->wl_lock);
- wrk = kmalloc(sizeof(struct ubi_work), GFP_NOFS);
+ wrk = kmalloc_obj(struct ubi_work, GFP_NOFS);
if (!wrk) {
err = -ENOMEM;
goto out_cancel;