Discussion:
[PATCH 0/2] backlight: pwm: fix oops on accessing removed legacy pwm device
Vladimir Zapolskiy
2014-10-11 13:46:24 UTC
Permalink
The changeset fixes an oops, if pwm device was allocated by calling
legacy API and not deregistered appropriately on removal:

% dmesg | grep -i pwm
pwm-backlight backlight.19: unable to request PWM, trying legacy API
% rmmod pwm_bl
% cat /sys/kernel/debug/pwm
Unable to handle kernel paging request at virtual address 7f0c18cc
pgd = ace18000
[7f0c18cc] *pgd=3c5eb811, *pte=00000000, *ppte=00000000
Internal error: Oops: 7 [#1] PREEMPT SMP ARM
......

Vladimir Zapolskiy (2):
backlight: pwm: don't call legacy pwm request for device defined in dt
backlight: pwm: clean up pwm requested using legacy API

drivers/video/backlight/pwm_bl.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-pwm" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Vladimir Zapolskiy
2014-10-11 13:46:25 UTC
Permalink
Platform PWM backlight data provided by board's device tree should be
complete enough to successfully request a pwm device using pwm_get() API.

Based on initial implementation done by Dmitry Eremin-Solenikov.

Reported-by: Dmitry Eremin-Solenikov <***@mentor.com>
Signed-off-by: Vladimir Zapolskiy <***@mentor.com>
Cc: Thierry Reding <***@gmail.com>
Cc: Jingoo Han <***@samsung.com>
Cc: Bryan Wu <***@gmail.com>
Cc: Lee Jones <***@linaro.org>
---
drivers/video/backlight/pwm_bl.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index cb5ae4c..dd7aaf7 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -272,15 +272,15 @@ static int pwm_backlight_probe(struct platform_device *pdev)
}

pb->pwm = devm_pwm_get(&pdev->dev, NULL);
- if (IS_ERR(pb->pwm)) {
+ if (IS_ERR(pb->pwm) && !pdev->dev.of_node) {
dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n");
-
pb->pwm = pwm_request(data->pwm_id, "pwm-backlight");
- if (IS_ERR(pb->pwm)) {
- dev_err(&pdev->dev, "unable to request legacy PWM\n");
- ret = PTR_ERR(pb->pwm);
- goto err_alloc;
- }
+ }
+
+ if (IS_ERR(pb->pwm)) {
+ dev_err(&pdev->dev, "unable to request PWM\n");
+ ret = PTR_ERR(pb->pwm);
+ goto err_alloc;
}

dev_dbg(&pdev->dev, "got pwm for backlight\n");
--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-pwm" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Greg KH
2014-10-11 14:21:46 UTC
Permalink
Post by Vladimir Zapolskiy
Platform PWM backlight data provided by board's device tree should be
complete enough to successfully request a pwm device using pwm_get() API.
Based on initial implementation done by Dmitry Eremin-Solenikov.
---
drivers/video/backlight/pwm_bl.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read Documentation/stable_kernel_rules.txt
for how to do this properly.

</formletter>
--
To unsubscribe from this list: send the line "unsubscribe linux-pwm" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Vladimir Zapolskiy
2014-10-11 13:46:26 UTC
Permalink
If PWM device is requested by means of legacy API pwm_request(), its
resources are not freed on module unbind, which may cause an oops on
access, e.g. by reading /sys/kernel/debug/pwm.

Reported-by: Dmitry Eremin-Solenikov <***@mentor.com>
Signed-off-by: Vladimir Zapolskiy <***@mentor.com>
---
drivers/video/backlight/pwm_bl.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index dd7aaf7..40770dd 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -34,6 +34,7 @@ struct pwm_bl_data {
struct regulator *power_supply;
struct gpio_desc *enable_gpio;
unsigned int scale;
+ bool legacy;
int (*notify)(struct device *,
int brightness);
void (*notify_after)(struct device *,
@@ -274,6 +275,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
pb->pwm = devm_pwm_get(&pdev->dev, NULL);
if (IS_ERR(pb->pwm) && !pdev->dev.of_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");
}

@@ -339,6 +341,8 @@ static int pwm_backlight_remove(struct platform_device *pdev)

if (pb->exit)
pb->exit(&pdev->dev);
+ if (pb->legacy)
+ pwm_free(pb->pwm);

return 0;
}
--
1.7.10.4
Greg KH
2014-10-11 14:21:56 UTC
Permalink
Post by Vladimir Zapolskiy
If PWM device is requested by means of legacy API pwm_request(), its
resources are not freed on module unbind, which may cause an oops on
access, e.g. by reading /sys/kernel/debug/pwm.
---
drivers/video/backlight/pwm_bl.c | 4 ++++
1 file changed, 4 insertions(+)
<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read Documentation/stable_kernel_rules.txt
for how to do this properly.

</formletter>

Loading...