Skip to content

Commit 81eb13a

Browse files
qianfengrongmiquelraynal
authored andcommitted
mtd: use vmalloc_array and vcalloc to simplify code
Remove array_size() calls and replace vmalloc(array_size()) with vmalloc_array() and vzalloc(array_size()) with vcalloc() to simplify the code. Compile-tested only. Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent e3d2faf commit 81eb13a

5 files changed

Lines changed: 10 additions & 12 deletions

File tree

drivers/mtd/ftl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static int build_maps(partition_t *part)
263263

264264
/* Set up virtual page map */
265265
blocks = le32_to_cpu(header.FormattedSize) >> header.BlockSize;
266-
part->VirtualBlockMap = vmalloc(array_size(blocks, sizeof(uint32_t)));
266+
part->VirtualBlockMap = vmalloc_array(blocks, sizeof(uint32_t));
267267
if (!part->VirtualBlockMap)
268268
goto out_XferInfo;
269269

drivers/mtd/mtdoops.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,8 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
356356

357357
/* oops_page_used is a bit field */
358358
cxt->oops_page_used =
359-
vmalloc(array_size(sizeof(unsigned long),
360-
DIV_ROUND_UP(mtdoops_pages,
361-
BITS_PER_LONG)));
359+
vmalloc_array(DIV_ROUND_UP(mtdoops_pages, BITS_PER_LONG),
360+
sizeof(unsigned long));
362361
if (!cxt->oops_page_used) {
363362
pr_err("could not allocate page array\n");
364363
return;

drivers/mtd/mtdswap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,11 +1285,11 @@ static int mtdswap_init(struct mtdswap_dev *d, unsigned int eblocks,
12851285
for (i = 0; i < MTDSWAP_TREE_CNT; i++)
12861286
d->trees[i].root = RB_ROOT;
12871287

1288-
d->page_data = vmalloc(array_size(pages, sizeof(int)));
1288+
d->page_data = vmalloc_array(pages, sizeof(int));
12891289
if (!d->page_data)
12901290
goto page_data_fail;
12911291

1292-
d->revmap = vmalloc(array_size(blocks, sizeof(int)));
1292+
d->revmap = vmalloc_array(blocks, sizeof(int));
12931293
if (!d->revmap)
12941294
goto revmap_fail;
12951295

drivers/mtd/nand/raw/nandsim.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,8 @@ static int __init ns_alloc_device(struct nandsim *ns)
552552
err = -EINVAL;
553553
goto err_close_filp;
554554
}
555-
ns->pages_written =
556-
vzalloc(array_size(sizeof(unsigned long),
557-
BITS_TO_LONGS(ns->geom.pgnum)));
555+
ns->pages_written = vcalloc(BITS_TO_LONGS(ns->geom.pgnum),
556+
sizeof(unsigned long));
558557
if (!ns->pages_written) {
559558
NS_ERR("alloc_device: unable to allocate pages written array\n");
560559
err = -ENOMEM;
@@ -578,7 +577,7 @@ static int __init ns_alloc_device(struct nandsim *ns)
578577
return err;
579578
}
580579

581-
ns->pages = vmalloc(array_size(sizeof(union ns_mem), ns->geom.pgnum));
580+
ns->pages = vmalloc_array(ns->geom.pgnum, sizeof(union ns_mem));
582581
if (!ns->pages) {
583582
NS_ERR("alloc_device: unable to allocate page array\n");
584583
return -ENOMEM;

drivers/mtd/rfd_ftl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ static int scan_header(struct partition *part)
190190
if (!part->blocks)
191191
goto err;
192192

193-
part->sector_map = vmalloc(array_size(sizeof(u_long),
194-
part->sector_count));
193+
part->sector_map = vmalloc_array(part->sector_count,
194+
sizeof(u_long));
195195
if (!part->sector_map)
196196
goto err;
197197

0 commit comments

Comments
 (0)