Skip to contentSkip to conversation

soc: amlogic: canvas: Fix meson_canvas_get when probe failed

PATCH In review Neil Armstrong 3 participants 3 messages Feb 4, 2019 – Feb 8, 2019 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soc: amlogic: canvas: Fix meson_canvas_get when probe failed

When probe fails, a platforn_device is still associated to the node, but dev_get_drvdata() returns NULL.

Handle this case by returning a consistent error.

Fixes d4983983d987 ("soc: amlogic: add meson-canvas driver")
---
 drivers/soc/amlogic/meson-canvas.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

This fix depends on "soc: amlogic: add missing of_node_put()" at [1]

[1] https://patchwork.kernel.org/patch/10794545/

drivers/soc/amlogic/meson-canvas.c +12 -1
index 87a6c6e23591..151aa84bc593 100644
@@ -51,6 +51,7 @@ struct meson_canvas *meson_canvas_get(struct device *dev)
 {
 	struct device_node *canvas_node;
 	struct platform_device *canvas_pdev;
+	struct meson_canvas *canvas;
 
 	canvas_node = of_parse_phandle(dev->of_node, "amlogic,canvas", 0);
 	if (!canvas_node)
@@ -63,7 +64,17 @@ struct meson_canvas *meson_canvas_get(struct device *dev)
 	}
 
 	of_node_put(canvas_node);
-	return dev_get_drvdata(&canvas_pdev->dev);
+
+	/*
+	 * If priv is NULL, it's probably because the canvas hasn't
+	 * properly initialized. Bait out with -EINVAL because, in the
+	 * current state, this driver probe cannot return -EPROBE_DEFER
+	 */
+	canvas = dev_get_drvdata(&canvas_pdev->dev);
+	if (!canvas)
+		return ERR_PTR(-EINVAL);
+
+	return canvas;
 }
 EXPORT_SYMBOL_GPL(meson_canvas_get);
 
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Neil,

Quoted 29 lines · Neil Armstrong

When probe fails, a platforn_device is still associated to the node, but dev_get_drvdata() returns NULL.

Handle this case by returning a consistent error.

Fixes d4983983d987 ("soc: amlogic: add meson-canvas driver")
---
 drivers/soc/amlogic/meson-canvas.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

This fix depends on "soc: amlogic: add missing of_node_put()" at [1]

[1] https://patchwork.kernel.org/patch/10794545/

drivers/soc/amlogic/meson-canvas.c +1 -0
index 87a6c6e23591..151aa84bc593 100644
@@ -51,6 +51,7 @@ struct meson_canvas *meson_canvas_get(struct device *dev)
 {
        struct device_node *canvas_node;
        struct platform_device *canvas_pdev;
+       struct meson_canvas *canvas;
 
        canvas_node = of_parse_phandle(dev->of_node, "amlogic,canvas", 0);
        if (!canvas_node)

drivers/soc/amlogic/meson-canvas.c struct meson_canvas *meson_canvas_get(struct device *dev) · line 70

Quoted 8 lines
drivers/soc/amlogic/meson-canvas.c +4 -1
@@ -63,7 +64,17 @@ struct meson_canvas *meson_canvas_get(struct device *dev)
        }
 
        of_node_put(canvas_node);
-       return dev_get_drvdata(&canvas_pdev->dev);
+
+       /*
+        * If priv is NULL, it's probably because the canvas hasn't
+        * properly initialized. Bait out with -EINVAL because, in the

Bait -> Bail ?

Quoted 14 lines
drivers/soc/amlogic/meson-canvas.c +7 -1
+        * current state, this driver probe cannot return -EPROBE_DEFER
+        */
+       canvas = dev_get_drvdata(&canvas_pdev->dev);
+       if (!canvas)
+               return ERR_PTR(-EINVAL);
+
+       return canvas;
 }
 EXPORT_SYMBOL_GPL(meson_canvas_get);
 
--

2.20.1

Quoted 4 lines

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Thanks for the patch, I missed the fact that a driver could have a pdev yet with a failed probe.

maintainer
#2 lore raw
Quoted 32 lines · Maxime Jourdan
Quoted 31 lines · Neil Armstrong

When probe fails, a platforn_device is still associated to the node, but dev_get_drvdata() returns NULL.

Handle this case by returning a consistent error.

Fixes d4983983d987 ("soc: amlogic: add meson-canvas driver")
---
 drivers/soc/amlogic/meson-canvas.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

This fix depends on "soc: amlogic: add missing of_node_put()" at [1]

[1] https://patchwork.kernel.org/patch/10794545/

drivers/soc/amlogic/meson-canvas.c +1 -0
index 87a6c6e23591..151aa84bc593 100644
@@ -51,6 +51,7 @@ struct meson_canvas *meson_canvas_get(struct device *dev)
 {
        struct device_node *canvas_node;
        struct platform_device *canvas_pdev;
+       struct meson_canvas *canvas;
 
        canvas_node = of_parse_phandle(dev->of_node, "amlogic,canvas", 0);
        if (!canvas_node)
@@ -63,7 +64,17 @@ struct meson_canvas *meson_canvas_get(struct device *dev)
        }
 
Quoted 8 lines

drivers/soc/amlogic/meson-canvas.c struct meson_canvas *meson_canvas_get(struct device *dev) · line 70

Quoted 6 lines
drivers/soc/amlogic/meson-canvas.c +4 -1
        of_node_put(canvas_node);
-       return dev_get_drvdata(&canvas_pdev->dev);
+
+       /*
+        * If priv is NULL, it's probably because the canvas hasn't
+        * properly initialized. Bait out with -EINVAL because, in the

Bait -> Bail ?

Fixed this up locally.

[...]

Quoted 4 lines

Thanks for the patch, I missed the fact that a driver could have a pdev yet with a failed probe.

Queud for v5.1 with Maxime's tag. (branch: v5.1/drivers)

Kevin