Linux-Amlogic Archive on lore.kernel.org
 help / Atom feed
* [PATCH] soc: amlogic: canvas: Fix meson_canvas_get when probe failed
@ 2019-02-04  9:49 Neil Armstrong
  2019-02-04  9:59 ` Maxime Jourdan
  0 siblings, 1 reply; 3+ messages in thread
From: Neil Armstrong @ 2019-02-04  9:49 UTC (permalink / raw)
  To: khilman; +Cc: linux-amlogic, linux-kernel, linux-arm-kernel, 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")
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
---
 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/

diff --git a/drivers/soc/amlogic/meson-canvas.c b/drivers/soc/amlogic/meson-canvas.c
index 87a6c6e23591..151aa84bc593 100644
--- a/drivers/soc/amlogic/meson-canvas.c
+++ b/drivers/soc/amlogic/meson-canvas.c
@@ -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);
 
-- 
2.20.1


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] soc: amlogic: canvas: Fix meson_canvas_get when probe failed
  2019-02-04  9:49 [PATCH] soc: amlogic: canvas: Fix meson_canvas_get when probe failed Neil Armstrong
@ 2019-02-04  9:59 ` Maxime Jourdan
  2019-02-08  0:30   ` Kevin Hilman
  0 siblings, 1 reply; 3+ messages in thread
From: Maxime Jourdan @ 2019-02-04  9:59 UTC (permalink / raw)
  To: Neil Armstrong
  Cc: Kevin Hilman, linux-kernel, linux-arm-kernel, linux-amlogic

Hi Neil,
On Mon, Feb 4, 2019 at 10:49 AM Neil Armstrong <narmstrong@baylibre.com> wrote:
>
> 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")
> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> ---
>  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/
>
> diff --git a/drivers/soc/amlogic/meson-canvas.c b/drivers/soc/amlogic/meson-canvas.c
> index 87a6c6e23591..151aa84bc593 100644
> --- a/drivers/soc/amlogic/meson-canvas.c
> +++ b/drivers/soc/amlogic/meson-canvas.c
> @@ -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

Bait -> Bail ?

> +        * 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
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> 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.

Reviewed-by: Maxime Jourdan <mjourdan@baylibre.com>

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] soc: amlogic: canvas: Fix meson_canvas_get when probe failed
  2019-02-04  9:59 ` Maxime Jourdan
@ 2019-02-08  0:30   ` Kevin Hilman
  0 siblings, 0 replies; 3+ messages in thread
From: Kevin Hilman @ 2019-02-08  0:30 UTC (permalink / raw)
  To: Maxime Jourdan, Neil Armstrong
  Cc: linux-amlogic, linux-kernel, linux-arm-kernel

Maxime Jourdan <mjourdan@baylibre.com> writes:

> On Mon, Feb 4, 2019 at 10:49 AM Neil Armstrong <narmstrong@baylibre.com> wrote:
>>
>> 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")
>> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
>> ---
>>  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/
>>
>> diff --git a/drivers/soc/amlogic/meson-canvas.c b/drivers/soc/amlogic/meson-canvas.c
>> index 87a6c6e23591..151aa84bc593 100644
>> --- a/drivers/soc/amlogic/meson-canvas.c
>> +++ b/drivers/soc/amlogic/meson-canvas.c
>> @@ -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
>
> Bait -> Bail ?

Fixed this up locally.

[...]

> Thanks for the patch, I missed the fact that a driver could have a
> pdev yet with a failed probe.
>
> Reviewed-by: Maxime Jourdan <mjourdan@baylibre.com>

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

Kevin

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-04  9:49 [PATCH] soc: amlogic: canvas: Fix meson_canvas_get when probe failed Neil Armstrong
2019-02-04  9:59 ` Maxime Jourdan
2019-02-08  0:30   ` Kevin Hilman

Linux-Amlogic Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-amlogic/0 linux-amlogic/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-amlogic linux-amlogic/ https://lore.kernel.org/linux-amlogic \
		linux-amlogic@lists.infradead.org linux-amlogic@archiver.kernel.org
	public-inbox-index linux-amlogic


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-amlogic


AGPL code for this site: git clone https://public-inbox.org/ public-inbox