diff mbox

[13/36] ARM: OMAP2+: gpmc.c: sanity check bank-width DT property

Message ID 1402477001-31132-14-git-send-email-rogerq@ti.com
State New
Headers show

Commit Message

Roger Quadros June 11, 2014, 8:56 a.m. UTC
Make sure bank-width property provided via DT is sane.

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 arch/arm/mach-omap2/gpmc.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
index c713616..70cb6b0 100644
--- a/arch/arm/mach-omap2/gpmc.c
+++ b/arch/arm/mach-omap2/gpmc.c
@@ -1219,6 +1219,7 @@  static int gpmc_probe_generic_child(struct platform_device *pdev,
 	struct resource res;
 	unsigned long base;
 	int ret, cs;
+	struct device *dev = &pdev->dev;
 
 	if (of_property_read_u32(child, "reg", &cs) < 0) {
 		dev_err(&pdev->dev, "%s has no 'reg' property\n",
@@ -1284,7 +1285,7 @@  static int gpmc_probe_generic_child(struct platform_device *pdev,
 			gpmc_s.device_width = GPMC_DEVWIDTH_16BIT;
 			break;
 		default:
-			dev_err(&pdev->dev, "%s: invalid 'nand-bus-width'\n",
+			dev_err(dev, "%s: invalid 'nand-bus-width'\n",
 				child->name);
 			ret = -EINVAL;
 			goto err;
@@ -1292,10 +1293,18 @@  static int gpmc_probe_generic_child(struct platform_device *pdev,
 
 		gpmc_s.device_nand = true;
 	} else {
-		ret = of_property_read_u32(child, "bank-width",
-					   &gpmc_s.device_width);
-		if (ret < 0)
+		if (of_property_read_u32(child, "bank-width",
+					 &gpmc_s.device_width)) {
+			dev_err(dev, "%s: no 'bank-width' property\n",
+				child->name);
+			goto err;
+		}
+
+		if (gpmc_s.device_width < 1 || gpmc_s.device_width > 2) {
+			dev_err(dev, "%s: invalid 'bank-width'\n",
+				child->name);
 			goto err;
+		}
 	}
 
 	ret = gpmc_cs_program_settings(cs, &gpmc_s);