linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] backlight: pwm_bl: Fix broken PWM backlight for non-dt platforms
@ 2015-12-10  9:09 Philipp Zabel
  2015-12-11 17:33 ` Robert Jarzmik
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Philipp Zabel @ 2015-12-10  9:09 UTC (permalink / raw)
  To: Lee Jones
  Cc: Thierry Reding, linux-pwm, Robert Jarzmik, kernel, linux-kernel,
	Philipp Zabel

Commit ee65ad0e2a9e ("backlight: pwm_bl: Avoid backlight flicker when
probed from DT") tries to dereference the device of_node pointer
unconditionally, causing a NULL pointer dereference on non-dt platforms.
Fix it by replacing the phandle variable with a node variable and
by checking that for NULL before dereferencing it.

Reported-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/video/backlight/pwm_bl.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 3daf9cc..a22c1ec 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -198,8 +198,8 @@ static int pwm_backlight_probe(struct platform_device *pdev)
 	struct platform_pwm_backlight_data defdata;
 	struct backlight_properties props;
 	struct backlight_device *bl;
+	struct device_node *node = pdev->dev.of_node;
 	struct pwm_bl_data *pb;
-	phandle phandle = pdev->dev.of_node->phandle;
 	int initial_blank = FB_BLANK_UNBLANK;
 	int ret;
 
@@ -273,7 +273,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
 		 * assume that another driver will enable the backlight at the
 		 * appropriate time. Therefore, if it is disabled, keep it so.
 		 */
-		if (phandle &&
+		if (node && node->phandle &&
 		    gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_OUT &&
 		    gpiod_get_value(pb->enable_gpio) == 0)
 			initial_blank = FB_BLANK_POWERDOWN;
@@ -287,12 +287,11 @@ static int pwm_backlight_probe(struct platform_device *pdev)
 		goto err_alloc;
 	}
 
-	if (phandle && !regulator_is_enabled(pb->power_supply))
+	if (node && node->phandle && !regulator_is_enabled(pb->power_supply))
 		initial_blank = FB_BLANK_POWERDOWN;
 
 	pb->pwm = devm_pwm_get(&pdev->dev, NULL);
-	if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER
-	    && !pdev->dev.of_node) {
+	if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER && !node) {
 		dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n");
 		pb->legacy = true;
 		pb->pwm = pwm_request(data->pwm_id, "pwm-backlight");
-- 
2.6.2

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

* Re: [PATCH] backlight: pwm_bl: Fix broken PWM backlight for non-dt platforms
  2015-12-10  9:09 [PATCH] backlight: pwm_bl: Fix broken PWM backlight for non-dt platforms Philipp Zabel
@ 2015-12-11 17:33 ` Robert Jarzmik
  2015-12-16 15:56 ` Thierry Reding
  2016-01-11  6:35 ` Lee Jones
  2 siblings, 0 replies; 4+ messages in thread
From: Robert Jarzmik @ 2015-12-11 17:33 UTC (permalink / raw)
  To: Philipp Zabel; +Cc: Lee Jones, Thierry Reding, linux-pwm, kernel, linux-kernel

Philipp Zabel <p.zabel@pengutronix.de> writes:

> Commit ee65ad0e2a9e ("backlight: pwm_bl: Avoid backlight flicker when
> probed from DT") tries to dereference the device of_node pointer
> unconditionally, causing a NULL pointer dereference on non-dt platforms.
> Fix it by replacing the phandle variable with a node variable and
> by checking that for NULL before dereferencing it.
>
> Reported-by: Robert Jarzmik <robert.jarzmik@free.fr>
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
And indeed it does the trick.

Tested-by: Robert Jarzmik <robert.jarzmik@free.fr>

-- 
Robert

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

* Re: [PATCH] backlight: pwm_bl: Fix broken PWM backlight for non-dt platforms
  2015-12-10  9:09 [PATCH] backlight: pwm_bl: Fix broken PWM backlight for non-dt platforms Philipp Zabel
  2015-12-11 17:33 ` Robert Jarzmik
@ 2015-12-16 15:56 ` Thierry Reding
  2016-01-11  6:35 ` Lee Jones
  2 siblings, 0 replies; 4+ messages in thread
From: Thierry Reding @ 2015-12-16 15:56 UTC (permalink / raw)
  To: Philipp Zabel; +Cc: Lee Jones, linux-pwm, Robert Jarzmik, kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 686 bytes --]

On Thu, Dec 10, 2015 at 10:09:06AM +0100, Philipp Zabel wrote:
> Commit ee65ad0e2a9e ("backlight: pwm_bl: Avoid backlight flicker when
> probed from DT") tries to dereference the device of_node pointer
> unconditionally, causing a NULL pointer dereference on non-dt platforms.
> Fix it by replacing the phandle variable with a node variable and
> by checking that for NULL before dereferencing it.
> 
> Reported-by: Robert Jarzmik <robert.jarzmik@free.fr>
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  drivers/video/backlight/pwm_bl.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)

Acked-by: Thierry Reding <thierry.reding@gmail.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH] backlight: pwm_bl: Fix broken PWM backlight for non-dt platforms
  2015-12-10  9:09 [PATCH] backlight: pwm_bl: Fix broken PWM backlight for non-dt platforms Philipp Zabel
  2015-12-11 17:33 ` Robert Jarzmik
  2015-12-16 15:56 ` Thierry Reding
@ 2016-01-11  6:35 ` Lee Jones
  2 siblings, 0 replies; 4+ messages in thread
From: Lee Jones @ 2016-01-11  6:35 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Thierry Reding, linux-pwm, Robert Jarzmik, kernel, linux-kernel

On Thu, 10 Dec 2015, Philipp Zabel wrote:

> Commit ee65ad0e2a9e ("backlight: pwm_bl: Avoid backlight flicker when
> probed from DT") tries to dereference the device of_node pointer
> unconditionally, causing a NULL pointer dereference on non-dt platforms.
> Fix it by replacing the phandle variable with a node variable and
> by checking that for NULL before dereferencing it.
> 
> Reported-by: Robert Jarzmik <robert.jarzmik@free.fr>
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  drivers/video/backlight/pwm_bl.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)

Applied, thanks.

> diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
> index 3daf9cc..a22c1ec 100644
> --- a/drivers/video/backlight/pwm_bl.c
> +++ b/drivers/video/backlight/pwm_bl.c
> @@ -198,8 +198,8 @@ static int pwm_backlight_probe(struct platform_device *pdev)
>  	struct platform_pwm_backlight_data defdata;
>  	struct backlight_properties props;
>  	struct backlight_device *bl;
> +	struct device_node *node = pdev->dev.of_node;
>  	struct pwm_bl_data *pb;
> -	phandle phandle = pdev->dev.of_node->phandle;
>  	int initial_blank = FB_BLANK_UNBLANK;
>  	int ret;
>  
> @@ -273,7 +273,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
>  		 * assume that another driver will enable the backlight at the
>  		 * appropriate time. Therefore, if it is disabled, keep it so.
>  		 */
> -		if (phandle &&
> +		if (node && node->phandle &&
>  		    gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_OUT &&
>  		    gpiod_get_value(pb->enable_gpio) == 0)
>  			initial_blank = FB_BLANK_POWERDOWN;
> @@ -287,12 +287,11 @@ static int pwm_backlight_probe(struct platform_device *pdev)
>  		goto err_alloc;
>  	}
>  
> -	if (phandle && !regulator_is_enabled(pb->power_supply))
> +	if (node && node->phandle && !regulator_is_enabled(pb->power_supply))
>  		initial_blank = FB_BLANK_POWERDOWN;
>  
>  	pb->pwm = devm_pwm_get(&pdev->dev, NULL);
> -	if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER
> -	    && !pdev->dev.of_node) {
> +	if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER && !node) {
>  		dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n");
>  		pb->legacy = true;
>  		pb->pwm = pwm_request(data->pwm_id, "pwm-backlight");

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

end of thread, other threads:[~2016-01-11  6:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-10  9:09 [PATCH] backlight: pwm_bl: Fix broken PWM backlight for non-dt platforms Philipp Zabel
2015-12-11 17:33 ` Robert Jarzmik
2015-12-16 15:56 ` Thierry Reding
2016-01-11  6:35 ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).