Commit 95b93a0c authored by Burman Yan's avatar Burman Yan Committed by David Woodhouse

[MTD] replace kmalloc+memset with kzalloc

Signed-off-by: default avatarYan Burman <yan_952@hotmail.com>
Signed-off-by: default avatarDavid Woodhouse <dwmw2@infradead.org>
parent 998a43e7
...@@ -358,13 +358,12 @@ ev64360_setup_mtd(void) ...@@ -358,13 +358,12 @@ ev64360_setup_mtd(void)
ptbl_entries = 3; ptbl_entries = 3;
if ((ptbl = kmalloc(ptbl_entries * sizeof(struct mtd_partition), if ((ptbl = kzalloc(ptbl_entries * sizeof(struct mtd_partition),
GFP_KERNEL)) == NULL) { GFP_KERNEL)) == NULL) {
printk(KERN_WARNING "Can't alloc MTD partition table\n"); printk(KERN_WARNING "Can't alloc MTD partition table\n");
return -ENOMEM; return -ENOMEM;
} }
memset(ptbl, 0, ptbl_entries * sizeof(struct mtd_partition));
ptbl[0].name = "reserved"; ptbl[0].name = "reserved";
ptbl[0].offset = 0; ptbl[0].offset = 0;
......
...@@ -207,11 +207,10 @@ static int parse_afs_partitions(struct mtd_info *mtd, ...@@ -207,11 +207,10 @@ static int parse_afs_partitions(struct mtd_info *mtd,
if (!sz) if (!sz)
return ret; return ret;
parts = kmalloc(sz, GFP_KERNEL); parts = kzalloc(sz, GFP_KERNEL);
if (!parts) if (!parts)
return -ENOMEM; return -ENOMEM;
memset(parts, 0, sz);
str = (char *)(parts + idx); str = (char *)(parts + idx);
/* /*
......
...@@ -643,13 +643,12 @@ static struct mtd_info *amd_flash_probe(struct map_info *map) ...@@ -643,13 +643,12 @@ static struct mtd_info *amd_flash_probe(struct map_info *map)
int reg_idx; int reg_idx;
int offset; int offset;
mtd = (struct mtd_info*)kmalloc(sizeof(*mtd), GFP_KERNEL); mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
if (!mtd) { if (!mtd) {
printk(KERN_WARNING printk(KERN_WARNING
"%s: kmalloc failed for info structure\n", map->name); "%s: kmalloc failed for info structure\n", map->name);
return NULL; return NULL;
} }
memset(mtd, 0, sizeof(*mtd));
mtd->priv = map; mtd->priv = map;
memset(&temp, 0, sizeof(temp)); memset(&temp, 0, sizeof(temp));
......
...@@ -337,12 +337,11 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary) ...@@ -337,12 +337,11 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
struct mtd_info *mtd; struct mtd_info *mtd;
int i; int i;
mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
if (!mtd) { if (!mtd) {
printk(KERN_ERR "Failed to allocate memory for MTD device\n"); printk(KERN_ERR "Failed to allocate memory for MTD device\n");
return NULL; return NULL;
} }
memset(mtd, 0, sizeof(*mtd));
mtd->priv = map; mtd->priv = map;
mtd->type = MTD_NORFLASH; mtd->type = MTD_NORFLASH;
......
...@@ -257,12 +257,11 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary) ...@@ -257,12 +257,11 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
struct mtd_info *mtd; struct mtd_info *mtd;
int i; int i;
mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
if (!mtd) { if (!mtd) {
printk(KERN_WARNING "Failed to allocate memory for MTD device\n"); printk(KERN_WARNING "Failed to allocate memory for MTD device\n");
return NULL; return NULL;
} }
memset(mtd, 0, sizeof(*mtd));
mtd->priv = map; mtd->priv = map;
mtd->type = MTD_NORFLASH; mtd->type = MTD_NORFLASH;
......
...@@ -172,7 +172,7 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map) ...@@ -172,7 +172,7 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
int i,j; int i,j;
unsigned long devsize = (1<<cfi->cfiq->DevSize) * cfi->interleave; unsigned long devsize = (1<<cfi->cfiq->DevSize) * cfi->interleave;
mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
//printk(KERN_DEBUG "number of CFI chips: %d\n", cfi->numchips); //printk(KERN_DEBUG "number of CFI chips: %d\n", cfi->numchips);
if (!mtd) { if (!mtd) {
...@@ -181,7 +181,6 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map) ...@@ -181,7 +181,6 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
return NULL; return NULL;
} }
memset(mtd, 0, sizeof(*mtd));
mtd->priv = map; mtd->priv = map;
mtd->type = MTD_NORFLASH; mtd->type = MTD_NORFLASH;
mtd->size = devsize * cfi->numchips; mtd->size = devsize * cfi->numchips;
......
...@@ -113,13 +113,12 @@ static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chi ...@@ -113,13 +113,12 @@ static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chi
} }
mapsize = (max_chips + BITS_PER_LONG-1) / BITS_PER_LONG; mapsize = (max_chips + BITS_PER_LONG-1) / BITS_PER_LONG;
chip_map = kmalloc(mapsize, GFP_KERNEL); chip_map = kzalloc(mapsize, GFP_KERNEL);
if (!chip_map) { if (!chip_map) {
printk(KERN_WARNING "%s: kmalloc failed for CFI chip map\n", map->name); printk(KERN_WARNING "%s: kmalloc failed for CFI chip map\n", map->name);
kfree(cfi.cfiq); kfree(cfi.cfiq);
return NULL; return NULL;
} }
memset (chip_map, 0, mapsize);
set_bit(0, chip_map); /* Mark first chip valid */ set_bit(0, chip_map); /* Mark first chip valid */
......
...@@ -116,11 +116,10 @@ static struct mtd_info *jedec_probe(struct map_info *map) ...@@ -116,11 +116,10 @@ static struct mtd_info *jedec_probe(struct map_info *map)
char Part[200]; char Part[200];
memset(&priv,0,sizeof(priv)); memset(&priv,0,sizeof(priv));
MTD = kmalloc(sizeof(struct mtd_info) + sizeof(struct jedec_private), GFP_KERNEL); MTD = kzalloc(sizeof(struct mtd_info) + sizeof(struct jedec_private), GFP_KERNEL);
if (!MTD) if (!MTD)
return NULL; return NULL;
memset(MTD, 0, sizeof(struct mtd_info) + sizeof(struct jedec_private));
priv = (struct jedec_private *)&MTD[1]; priv = (struct jedec_private *)&MTD[1];
my_bank_size = map->size; my_bank_size = map->size;
......
...@@ -47,13 +47,11 @@ static struct mtd_info *map_absent_probe(struct map_info *map) ...@@ -47,13 +47,11 @@ static struct mtd_info *map_absent_probe(struct map_info *map)
{ {
struct mtd_info *mtd; struct mtd_info *mtd;
mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
if (!mtd) { if (!mtd) {
return NULL; return NULL;
} }
memset(mtd, 0, sizeof(*mtd));
map->fldrv = &map_absent_chipdrv; map->fldrv = &map_absent_chipdrv;
mtd->priv = map; mtd->priv = map;
mtd->name = map->name; mtd->name = map->name;
......
...@@ -55,12 +55,10 @@ static struct mtd_info *map_ram_probe(struct map_info *map) ...@@ -55,12 +55,10 @@ static struct mtd_info *map_ram_probe(struct map_info *map)
#endif #endif
/* OK. It seems to be RAM. */ /* OK. It seems to be RAM. */
mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
if (!mtd) if (!mtd)
return NULL; return NULL;
memset(mtd, 0, sizeof(*mtd));
map->fldrv = &mapram_chipdrv; map->fldrv = &mapram_chipdrv;
mtd->priv = map; mtd->priv = map;
mtd->name = map->name; mtd->name = map->name;
......
...@@ -31,12 +31,10 @@ static struct mtd_info *map_rom_probe(struct map_info *map) ...@@ -31,12 +31,10 @@ static struct mtd_info *map_rom_probe(struct map_info *map)
{ {
struct mtd_info *mtd; struct mtd_info *mtd;
mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
if (!mtd) if (!mtd)
return NULL; return NULL;
memset(mtd, 0, sizeof(*mtd));
map->fldrv = &maprom_chipdrv; map->fldrv = &maprom_chipdrv;
mtd->priv = map; mtd->priv = map;
mtd->name = map->name; mtd->name = map->name;
......
...@@ -112,18 +112,16 @@ static struct mtd_info *sharp_probe(struct map_info *map) ...@@ -112,18 +112,16 @@ static struct mtd_info *sharp_probe(struct map_info *map)
struct sharp_info *sharp = NULL; struct sharp_info *sharp = NULL;
int width; int width;
mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
if(!mtd) if(!mtd)
return NULL; return NULL;
sharp = kmalloc(sizeof(*sharp), GFP_KERNEL); sharp = kzalloc(sizeof(*sharp), GFP_KERNEL);
if(!sharp) { if(!sharp) {
kfree(mtd); kfree(mtd);
return NULL; return NULL;
} }
memset(mtd, 0, sizeof(*mtd));
width = sharp_probe_map(map,mtd); width = sharp_probe_map(map,mtd);
if(!width){ if(!width){
kfree(mtd); kfree(mtd);
...@@ -143,7 +141,6 @@ static struct mtd_info *sharp_probe(struct map_info *map) ...@@ -143,7 +141,6 @@ static struct mtd_info *sharp_probe(struct map_info *map)
mtd->writesize = 1; mtd->writesize = 1;
mtd->name = map->name; mtd->name = map->name;
memset(sharp, 0, sizeof(*sharp));
sharp->chipshift = 23; sharp->chipshift = 23;
sharp->numchips = 1; sharp->numchips = 1;
sharp->chips[0].start = 0; sharp->chips[0].start = 0;
......
...@@ -163,13 +163,12 @@ static struct mtd_partition * newpart(char *s, ...@@ -163,13 +163,12 @@ static struct mtd_partition * newpart(char *s,
*num_parts = this_part + 1; *num_parts = this_part + 1;
alloc_size = *num_parts * sizeof(struct mtd_partition) + alloc_size = *num_parts * sizeof(struct mtd_partition) +
extra_mem_size; extra_mem_size;
parts = kmalloc(alloc_size, GFP_KERNEL); parts = kzalloc(alloc_size, GFP_KERNEL);
if (!parts) if (!parts)
{ {
printk(KERN_ERR ERRP "out of memory\n"); printk(KERN_ERR ERRP "out of memory\n");
return NULL; return NULL;
} }
memset(parts, 0, alloc_size);
extra_mem = (unsigned char *)(parts + *num_parts); extra_mem = (unsigned char *)(parts + *num_parts);
} }
/* enter this partition (offset will be calculated later if it is zero at this point) */ /* enter this partition (offset will be calculated later if it is zero at this point) */
......
...@@ -295,10 +295,9 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size) ...@@ -295,10 +295,9 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
if (!devname) if (!devname)
return NULL; return NULL;
dev = kmalloc(sizeof(struct block2mtd_dev), GFP_KERNEL); dev = kzalloc(sizeof(struct block2mtd_dev), GFP_KERNEL);
if (!dev) if (!dev)
return NULL; return NULL;
memset(dev, 0, sizeof(*dev));
/* Get a handle on the device */ /* Get a handle on the device */
bdev = open_bdev_excl(devname, O_RDWR, NULL); bdev = open_bdev_excl(devname, O_RDWR, NULL);
......
...@@ -131,11 +131,10 @@ static int __init ms02nv_init_one(ulong addr) ...@@ -131,11 +131,10 @@ static int __init ms02nv_init_one(ulong addr)
int ret = -ENODEV; int ret = -ENODEV;
/* The module decodes 8MiB of address space. */ /* The module decodes 8MiB of address space. */
mod_res = kmalloc(sizeof(*mod_res), GFP_KERNEL); mod_res = kzalloc(sizeof(*mod_res), GFP_KERNEL);
if (!mod_res) if (!mod_res)
return -ENOMEM; return -ENOMEM;
memset(mod_res, 0, sizeof(*mod_res));
mod_res->name = ms02nv_name; mod_res->name = ms02nv_name;
mod_res->start = addr; mod_res->start = addr;
mod_res->end = addr + MS02NV_SLOT_SIZE - 1; mod_res->end = addr + MS02NV_SLOT_SIZE - 1;
...@@ -153,24 +152,21 @@ static int __init ms02nv_init_one(ulong addr) ...@@ -153,24 +152,21 @@ static int __init ms02nv_init_one(ulong addr)
} }
ret = -ENOMEM; ret = -ENOMEM;
mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
if (!mtd) if (!mtd)
goto err_out_mod_res_rel; goto err_out_mod_res_rel;
memset(mtd, 0, sizeof(*mtd)); mp = kzalloc(sizeof(*mp), GFP_KERNEL);
mp = kmalloc(sizeof(*mp), GFP_KERNEL);
if (!mp) if (!mp)
goto err_out_mtd; goto err_out_mtd;
memset(mp, 0, sizeof(*mp));
mtd->priv = mp; mtd->priv = mp;
mp->resource.module = mod_res; mp->resource.module = mod_res;
/* Firmware's diagnostic NVRAM area. */ /* Firmware's diagnostic NVRAM area. */
diag_res = kmalloc(sizeof(*diag_res), GFP_KERNEL); diag_res = kzalloc(sizeof(*diag_res), GFP_KERNEL);
if (!diag_res) if (!diag_res)
goto err_out_mp; goto err_out_mp;
memset(diag_res, 0, sizeof(*diag_res));
diag_res->name = ms02nv_res_diag_ram; diag_res->name = ms02nv_res_diag_ram;
diag_res->start = addr; diag_res->start = addr;
diag_res->end = addr + MS02NV_RAM - 1; diag_res->end = addr + MS02NV_RAM - 1;
...@@ -180,11 +176,10 @@ static int __init ms02nv_init_one(ulong addr) ...@@ -180,11 +176,10 @@ static int __init ms02nv_init_one(ulong addr)
mp->resource.diag_ram = diag_res; mp->resource.diag_ram = diag_res;
/* User-available general-purpose NVRAM area. */ /* User-available general-purpose NVRAM area. */
user_res = kmalloc(sizeof(*user_res), GFP_KERNEL); user_res = kzalloc(sizeof(*user_res), GFP_KERNEL);
if (!user_res) if (!user_res)
goto err_out_diag_res; goto err_out_diag_res;
memset(user_res, 0, sizeof(*user_res));
user_res->name = ms02nv_res_user_ram; user_res->name = ms02nv_res_user_ram;
user_res->start = addr + MS02NV_RAM; user_res->start = addr + MS02NV_RAM;
user_res->end = addr + size - 1; user_res->end = addr + size - 1;
...@@ -194,11 +189,10 @@ static int __init ms02nv_init_one(ulong addr) ...@@ -194,11 +189,10 @@ static int __init ms02nv_init_one(ulong addr)
mp->resource.user_ram = user_res; mp->resource.user_ram = user_res;
/* Control and status register. */ /* Control and status register. */
csr_res = kmalloc(sizeof(*csr_res), GFP_KERNEL); csr_res = kzalloc(sizeof(*csr_res), GFP_KERNEL);
if (!csr_res) if (!csr_res)
goto err_out_user_res; goto err_out_user_res;
memset(csr_res, 0, sizeof(*csr_res));
csr_res->name = ms02nv_res_csr; csr_res->name = ms02nv_res_csr;
csr_res->start = addr + MS02NV_CSR; csr_res->start = addr + MS02NV_CSR;
csr_res->end = addr + MS02NV_CSR + 3; csr_res->end = addr + MS02NV_CSR + 3;
......
...@@ -126,12 +126,10 @@ static int register_device(char *name, unsigned long start, unsigned long len) ...@@ -126,12 +126,10 @@ static int register_device(char *name, unsigned long start, unsigned long len)
struct phram_mtd_list *new; struct phram_mtd_list *new;
int ret = -ENOMEM; int ret = -ENOMEM;
new = kmalloc(sizeof(*new), GFP_KERNEL); new = kzalloc(sizeof(*new), GFP_KERNEL);
if (!new) if (!new)
goto out0; goto out0;
memset(new, 0, sizeof(*new));
ret = -EIO; ret = -EIO;
new->mtd.priv = ioremap(start, len); new->mtd.priv = ioremap(start, len);
if (!new->mtd.priv) { if (!new->mtd.priv) {
......
...@@ -168,19 +168,16 @@ static int register_device(char *name, unsigned long start, unsigned long length ...@@ -168,19 +168,16 @@ static int register_device(char *name, unsigned long start, unsigned long length
E("slram: Cannot allocate new MTD device.\n"); E("slram: Cannot allocate new MTD device.\n");
return(-ENOMEM); return(-ENOMEM);
} }
(*curmtd)->mtdinfo = kmalloc(sizeof(struct mtd_info), GFP_KERNEL); (*curmtd)->mtdinfo = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
(*curmtd)->next = NULL; (*curmtd)->next = NULL;
if ((*curmtd)->mtdinfo) { if ((*curmtd)->mtdinfo) {
memset((char *)(*curmtd)->mtdinfo, 0, sizeof(struct mtd_info));
(*curmtd)->mtdinfo->priv = (*curmtd)->mtdinfo->priv =
kmalloc(sizeof(slram_priv_t), GFP_KERNEL); kzalloc(sizeof(slram_priv_t), GFP_KERNEL);
if (!(*curmtd)->mtdinfo->priv) { if (!(*curmtd)->mtdinfo->priv) {
kfree((*curmtd)->mtdinfo); kfree((*curmtd)->mtdinfo);
(*curmtd)->mtdinfo = NULL; (*curmtd)->mtdinfo = NULL;
} else {
memset((*curmtd)->mtdinfo->priv,0,sizeof(slram_priv_t));
} }
} }
......
...@@ -1033,7 +1033,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) ...@@ -1033,7 +1033,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
{ {
partition_t *partition; partition_t *partition;
partition = kmalloc(sizeof(partition_t), GFP_KERNEL); partition = kzalloc(sizeof(partition_t), GFP_KERNEL);
if (!partition) { if (!partition) {
printk(KERN_WARNING "No memory to scan for FTL on %s\n", printk(KERN_WARNING "No memory to scan for FTL on %s\n",
...@@ -1041,8 +1041,6 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) ...@@ -1041,8 +1041,6 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
return; return;
} }
memset(partition, 0, sizeof(partition_t));
partition->mbd.mtd = mtd; partition->mbd.mtd = mtd;
if ((scan_header(partition) == 0) && if ((scan_header(partition) == 0) &&
......
...@@ -67,13 +67,12 @@ static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) ...@@ -67,13 +67,12 @@ static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
DEBUG(MTD_DEBUG_LEVEL3, "INFTL: add_mtd for %s\n", mtd->name); DEBUG(MTD_DEBUG_LEVEL3, "INFTL: add_mtd for %s\n", mtd->name);
inftl = kmalloc(sizeof(*inftl), GFP_KERNEL); inftl = kzalloc(sizeof(*inftl), GFP_KERNEL);
if (!inftl) { if (!inftl) {
printk(KERN_WARNING "INFTL: Out of memory for data structures\n"); printk(KERN_WARNING "INFTL: Out of memory for data structures\n");
return; return;
} }
memset(inftl, 0, sizeof(*inftl));
inftl->mbd.mtd = mtd; inftl->mbd.mtd = mtd;
inftl->mbd.devnum = -1; inftl->mbd.devnum = -1;
......
...@@ -122,10 +122,9 @@ static int __init clps_setup_mtd(struct clps_info *clps, int nr, struct mtd_info ...@@ -122,10 +122,9 @@ static int __init clps_setup_mtd(struct clps_info *clps, int nr, struct mtd_info
/* /*
* Allocate the map_info structs in one go. * Allocate the map_info structs in one go.
*/ */
maps = kmalloc(sizeof(struct map_info) * nr, GFP_KERNEL); maps = kzalloc(sizeof(struct map_info) * nr, GFP_KERNEL);
if (!maps) if (!maps)
return -ENOMEM; return -ENOMEM;
memset(maps, 0, sizeof(struct map_info) * nr);
/* /*
* Claim and then map the memory regions. * Claim and then map the memory regions.
*/ */
......
...@@ -75,14 +75,12 @@ static int armflash_probe(struct platform_device *dev) ...@@ -75,14 +75,12 @@ static int armflash_probe(struct platform_device *dev)
int err; int err;
void __iomem *base; void __iomem *base;
info = kmalloc(sizeof(struct armflash_info), GFP_KERNEL); info = kzalloc(sizeof(struct armflash_info), GFP_KERNEL);
if (!info) { if (!info) {
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
} }
memset(info, 0, sizeof(struct armflash_info));
info->plat = plat; info->plat = plat;
if (plat && plat->init) { if (plat && plat->init) {
err = plat->init(); err = plat->init();
......
...@@ -78,12 +78,10 @@ static int __devinit omapflash_probe(struct platform_device *pdev) ...@@ -78,12 +78,10 @@ static int __devinit omapflash_probe(struct platform_device *pdev)
struct resource *res = pdev->resource; struct resource *res = pdev->resource;
unsigned long size = res->end - res->start + 1; unsigned long size = res->end - res->start + 1;
info = kmalloc(sizeof(struct omapflash_info), GFP_KERNEL); info = kzalloc(sizeof(struct omapflash_info), GFP_KERNEL);
if (!info) if (!info)
return -ENOMEM; return -ENOMEM;
memset(info, 0, sizeof(struct omapflash_info));
if (!request_mem_region(res->start, size, "flash")) { if (!request_mem_region(res->start, size, "flash")) {
err = -EBUSY; err = -EBUSY;
goto out_free_info; goto out_free_info;
......
...@@ -735,11 +735,10 @@ static int pcmciamtd_probe(struct pcmcia_device *link) ...@@ -735,11 +735,10 @@ static int pcmciamtd_probe(struct pcmcia_device *link)
struct pcmciamtd_dev *dev; struct pcmciamtd_dev *dev;
/* Create new memory card device */ /* Create new memory card device */
dev = kmalloc(sizeof(*dev), GFP_KERNEL); dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) return -ENOMEM; if (!dev) return -ENOMEM;
DEBUG(1, "dev=0x%p", dev); DEBUG(1, "dev=0x%p", dev);
memset(dev, 0, sizeof(*dev));
dev->p_dev = link; dev->p_dev = link;
link->priv = dev; link->priv = dev;
......
...@@ -92,12 +92,11 @@ static int physmap_flash_probe(struct platform_device *dev) ...@@ -92,12 +92,11 @@ static int physmap_flash_probe(struct platform_device *dev)
(unsigned long long)(dev->resource->end - dev->resource->start + 1), (unsigned long long)(dev->resource->end - dev->resource->start + 1),
(unsigned long long)dev->resource->start); (unsigned long long)dev->resource->start);
info = kmalloc(sizeof(struct physmap_flash_info), GFP_KERNEL); info = kzalloc(sizeof(struct physmap_flash_info), GFP_KERNEL);
if (info == NULL) { if (info == NULL) {
err = -ENOMEM; err = -ENOMEM;
goto err_out; goto err_out;
} }
memset(info, 0, sizeof(*info));
platform_set_drvdata(dev, info); platform_set_drvdata(dev, info);
......
...@@ -147,14 +147,13 @@ static int platram_probe(struct platform_device *pdev) ...@@ -147,14 +147,13 @@ static int platram_probe(struct platform_device *pdev)
pdata = pdev->dev.platform_data; pdata = pdev->dev.platform_data;
info = kmalloc(sizeof(*info), GFP_KERNEL); info = kzalloc(sizeof(*info), GFP_KERNEL);
if (info == NULL) { if (info == NULL) {
dev_err(&pdev->dev, "no memory for flash info\n"); dev_err(&pdev->dev, "no memory for flash info\n");
err = -ENOMEM; err = -ENOMEM;
goto exit_error; goto exit_error;
} }
memset(info, 0, sizeof(*info));
platform_set_drvdata(pdev, info); platform_set_drvdata(pdev, info);
info->dev = &pdev->dev; info->dev = &pdev->dev;
......
...@@ -273,14 +273,12 @@ sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *plat) ...@@ -273,14 +273,12 @@ sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *plat)
/* /*
* Allocate the map_info structs in one go. * Allocate the map_info structs in one go.
*/ */
info = kmalloc(size, GFP_KERNEL); info = kzalloc(size, GFP_KERNEL);
if (!info) { if (!info) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
memset(info, 0, size);
if (plat->init) { if (plat->init) {
ret = plat->init(); ret = plat->init();
if (ret) if (ret)
......
...@@ -132,20 +132,16 @@ static int __init init_tqm834x_mtd(void) ...@@ -132,20 +132,16 @@ static int __init init_tqm834x_mtd(void)
pr_debug("%s: chip probing count %d\n", __FUNCTION__, idx); pr_debug("%s: chip probing count %d\n", __FUNCTION__, idx);
map_banks[idx] = map_banks[idx] = kzalloc(sizeof(struct map_info), GFP_KERNEL);
(struct map_info *)kmalloc(sizeof(struct map_info),
GFP_KERNEL);
if (map_banks[idx] == NULL) { if (map_banks[idx] == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_mem; goto error_mem;
} }
memset((void *)map_banks[idx], 0, sizeof(struct map_info)); map_banks[idx]->name = kzalloc(16, GFP_KERNEL);
map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL);
if (map_banks[idx]->name == NULL) { if (map_banks[idx]->name == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_mem; goto error_mem;
} }
memset((void *)map_banks[idx]->name, 0, 16);
sprintf(map_banks[idx]->name, "TQM834x-%d", idx); sprintf(map_banks[idx]->name, "TQM834x-%d", idx);
map_banks[idx]->size = flash_size; map_banks[idx]->size = flash_size;
......
...@@ -134,14 +134,13 @@ int __init init_tqm_mtd(void) ...@@ -134,14 +134,13 @@ int __init init_tqm_mtd(void)
printk(KERN_INFO "%s: chip probing count %d\n", __FUNCTION__, idx); printk(KERN_INFO "%s: chip probing count %d\n", __FUNCTION__, idx);
map_banks[idx] = (struct map_info *)kmalloc(sizeof(struct map_info), GFP_KERNEL); map_banks[idx] = kzalloc(sizeof(struct map_info), GFP_KERNEL);
if(map_banks[idx] == NULL) { if(map_banks[idx] == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
/* FIXME: What if some MTD devices were probed already? */ /* FIXME: What if some MTD devices were probed already? */
goto error_mem; goto error_mem;
} }
memset((void *)map_banks[idx], 0, sizeof(struct map_info));
map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL); map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL);
if (!map_banks[idx]->name) { if (!map_banks[idx]->name) {
......
...@@ -373,12 +373,10 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr) ...@@ -373,12 +373,10 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
if (!blktrans_notifier.list.next) if (!blktrans_notifier.list.next)
register_mtd_user(&blktrans_notifier); register_mtd_user(&blktrans_notifier);
tr->blkcore_priv = kmalloc(sizeof(*tr->blkcore_priv), GFP_KERNEL); tr->blkcore_priv = kzalloc(sizeof(*tr->blkcore_priv), GFP_KERNEL);
if (!tr->blkcore_priv) if (!tr->blkcore_priv)
return -ENOMEM; return -ENOMEM;
memset(tr->blkcore_priv, 0, sizeof(*tr->blkcore_priv));
mutex_lock(&mtd_table_mutex); mutex_lock(&mtd_table_mutex);
ret = register_blkdev(tr->major, tr->name); ret = register_blkdev(tr->major, tr->name);
......
...@@ -278,11 +278,10 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd) ...@@ -278,11 +278,10 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
} }
/* OK, it's not open. Create cache info for it */ /* OK, it's not open. Create cache info for it */
mtdblk = kmalloc(sizeof(struct mtdblk_dev), GFP_KERNEL); mtdblk = kzalloc(sizeof(struct mtdblk_dev), GFP_KERNEL);
if (!mtdblk) if (!mtdblk)
return -ENOMEM; return -ENOMEM;
memset(mtdblk, 0, sizeof(*mtdblk));
mtdblk->count = 1; mtdblk->count = 1;
mtdblk->mtd = mtd; mtdblk->mtd = mtd;
...@@ -339,13 +338,11 @@ static int mtdblock_flush(struct mtd_blktrans_dev *dev) ...@@ -339,13 +338,11 @@ static int mtdblock_flush(struct mtd_blktrans_dev *dev)
static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
{ {
struct mtd_blktrans_dev *dev = kmalloc(sizeof(*dev), GFP_KERNEL); struct mtd_blktrans_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) if (!dev)
return; return;
memset(dev, 0, sizeof(*dev));
dev->mtd = mtd; dev->mtd = mtd;
dev->devnum = mtd->index; dev->devnum = mtd->index;
......
...@@ -33,13 +33,11 @@ static int mtdblock_writesect(struct mtd_blktrans_dev *dev, ...@@ -33,13 +33,11 @@ static int mtdblock_writesect(struct mtd_blktrans_dev *dev,
static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
{ {
struct mtd_blktrans_dev *dev = kmalloc(sizeof(*dev), GFP_KERNEL); struct mtd_blktrans_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) if (!dev)
return; return;
memset(dev, 0, sizeof(*dev));
dev->mtd = mtd; dev->mtd = mtd;
dev->devnum = mtd->index; dev->devnum = mtd->index;
......
...@@ -431,7 +431,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file, ...@@ -431,7 +431,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
if(!(file->f_mode & 2)) if(!(file->f_mode & 2))
return -EPERM; return -EPERM;
erase=kmalloc(sizeof(struct erase_info),GFP_KERNEL); erase=kzalloc(sizeof(struct erase_info),GFP_KERNEL);
if (!erase) if (!erase)
ret = -ENOMEM; ret = -ENOMEM;
else { else {
...@@ -440,7 +440,6 @@ static int mtd_ioctl(struct inode *inode, struct file *file, ...@@ -440,7 +440,6 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
init_waitqueue_head(&waitq); init_waitqueue_head(&waitq);
memset (erase,0,sizeof(struct erase_info));
if (copy_from_user(&erase->addr, argp, if (copy_from_user(&erase->addr, argp,
sizeof(struct erase_info_user))) { sizeof(struct erase_info_user))) {
kfree(erase); kfree(erase);
......
...@@ -708,14 +708,13 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c ...@@ -708,14 +708,13 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
/* allocate the device structure */ /* allocate the device structure */
size = SIZEOF_STRUCT_MTD_CONCAT(num_devs); size = SIZEOF_STRUCT_MTD_CONCAT(num_devs);
concat = kmalloc(size, GFP_KERNEL); concat = kzalloc(size, GFP_KERNEL);
if (!concat) { if (!concat) {
printk printk
("memory allocation error while creating concatenated device \"%s\"\n", ("memory allocation error while creating concatenated device \"%s\"\n",
name); name);
return NULL; return NULL;
} }
memset(concat, 0, size);
concat->subdev = (struct mtd_info **) (concat + 1); concat->subdev = (struct mtd_info **) (concat + 1);
/* /*
......
...@@ -323,14 +323,13 @@ int add_mtd_partitions(struct mtd_info *master, ...@@ -323,14 +323,13 @@ int add_mtd_partitions(struct mtd_info *master,
for (i = 0; i < nbparts; i++) { for (i = 0; i < nbparts; i++) {
/* allocate the partition structure */ /* allocate the partition structure */
slave = kmalloc (sizeof(*slave), GFP_KERNEL); slave = kzalloc (sizeof(*slave), GFP_KERNEL);
if (!slave) { if (!slave) {
printk ("memory allocation error while creating partitions for \"%s\"\n", printk ("memory allocation error while creating partitions for \"%s\"\n",
master->name); master->name);
del_mtd_partitions(master); del_mtd_partitions(master);
return -ENOMEM; return -ENOMEM;
} }
memset(slave, 0, sizeof(*slave));
list_add(&slave->list, &mtd_partitions); list_add(&slave->list, &mtd_partitions);
/* set up the MTD object for this partition */ /* set up the MTD object for this partition */
......
...@@ -1635,13 +1635,12 @@ static int __init doc_probe(unsigned long physadr) ...@@ -1635,13 +1635,12 @@ static int __init doc_probe(unsigned long physadr)
len = sizeof(struct mtd_info) + len = sizeof(struct mtd_info) +
sizeof(struct nand_chip) + sizeof(struct doc_priv) + (2 * sizeof(struct nand_bbt_descr)); sizeof(struct nand_chip) + sizeof(struct doc_priv) + (2 * sizeof(struct nand_bbt_descr));
mtd = kmalloc(len, GFP_KERNEL); mtd = kzalloc(len, GFP_KERNEL);
if (!mtd) { if (!mtd) {
printk(KERN_ERR "DiskOnChip kmalloc (%d bytes) failed!\n", len); printk(KERN_ERR "DiskOnChip kmalloc (%d bytes) failed!\n", len);
ret = -ENOMEM; ret = -ENOMEM;
goto fail; goto fail;
} }
memset(mtd, 0, len);
nand = (struct nand_chip *) (mtd + 1); nand = (struct nand_chip *) (mtd + 1);
doc = (struct doc_priv *) (nand + 1); doc = (struct doc_priv *) (nand + 1);
......
...@@ -960,14 +960,12 @@ int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) ...@@ -960,14 +960,12 @@ int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
struct nand_bbt_descr *md = this->bbt_md; struct nand_bbt_descr *md = this->bbt_md;
len = mtd->size >> (this->bbt_erase_shift + 2); len = mtd->size >> (this->bbt_erase_shift + 2);
/* Allocate memory (2bit per block) */ /* Allocate memory (2bit per block) and clear the memory bad block table */
this->bbt = kmalloc(len, GFP_KERNEL); this->bbt = kzalloc(len, GFP_KERNEL);
if (!this->bbt) { if (!this->bbt) {
printk(KERN_ERR "nand_scan_bbt: Out of memory\n"); printk(KERN_ERR "nand_scan_bbt: Out of memory\n");
return -ENOMEM; return -ENOMEM;
} }
/* Clear the memory bad block table */
memset(this->bbt, 0x00, len);
/* If no primary table decriptor is given, scan the device /* If no primary table decriptor is given, scan the device
* to build a memory based bad block table * to build a memory based bad block table
......
...@@ -1511,14 +1511,12 @@ static int __init ns_init_module(void) ...@@ -1511,14 +1511,12 @@ static int __init ns_init_module(void)
} }
/* Allocate and initialize mtd_info, nand_chip and nandsim structures */ /* Allocate and initialize mtd_info, nand_chip and nandsim structures */
nsmtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip) nsmtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip)
+ sizeof(struct nandsim), GFP_KERNEL); + sizeof(struct nandsim), GFP_KERNEL);
if (!nsmtd) { if (!nsmtd) {
NS_ERR("unable to allocate core structures.\n"); NS_ERR("unable to allocate core structures.\n");
return -ENOMEM; return -ENOMEM;
} }
memset(nsmtd, 0, sizeof(struct mtd_info) + sizeof(struct nand_chip) +
sizeof(struct nandsim));
chip = (struct nand_chip *)(nsmtd + 1); chip = (struct nand_chip *)(nsmtd + 1);
nsmtd->priv = (void *)chip; nsmtd->priv = (void *)chip;
nand = (struct nandsim *)(chip + 1); nand = (struct nandsim *)(chip + 1);
......
...@@ -57,13 +57,12 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) ...@@ -57,13 +57,12 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
DEBUG(MTD_DEBUG_LEVEL1, "NFTL: add_mtd for %s\n", mtd->name); DEBUG(MTD_DEBUG_LEVEL1, "NFTL: add_mtd for %s\n", mtd->name);
nftl = kmalloc(sizeof(struct NFTLrecord), GFP_KERNEL); nftl = kzalloc(sizeof(struct NFTLrecord), GFP_KERNEL);
if (!nftl) { if (!nftl) {
printk(KERN_WARNING "NFTL: out of memory for data structures\n"); printk(KERN_WARNING "NFTL: out of memory for data structures\n");
return; return;
} }
memset(nftl, 0, sizeof(*nftl));
nftl->mbd.mtd = mtd; nftl->mbd.mtd = mtd;
nftl->mbd.devnum = -1; nftl->mbd.devnum = -1;
......
...@@ -45,12 +45,10 @@ static int __devinit generic_onenand_probe(struct device *dev) ...@@ -45,12 +45,10 @@ static int __devinit generic_onenand_probe(struct device *dev)
unsigned long size = res->end - res->start + 1; unsigned long size = res->end - res->start + 1;
int err; int err;
info = kmalloc(sizeof(struct onenand_info), GFP_KERNEL); info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
if (!info) if (!info)
return -ENOMEM; return -ENOMEM;
memset(info, 0, sizeof(struct onenand_info));
if (!request_mem_region(res->start, size, dev->driver->name)) { if (!request_mem_region(res->start, size, dev->driver->name)) {
err = -EBUSY; err = -EBUSY;
goto out_free_info; goto out_free_info;
......
...@@ -177,14 +177,12 @@ int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) ...@@ -177,14 +177,12 @@ int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
int len, ret = 0; int len, ret = 0;
len = mtd->size >> (this->erase_shift + 2); len = mtd->size >> (this->erase_shift + 2);
/* Allocate memory (2bit per block) */ /* Allocate memory (2bit per block) and clear the memory bad block table */
bbm->bbt = kmalloc(len, GFP_KERNEL); bbm->bbt = kzalloc(len, GFP_KERNEL);
if (!bbm->bbt) { if (!bbm->bbt) {
printk(KERN_ERR "onenand_scan_bbt: Out of memory\n"); printk(KERN_ERR "onenand_scan_bbt: Out of memory\n");
return -ENOMEM; return -ENOMEM;
} }
/* Clear the memory bad block table */
memset(bbm->bbt, 0x00, len);
/* Set the bad block position */ /* Set the bad block position */
bbm->badblockpos = ONENAND_BADBLOCK_POS; bbm->badblockpos = ONENAND_BADBLOCK_POS;
...@@ -230,14 +228,12 @@ int onenand_default_bbt(struct mtd_info *mtd) ...@@ -230,14 +228,12 @@ int onenand_default_bbt(struct mtd_info *mtd)
struct onenand_chip *this = mtd->priv; struct onenand_chip *this = mtd->priv;
struct bbm_info *bbm; struct bbm_info *bbm;
this->bbm = kmalloc(sizeof(struct bbm_info), GFP_KERNEL); this->bbm = kzalloc(sizeof(struct bbm_info), GFP_KERNEL);
if (!this->bbm) if (!this->bbm)
return -ENOMEM; return -ENOMEM;
bbm = this->bbm; bbm = this->bbm;
memset(bbm, 0, sizeof(struct bbm_info));
/* 1KB page has same configuration as 2KB page */ /* 1KB page has same configuration as 2KB page */
if (!bbm->badblock_pattern) if (!bbm->badblock_pattern)
bbm->badblock_pattern = &largepage_memorybased; bbm->badblock_pattern = &largepage_memorybased;
......
...@@ -165,15 +165,13 @@ static int parse_redboot_partitions(struct mtd_info *master, ...@@ -165,15 +165,13 @@ static int parse_redboot_partitions(struct mtd_info *master,
} }
} }
#endif #endif
parts = kmalloc(sizeof(*parts)*nrparts + nulllen + namelen, GFP_KERNEL); parts = kzalloc(sizeof(*parts)*nrparts + nulllen + namelen, GFP_KERNEL);
if (!parts) { if (!parts) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
memset(parts, 0, sizeof(*parts)*nrparts + nulllen + namelen);
nullname = (char *)&parts[nrparts]; nullname = (char *)&parts[nrparts];
#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED #ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
if (nulllen > 0) { if (nulllen > 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment