mtd: rawnand: Add a check in of_get_nand_secure_regions()
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 17 Jun 2021 13:37:25 +0000 (16:37 +0300)
committerSasha Levin <sashal@kernel.org>
Thu, 26 Aug 2021 12:35:01 +0000 (08:35 -0400)
[ Upstream commit 14f97f0b8e2b9950c028d0cb7311ffe26a3cc1c0 ]

Check for whether of_property_count_elems_of_size() returns a negative
error code.

Fixes: 13b89768275d ("mtd: rawnand: Add support for secure regions in NAND memory")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/YMtQFXE0F1w7mUh+@mwanda
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/mtd/nand/raw/nand_base.c

index fb072c444495013acab4eb5bff26c131d6247ac0..b18c089a7dca2390b56327b0a9c518c19276b87c 100644 (file)
@@ -5059,8 +5059,8 @@ static int of_get_nand_secure_regions(struct nand_chip *chip)
        int nr_elem, i, j;
 
        nr_elem = of_property_count_elems_of_size(dn, "secure-regions", sizeof(u64));
-       if (!nr_elem)
-               return 0;
+       if (nr_elem <= 0)
+               return nr_elem;
 
        chip->nr_secure_regions = nr_elem / 2;
        chip->secure_regions = kcalloc(chip->nr_secure_regions, sizeof(*chip->secure_regions),