pinctrl: freescale: imx: fix bogus check of of_iomap() return value
diff mbox

Message ID 1457484336-8928-1-git-send-email-vz@mleia.com
State New
Headers show

Commit Message

Vladimir Zapolskiy March 9, 2016, 12:45 a.m. UTC
On error path of_iomap() returns NULL, hence IS_ERR() check is invalid
and may cause a NULL pointer dereference, the change fixes this
problem.

While we are here invert a device node check to simplify the code.

Fixes: 26d8cde5260b ("pinctrl: freescale: imx: add shared input select reg support")
Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
---
 drivers/pinctrl/freescale/pinctrl-imx.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

Comments

Shawn Guo March 15, 2016, 9 a.m. UTC | #1
On Wed, Mar 09, 2016 at 02:45:36AM +0200, Vladimir Zapolskiy wrote:
> On error path of_iomap() returns NULL, hence IS_ERR() check is invalid
> and may cause a NULL pointer dereference, the change fixes this
> problem.
> 
> While we are here invert a device node check to simplify the code.
> 
> Fixes: 26d8cde5260b ("pinctrl: freescale: imx: add shared input select reg support")
> Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>

Acked-by: Shawn Guo <shawnguo@kernel.org>
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij March 16, 2016, 12:57 p.m. UTC | #2
On Wed, Mar 9, 2016 at 1:45 AM, Vladimir Zapolskiy <vz@mleia.com> wrote:

> On error path of_iomap() returns NULL, hence IS_ERR() check is invalid
> and may cause a NULL pointer dereference, the change fixes this
> problem.
>
> While we are here invert a device node check to simplify the code.
>
> Fixes: 26d8cde5260b ("pinctrl: freescale: imx: add shared input select reg support")
> Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>

Patch applied with Shawn's ACK.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
index 4c435cf..b2d0ac7 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx.c
@@ -752,19 +752,18 @@  int imx_pinctrl_probe(struct platform_device *pdev,
 
 	if (of_property_read_bool(dev_np, "fsl,input-sel")) {
 		np = of_parse_phandle(dev_np, "fsl,input-sel", 0);
-		if (np) {
-			ipctl->input_sel_base = of_iomap(np, 0);
-			if (IS_ERR(ipctl->input_sel_base)) {
-				of_node_put(np);
-				dev_err(&pdev->dev,
-					"iomuxc input select base address not found\n");
-				return PTR_ERR(ipctl->input_sel_base);
-			}
-		} else {
+		if (!np) {
 			dev_err(&pdev->dev, "iomuxc fsl,input-sel property not found\n");
 			return -EINVAL;
 		}
+
+		ipctl->input_sel_base = of_iomap(np, 0);
 		of_node_put(np);
+		if (!ipctl->input_sel_base) {
+			dev_err(&pdev->dev,
+				"iomuxc input select base address not found\n");
+			return -ENOMEM;
+		}
 	}
 
 	imx_pinctrl_desc.name = dev_name(&pdev->dev);