mtd: rawnand: nandsim: Replace overflow check with kzalloc to single kcalloc
authorRinHizakura <s921975628@gmail.com>
Sat, 25 Dec 2021 10:06:07 +0000 (18:06 +0800)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Sun, 23 Jan 2022 15:37:04 +0000 (16:37 +0100)
Instead of self-checking overflow and allocating an array of specific size
by counting the total required space handy, we already have existed kernel
API which responses for all these works.

Signed-off-by: RinHizakura <s921975628@gmail.com>
Reviewed-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20211225100607.118932-1-s921975628@gmail.com
drivers/mtd/nand/raw/nandsim.c

index 0750121..3698fb4 100644 (file)
@@ -979,15 +979,8 @@ static int ns_read_error(unsigned int page_no)
 
 static int ns_setup_wear_reporting(struct mtd_info *mtd)
 {
-       size_t mem;
-
        wear_eb_count = div_u64(mtd->size, mtd->erasesize);
-       mem = wear_eb_count * sizeof(unsigned long);
-       if (mem / sizeof(unsigned long) != wear_eb_count) {
-               NS_ERR("Too many erase blocks for wear reporting\n");
-               return -ENOMEM;
-       }
-       erase_block_wear = kzalloc(mem, GFP_KERNEL);
+       erase_block_wear = kcalloc(wear_eb_count, sizeof(unsigned long), GFP_KERNEL);
        if (!erase_block_wear) {
                NS_ERR("Too many erase blocks for wear reporting\n");
                return -ENOMEM;