Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Julia Lawall and committed by
David Woodhouse
2bfefa4c ecce2a6f

+10 -21
+2 -5
drivers/mtd/lpddr/qinfo_probe.c
··· 134 134 static int lpddr_chip_setup(struct map_info *map, struct lpddr_private *lpddr) 135 135 { 136 136 137 - lpddr->qinfo = kmalloc(sizeof(struct qinfo_chip), GFP_KERNEL); 137 + lpddr->qinfo = kzalloc(sizeof(struct qinfo_chip), GFP_KERNEL); 138 138 if (!lpddr->qinfo) { 139 139 printk(KERN_WARNING "%s: no memory for LPDDR qinfo structure\n", 140 140 map->name); 141 141 return 0; 142 142 } 143 - memset(lpddr->qinfo, 0, sizeof(struct qinfo_chip)); 144 143 145 144 /* Get the ManuID */ 146 145 lpddr->ManufactId = CMDVAL(map_read(map, map->pfow_base + PFOW_MANUFACTURER_ID)); ··· 184 185 lpddr.numchips = 1; 185 186 186 187 numvirtchips = lpddr.numchips * lpddr.qinfo->HWPartsNum; 187 - retlpddr = kmalloc(sizeof(struct lpddr_private) + 188 + retlpddr = kzalloc(sizeof(struct lpddr_private) + 188 189 numvirtchips * sizeof(struct flchip), GFP_KERNEL); 189 190 if (!retlpddr) 190 191 return NULL; 191 192 192 - memset(retlpddr, 0, sizeof(struct lpddr_private) + 193 - numvirtchips * sizeof(struct flchip)); 194 193 memcpy(retlpddr, &lpddr, sizeof(struct lpddr_private)); 195 194 196 195 retlpddr->numchips = numvirtchips;
+1 -2
drivers/mtd/maps/ixp2000.c
··· 165 165 return -EIO; 166 166 } 167 167 168 - info = kmalloc(sizeof(struct ixp2000_flash_info), GFP_KERNEL); 168 + info = kzalloc(sizeof(struct ixp2000_flash_info), GFP_KERNEL); 169 169 if(!info) { 170 170 err = -ENOMEM; 171 171 goto Error; 172 172 } 173 - memset(info, 0, sizeof(struct ixp2000_flash_info)); 174 173 175 174 platform_set_drvdata(dev, info); 176 175
+1 -2
drivers/mtd/maps/ixp4xx.c
··· 196 196 return err; 197 197 } 198 198 199 - info = kmalloc(sizeof(struct ixp4xx_flash_info), GFP_KERNEL); 199 + info = kzalloc(sizeof(struct ixp4xx_flash_info), GFP_KERNEL); 200 200 if(!info) { 201 201 err = -ENOMEM; 202 202 goto Error; 203 203 } 204 - memset(info, 0, sizeof(struct ixp4xx_flash_info)); 205 204 206 205 platform_set_drvdata(dev, info); 207 206
+1 -2
drivers/mtd/maps/pxa2xx-flash.c
··· 63 63 if (!res) 64 64 return -ENODEV; 65 65 66 - info = kmalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL); 66 + info = kzalloc(sizeof(struct pxa2xx_flash_info), GFP_KERNEL); 67 67 if (!info) 68 68 return -ENOMEM; 69 69 70 - memset(info, 0, sizeof(struct pxa2xx_flash_info)); 71 70 info->map.name = (char *) flash->name; 72 71 info->map.bankwidth = flash->width; 73 72 info->map.phys = res->start;
+1 -2
drivers/mtd/tests/mtd_pagetest.c
··· 480 480 { 481 481 int i, bad = 0; 482 482 483 - bbt = kmalloc(ebcnt, GFP_KERNEL); 483 + bbt = kzalloc(ebcnt, GFP_KERNEL); 484 484 if (!bbt) { 485 485 printk(PRINT_PREF "error: cannot allocate memory\n"); 486 486 return -ENOMEM; 487 487 } 488 - memset(bbt, 0 , ebcnt); 489 488 490 489 printk(PRINT_PREF "scanning for bad eraseblocks\n"); 491 490 for (i = 0; i < ebcnt; ++i) {
+1 -2
drivers/mtd/tests/mtd_readtest.c
··· 141 141 { 142 142 int i, bad = 0; 143 143 144 - bbt = kmalloc(ebcnt, GFP_KERNEL); 144 + bbt = kzalloc(ebcnt, GFP_KERNEL); 145 145 if (!bbt) { 146 146 printk(PRINT_PREF "error: cannot allocate memory\n"); 147 147 return -ENOMEM; 148 148 } 149 - memset(bbt, 0 , ebcnt); 150 149 151 150 /* NOR flash does not implement block_isbad */ 152 151 if (mtd->block_isbad == NULL)
+1 -2
drivers/mtd/tests/mtd_speedtest.c
··· 295 295 { 296 296 int i, bad = 0; 297 297 298 - bbt = kmalloc(ebcnt, GFP_KERNEL); 298 + bbt = kzalloc(ebcnt, GFP_KERNEL); 299 299 if (!bbt) { 300 300 printk(PRINT_PREF "error: cannot allocate memory\n"); 301 301 return -ENOMEM; 302 302 } 303 - memset(bbt, 0 , ebcnt); 304 303 305 304 /* NOR flash does not implement block_isbad */ 306 305 if (mtd->block_isbad == NULL)
+1 -2
drivers/mtd/tests/mtd_stresstest.c
··· 221 221 { 222 222 int i, bad = 0; 223 223 224 - bbt = kmalloc(ebcnt, GFP_KERNEL); 224 + bbt = kzalloc(ebcnt, GFP_KERNEL); 225 225 if (!bbt) { 226 226 printk(PRINT_PREF "error: cannot allocate memory\n"); 227 227 return -ENOMEM; 228 228 } 229 - memset(bbt, 0 , ebcnt); 230 229 231 230 /* NOR flash does not implement block_isbad */ 232 231 if (mtd->block_isbad == NULL)
+1 -2
drivers/mtd/tests/mtd_subpagetest.c
··· 354 354 { 355 355 int i, bad = 0; 356 356 357 - bbt = kmalloc(ebcnt, GFP_KERNEL); 357 + bbt = kzalloc(ebcnt, GFP_KERNEL); 358 358 if (!bbt) { 359 359 printk(PRINT_PREF "error: cannot allocate memory\n"); 360 360 return -ENOMEM; 361 361 } 362 - memset(bbt, 0 , ebcnt); 363 362 364 363 printk(PRINT_PREF "scanning for bad eraseblocks\n"); 365 364 for (i = 0; i < ebcnt; ++i) {