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>pull/1354/merge
parent
e3d2faffdd
commit
81eb13a19a
|
|
@ -263,7 +263,7 @@ static int build_maps(partition_t *part)
|
||||||
|
|
||||||
/* Set up virtual page map */
|
/* Set up virtual page map */
|
||||||
blocks = le32_to_cpu(header.FormattedSize) >> header.BlockSize;
|
blocks = le32_to_cpu(header.FormattedSize) >> header.BlockSize;
|
||||||
part->VirtualBlockMap = vmalloc(array_size(blocks, sizeof(uint32_t)));
|
part->VirtualBlockMap = vmalloc_array(blocks, sizeof(uint32_t));
|
||||||
if (!part->VirtualBlockMap)
|
if (!part->VirtualBlockMap)
|
||||||
goto out_XferInfo;
|
goto out_XferInfo;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -356,9 +356,8 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
|
||||||
|
|
||||||
/* oops_page_used is a bit field */
|
/* oops_page_used is a bit field */
|
||||||
cxt->oops_page_used =
|
cxt->oops_page_used =
|
||||||
vmalloc(array_size(sizeof(unsigned long),
|
vmalloc_array(DIV_ROUND_UP(mtdoops_pages, BITS_PER_LONG),
|
||||||
DIV_ROUND_UP(mtdoops_pages,
|
sizeof(unsigned long));
|
||||||
BITS_PER_LONG)));
|
|
||||||
if (!cxt->oops_page_used) {
|
if (!cxt->oops_page_used) {
|
||||||
pr_err("could not allocate page array\n");
|
pr_err("could not allocate page array\n");
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1285,11 +1285,11 @@ static int mtdswap_init(struct mtdswap_dev *d, unsigned int eblocks,
|
||||||
for (i = 0; i < MTDSWAP_TREE_CNT; i++)
|
for (i = 0; i < MTDSWAP_TREE_CNT; i++)
|
||||||
d->trees[i].root = RB_ROOT;
|
d->trees[i].root = RB_ROOT;
|
||||||
|
|
||||||
d->page_data = vmalloc(array_size(pages, sizeof(int)));
|
d->page_data = vmalloc_array(pages, sizeof(int));
|
||||||
if (!d->page_data)
|
if (!d->page_data)
|
||||||
goto page_data_fail;
|
goto page_data_fail;
|
||||||
|
|
||||||
d->revmap = vmalloc(array_size(blocks, sizeof(int)));
|
d->revmap = vmalloc_array(blocks, sizeof(int));
|
||||||
if (!d->revmap)
|
if (!d->revmap)
|
||||||
goto revmap_fail;
|
goto revmap_fail;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -552,9 +552,8 @@ static int __init ns_alloc_device(struct nandsim *ns)
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
goto err_close_filp;
|
goto err_close_filp;
|
||||||
}
|
}
|
||||||
ns->pages_written =
|
ns->pages_written = vcalloc(BITS_TO_LONGS(ns->geom.pgnum),
|
||||||
vzalloc(array_size(sizeof(unsigned long),
|
sizeof(unsigned long));
|
||||||
BITS_TO_LONGS(ns->geom.pgnum)));
|
|
||||||
if (!ns->pages_written) {
|
if (!ns->pages_written) {
|
||||||
NS_ERR("alloc_device: unable to allocate pages written array\n");
|
NS_ERR("alloc_device: unable to allocate pages written array\n");
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
|
|
@ -578,7 +577,7 @@ err_close_filp:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
ns->pages = vmalloc(array_size(sizeof(union ns_mem), ns->geom.pgnum));
|
ns->pages = vmalloc_array(ns->geom.pgnum, sizeof(union ns_mem));
|
||||||
if (!ns->pages) {
|
if (!ns->pages) {
|
||||||
NS_ERR("alloc_device: unable to allocate page array\n");
|
NS_ERR("alloc_device: unable to allocate page array\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
|
||||||
|
|
@ -190,8 +190,8 @@ static int scan_header(struct partition *part)
|
||||||
if (!part->blocks)
|
if (!part->blocks)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
part->sector_map = vmalloc(array_size(sizeof(u_long),
|
part->sector_map = vmalloc_array(part->sector_count,
|
||||||
part->sector_count));
|
sizeof(u_long));
|
||||||
if (!part->sector_map)
|
if (!part->sector_map)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue