mirror of https://gitee.com/openkylin/linux.git
drivers/mtd: Use kzalloc
Use kzalloc rather than the combination of kmalloc and memset. The semantic patch that makes this change is as follows: (http://coccinelle.lip6.fr/) // <smpl> @@ expression x,size,flags; statement S; @@ -x = kmalloc(size,flags); +x = kzalloc(size,flags); if (x == NULL) S -memset(x, 0, size); // </smpl> Signed-off-by: Julia Lawall <julia@diku.dk> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
This commit is contained in:
parent
ecce2a6f9b
commit
2bfefa4c96
|
@ -134,13 +134,12 @@ static int lpddr_pfow_present(struct map_info *map, struct lpddr_private *lpddr)
|
||||||
static int lpddr_chip_setup(struct map_info *map, struct lpddr_private *lpddr)
|
static int lpddr_chip_setup(struct map_info *map, struct lpddr_private *lpddr)
|
||||||
{
|
{
|
||||||
|
|
||||||
lpddr->qinfo = kmalloc(sizeof(struct qinfo_chip), GFP_KERNEL);
|
lpddr->qinfo = kzalloc(sizeof(struct qinfo_chip), GFP_KERNEL);
|
||||||
if (!lpddr->qinfo) {
|
if (!lpddr->qinfo) {
|
||||||
printk(KERN_WARNING "%s: no memory for LPDDR qinfo structure\n",
|
printk(KERN_WARNING "%s: no memory for LPDDR qinfo structure\n",
|
||||||
map->name);
|
map->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memset(lpddr->qinfo, 0, sizeof(struct qinfo_chip));
|
|
||||||
|
|
||||||
/* Get the ManuID */
|
/* Get the ManuID */
|
||||||
lpddr->ManufactId = CMDVAL(map_read(map, map->pfow_base + PFOW_MANUFACTURER_ID));
|
lpddr->ManufactId = CMDVAL(map_read(map, map->pfow_base + PFOW_MANUFACTURER_ID));
|
||||||
|
@ -185,13 +184,11 @@ static struct lpddr_private *lpddr_probe_chip(struct map_info *map)
|
||||||
lpddr.numchips = 1;
|
lpddr.numchips = 1;
|
||||||
|
|
||||||
numvirtchips = lpddr.numchips * lpddr.qinfo->HWPartsNum;
|
numvirtchips = lpddr.numchips * lpddr.qinfo->HWPartsNum;
|
||||||
retlpddr = kmalloc(sizeof(struct lpddr_private) +
|
retlpddr = kzalloc(sizeof(struct lpddr_private) +
|
||||||
numvirtchips * sizeof(struct flchip), GFP_KERNEL);
|
numvirtchips * sizeof(struct flchip), GFP_KERNEL);
|
||||||
if (!retlpddr)
|
if (!retlpddr)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memset(retlpddr, 0, sizeof(struct lpddr_private) +
|
|
||||||
numvirtchips * sizeof(struct flchip));
|
|
||||||
memcpy(retlpddr, &lpddr, sizeof(struct lpddr_private));
|
memcpy(retlpddr, &lpddr, sizeof(struct lpddr_private));
|
||||||
|
|
||||||
retlpddr->numchips = numvirtchips;
|
retlpddr->numchips = numvirtchips;
|
||||||
|
|
|
@ -165,12 +165,11 @@ static int ixp2000_flash_probe(struct platform_device *dev)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
info = kmalloc(sizeof(struct ixp2000_flash_info), GFP_KERNEL);
|
info = kzalloc(sizeof(struct ixp2000_flash_info), GFP_KERNEL);
|
||||||
if(!info) {
|
if(!info) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto Error;
|
goto Error;
|
||||||
}
|
}
|
||||||
memset(info, 0, sizeof(struct ixp2000_flash_info));
|
|
||||||
|
|
||||||
platform_set_drvdata(dev, info);
|
platform_set_drvdata(dev, info);
|
||||||
|
|
||||||
|
|
|
@ -196,12 +196,11 @@ static int ixp4xx_flash_probe(struct platform_device *dev)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
info = kmalloc(sizeof(struct ixp4xx_flash_info), GFP_KERNEL);
|
info = kzalloc(sizeof(struct ixp4xx_flash_info), GFP_KERNEL);
|
||||||
if(!info) {
|
if(!info) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto Error;
|
goto Error;
|
||||||
}
|
}
|
||||||
memset(info, 0, sizeof(struct ixp4xx_flash_info));
|
|
||||||
|
|
||||||
platform_set_drvdata(dev, info);
|
platform_set_drvdata(dev, info);
|
||||||
|
|
||||||
|
|
|
@ -63,11 +63,10 @@ static int __init pxa2xx_flash_probe(struct platform_device *pdev)
|
||||||
if (!res)
|
if (!res)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
info = kmalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL);
|
info = kzalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL);
|
||||||
if (!info)
|
if (!info)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
memset(info, 0, sizeof(struct pxa2xx_flash_info));
|
|
||||||
info->map.name = (char *) flash->name;
|
info->map.name = (char *) flash->name;
|
||||||
info->map.bankwidth = flash->width;
|
info->map.bankwidth = flash->width;
|
||||||
info->map.phys = res->start;
|
info->map.phys = res->start;
|
||||||
|
|
|
@ -480,12 +480,11 @@ static int scan_for_bad_eraseblocks(void)
|
||||||
{
|
{
|
||||||
int i, bad = 0;
|
int i, bad = 0;
|
||||||
|
|
||||||
bbt = kmalloc(ebcnt, GFP_KERNEL);
|
bbt = kzalloc(ebcnt, GFP_KERNEL);
|
||||||
if (!bbt) {
|
if (!bbt) {
|
||||||
printk(PRINT_PREF "error: cannot allocate memory\n");
|
printk(PRINT_PREF "error: cannot allocate memory\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
memset(bbt, 0 , ebcnt);
|
|
||||||
|
|
||||||
printk(PRINT_PREF "scanning for bad eraseblocks\n");
|
printk(PRINT_PREF "scanning for bad eraseblocks\n");
|
||||||
for (i = 0; i < ebcnt; ++i) {
|
for (i = 0; i < ebcnt; ++i) {
|
||||||
|
|
|
@ -141,12 +141,11 @@ static int scan_for_bad_eraseblocks(void)
|
||||||
{
|
{
|
||||||
int i, bad = 0;
|
int i, bad = 0;
|
||||||
|
|
||||||
bbt = kmalloc(ebcnt, GFP_KERNEL);
|
bbt = kzalloc(ebcnt, GFP_KERNEL);
|
||||||
if (!bbt) {
|
if (!bbt) {
|
||||||
printk(PRINT_PREF "error: cannot allocate memory\n");
|
printk(PRINT_PREF "error: cannot allocate memory\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
memset(bbt, 0 , ebcnt);
|
|
||||||
|
|
||||||
/* NOR flash does not implement block_isbad */
|
/* NOR flash does not implement block_isbad */
|
||||||
if (mtd->block_isbad == NULL)
|
if (mtd->block_isbad == NULL)
|
||||||
|
|
|
@ -295,12 +295,11 @@ static int scan_for_bad_eraseblocks(void)
|
||||||
{
|
{
|
||||||
int i, bad = 0;
|
int i, bad = 0;
|
||||||
|
|
||||||
bbt = kmalloc(ebcnt, GFP_KERNEL);
|
bbt = kzalloc(ebcnt, GFP_KERNEL);
|
||||||
if (!bbt) {
|
if (!bbt) {
|
||||||
printk(PRINT_PREF "error: cannot allocate memory\n");
|
printk(PRINT_PREF "error: cannot allocate memory\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
memset(bbt, 0 , ebcnt);
|
|
||||||
|
|
||||||
/* NOR flash does not implement block_isbad */
|
/* NOR flash does not implement block_isbad */
|
||||||
if (mtd->block_isbad == NULL)
|
if (mtd->block_isbad == NULL)
|
||||||
|
|
|
@ -221,12 +221,11 @@ static int scan_for_bad_eraseblocks(void)
|
||||||
{
|
{
|
||||||
int i, bad = 0;
|
int i, bad = 0;
|
||||||
|
|
||||||
bbt = kmalloc(ebcnt, GFP_KERNEL);
|
bbt = kzalloc(ebcnt, GFP_KERNEL);
|
||||||
if (!bbt) {
|
if (!bbt) {
|
||||||
printk(PRINT_PREF "error: cannot allocate memory\n");
|
printk(PRINT_PREF "error: cannot allocate memory\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
memset(bbt, 0 , ebcnt);
|
|
||||||
|
|
||||||
/* NOR flash does not implement block_isbad */
|
/* NOR flash does not implement block_isbad */
|
||||||
if (mtd->block_isbad == NULL)
|
if (mtd->block_isbad == NULL)
|
||||||
|
|
|
@ -354,12 +354,11 @@ static int scan_for_bad_eraseblocks(void)
|
||||||
{
|
{
|
||||||
int i, bad = 0;
|
int i, bad = 0;
|
||||||
|
|
||||||
bbt = kmalloc(ebcnt, GFP_KERNEL);
|
bbt = kzalloc(ebcnt, GFP_KERNEL);
|
||||||
if (!bbt) {
|
if (!bbt) {
|
||||||
printk(PRINT_PREF "error: cannot allocate memory\n");
|
printk(PRINT_PREF "error: cannot allocate memory\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
memset(bbt, 0 , ebcnt);
|
|
||||||
|
|
||||||
printk(PRINT_PREF "scanning for bad eraseblocks\n");
|
printk(PRINT_PREF "scanning for bad eraseblocks\n");
|
||||||
for (i = 0; i < ebcnt; ++i) {
|
for (i = 0; i < ebcnt; ++i) {
|
||||||
|
|
Loading…
Reference in New Issue