All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pwm: img: Fix null pointer access in probe
@ 2020-08-15 16:31 Hauke Mehrtens
  2020-08-19 10:39 ` Lee Jones
  2020-08-20 13:02 ` Uwe Kleine-König
  0 siblings, 2 replies; 4+ messages in thread
From: Hauke Mehrtens @ 2020-08-15 16:31 UTC (permalink / raw)
  To: thierry.reding, u.kleine-koenig, lee.jones
  Cc: ed.blake, linux-pwm, wigyori, Hauke Mehrtens

dev_get_drvdata() is called in img_pwm_runtime_resume() before the
driver data is set.
When pm_runtime_enabled() returns false in img_pwm_probe() it calls
img_pwm_runtime_resume() which results in a null pointer access.

This patch fixes the problem by setting the driver data earlier in the
img_pwm_probe() function.

Fixes: e690ae526216 ("pwm: img: Add runtime PM")
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
 drivers/pwm/pwm-img.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/pwm/pwm-img.c b/drivers/pwm/pwm-img.c
index 599a0f66a384..11831e885e1b 100644
--- a/drivers/pwm/pwm-img.c
+++ b/drivers/pwm/pwm-img.c
@@ -277,6 +277,8 @@ static int img_pwm_probe(struct platform_device *pdev)
 		return PTR_ERR(pwm->pwm_clk);
 	}
 
+	platform_set_drvdata(pdev, pwm);
+
 	pm_runtime_set_autosuspend_delay(&pdev->dev, IMG_PWM_PM_TIMEOUT);
 	pm_runtime_use_autosuspend(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);
@@ -313,7 +315,6 @@ static int img_pwm_probe(struct platform_device *pdev)
 		goto err_suspend;
 	}
 
-	platform_set_drvdata(pdev, pwm);
 	return 0;
 
 err_suspend:
@@ -322,6 +323,7 @@ static int img_pwm_probe(struct platform_device *pdev)
 err_pm_disable:
 	pm_runtime_disable(&pdev->dev);
 	pm_runtime_dont_use_autosuspend(&pdev->dev);
+	platform_set_drvdata(pdev, NULL);
 	return ret;
 }
 
-- 
2.20.1


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

* Re: [PATCH] pwm: img: Fix null pointer access in probe
  2020-08-15 16:31 [PATCH] pwm: img: Fix null pointer access in probe Hauke Mehrtens
@ 2020-08-19 10:39 ` Lee Jones
  2020-08-20 13:02 ` Uwe Kleine-König
  1 sibling, 0 replies; 4+ messages in thread
From: Lee Jones @ 2020-08-19 10:39 UTC (permalink / raw)
  To: Hauke Mehrtens
  Cc: thierry.reding, u.kleine-koenig, ed.blake, linux-pwm, wigyori

On Sat, 15 Aug 2020, Hauke Mehrtens wrote:

> dev_get_drvdata() is called in img_pwm_runtime_resume() before the
> driver data is set.
> When pm_runtime_enabled() returns false in img_pwm_probe() it calls
> img_pwm_runtime_resume() which results in a null pointer access.
> 
> This patch fixes the problem by setting the driver data earlier in the
> img_pwm_probe() function.
> 
> Fixes: e690ae526216 ("pwm: img: Add runtime PM")
> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
> ---
>  drivers/pwm/pwm-img.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Looks fine.

Acked-by: Lee Jones <lee.jones@linaro.org>

-- 
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH] pwm: img: Fix null pointer access in probe
  2020-08-15 16:31 [PATCH] pwm: img: Fix null pointer access in probe Hauke Mehrtens
  2020-08-19 10:39 ` Lee Jones
@ 2020-08-20 13:02 ` Uwe Kleine-König
  2020-08-20 16:16   ` Hauke Mehrtens
  1 sibling, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2020-08-20 13:02 UTC (permalink / raw)
  To: Hauke Mehrtens; +Cc: thierry.reding, lee.jones, ed.blake, linux-pwm, wigyori

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

On Sat, Aug 15, 2020 at 06:31:15PM +0200, Hauke Mehrtens wrote:
> dev_get_drvdata() is called in img_pwm_runtime_resume() before the
> driver data is set.
> When pm_runtime_enabled() returns false in img_pwm_probe() it calls
> img_pwm_runtime_resume() which results in a null pointer access.

Is this a theoretical issue, or did you see this crash on a machine?
 
> This patch fixes the problem by setting the driver data earlier in the
> img_pwm_probe() function.
> 
> Fixes: e690ae526216 ("pwm: img: Add runtime PM")
> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
> ---
>  drivers/pwm/pwm-img.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pwm/pwm-img.c b/drivers/pwm/pwm-img.c
> index 599a0f66a384..11831e885e1b 100644
> --- a/drivers/pwm/pwm-img.c
> +++ b/drivers/pwm/pwm-img.c
> @@ -277,6 +277,8 @@ static int img_pwm_probe(struct platform_device *pdev)
>  		return PTR_ERR(pwm->pwm_clk);
>  	}
>  
> +	platform_set_drvdata(pdev, pwm);
> +
>  	pm_runtime_set_autosuspend_delay(&pdev->dev, IMG_PWM_PM_TIMEOUT);
>  	pm_runtime_use_autosuspend(&pdev->dev);
>  	pm_runtime_enable(&pdev->dev);
> @@ -313,7 +315,6 @@ static int img_pwm_probe(struct platform_device *pdev)
>  		goto err_suspend;
>  	}
>  
> -	platform_set_drvdata(pdev, pwm);
>  	return 0;
>  
>  err_suspend:
> @@ -322,6 +323,7 @@ static int img_pwm_probe(struct platform_device *pdev)
>  err_pm_disable:
>  	pm_runtime_disable(&pdev->dev);
>  	pm_runtime_dont_use_autosuspend(&pdev->dev);
> +	platform_set_drvdata(pdev, NULL);

The driver core takes care about removing drvdata, so this hunk isn't
necessary.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

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

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

* Re: [PATCH] pwm: img: Fix null pointer access in probe
  2020-08-20 13:02 ` Uwe Kleine-König
@ 2020-08-20 16:16   ` Hauke Mehrtens
  0 siblings, 0 replies; 4+ messages in thread
From: Hauke Mehrtens @ 2020-08-20 16:16 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: thierry.reding, lee.jones, ed.blake, linux-pwm, wigyori


[-- Attachment #1.1: Type: text/plain, Size: 1966 bytes --]

On 8/20/20 3:02 PM, Uwe Kleine-König wrote:
> On Sat, Aug 15, 2020 at 06:31:15PM +0200, Hauke Mehrtens wrote:
>> dev_get_drvdata() is called in img_pwm_runtime_resume() before the
>> driver data is set.
>> When pm_runtime_enabled() returns false in img_pwm_probe() it calls
>> img_pwm_runtime_resume() which results in a null pointer access.
> 
> Is this a theoretical issue, or did you see this crash on a machine?

This is a real issue.

I ran into this issue when porting the pistachio target in OpenWrt from
kernel 4.14 to 5.4, it immediately crashed at bootup.

>> This patch fixes the problem by setting the driver data earlier in the
>> img_pwm_probe() function.
>>
>> Fixes: e690ae526216 ("pwm: img: Add runtime PM")
>> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
>> ---
>>  drivers/pwm/pwm-img.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/pwm/pwm-img.c b/drivers/pwm/pwm-img.c
>> index 599a0f66a384..11831e885e1b 100644
>> --- a/drivers/pwm/pwm-img.c
>> +++ b/drivers/pwm/pwm-img.c
>> @@ -277,6 +277,8 @@ static int img_pwm_probe(struct platform_device *pdev)
>>  		return PTR_ERR(pwm->pwm_clk);
>>  	}
>>  
>> +	platform_set_drvdata(pdev, pwm);
>> +
>>  	pm_runtime_set_autosuspend_delay(&pdev->dev, IMG_PWM_PM_TIMEOUT);
>>  	pm_runtime_use_autosuspend(&pdev->dev);
>>  	pm_runtime_enable(&pdev->dev);
>> @@ -313,7 +315,6 @@ static int img_pwm_probe(struct platform_device *pdev)
>>  		goto err_suspend;
>>  	}
>>  
>> -	platform_set_drvdata(pdev, pwm);
>>  	return 0;
>>  
>>  err_suspend:
>> @@ -322,6 +323,7 @@ static int img_pwm_probe(struct platform_device *pdev)
>>  err_pm_disable:
>>  	pm_runtime_disable(&pdev->dev);
>>  	pm_runtime_dont_use_autosuspend(&pdev->dev);
>> +	platform_set_drvdata(pdev, NULL);
> 
> The driver core takes care about removing drvdata, so this hunk isn't
> necessary.

I will send a v2 without this change.

Hauke


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2020-08-20 16:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-15 16:31 [PATCH] pwm: img: Fix null pointer access in probe Hauke Mehrtens
2020-08-19 10:39 ` Lee Jones
2020-08-20 13:02 ` Uwe Kleine-König
2020-08-20 16:16   ` Hauke Mehrtens

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.