[PATCH 3/3] mtd: rawnand: marvell: use OF helper to read a property element count

Miquel Raynal miquel.raynal at bootlin.com
Wed Apr 25 05:53:31 PDT 2018


The 'reg' property of a 'nand' node (with the new bindings) gives the
IDs of each CS line in use. marvell_nand.c driver first look at the
number of CS lines that are present in this property.

Better use of_property_count_elems_of_size() than dividing by 4 the size
of the number of bytes returned by of_get_property().

Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
---
 drivers/mtd/nand/raw/marvell_nand.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/raw/marvell_nand.c b/drivers/mtd/nand/raw/marvell_nand.c
index c33ebc2cc024..1d779a35ac8e 100644
--- a/drivers/mtd/nand/raw/marvell_nand.c
+++ b/drivers/mtd/nand/raw/marvell_nand.c
@@ -2308,17 +2308,11 @@ static int marvell_nand_chip_init(struct device *dev, struct marvell_nfc *nfc,
 	if (pdata || nfc->caps->legacy_of_bindings) {
 		nsels = 1;
 	} else {
-		if (!of_get_property(np, "reg", &nsels)) {
-			dev_err(dev, "missing reg property\n");
+		nsels = of_property_count_elems_of_size(np, "reg", sizeof(u32));
+		if (nsels <= 0) {
+			dev_err(dev, "missing/invalid reg property\n");
 			return -EINVAL;
 		}
-
-		nsels /= sizeof(u32);
-	}
-
-	if (!nsels) {
-		dev_err(dev, "invalid reg property size\n");
-		return -EINVAL;
 	}
 
 	/* Alloc the nand chip structure */
-- 
2.14.1




More information about the linux-mtd mailing list