Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit edf387b6 authored by Vladimir Zapolskiy's avatar Vladimir Zapolskiy Committed by Lee Jones
Browse files

backlight: pwm: Clean-up pwm requested using legacy API



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: default avatarDmitry Eremin-Solenikov <dmitry_eremin@mentor.com>
Signed-off-by: default avatarVladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
parent 0df1f248
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@ struct pwm_bl_data {
	struct regulator	*power_supply;
	struct regulator	*power_supply;
	struct gpio_desc	*enable_gpio;
	struct gpio_desc	*enable_gpio;
	unsigned int		scale;
	unsigned int		scale;
	bool			legacy;
	int			(*notify)(struct device *,
	int			(*notify)(struct device *,
					  int brightness);
					  int brightness);
	void			(*notify_after)(struct device *,
	void			(*notify_after)(struct device *,
@@ -274,7 +275,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
	pb->pwm = devm_pwm_get(&pdev->dev, NULL);
	pb->pwm = devm_pwm_get(&pdev->dev, NULL);
	if (IS_ERR(pb->pwm)) {
	if (IS_ERR(pb->pwm)) {
		dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n");
		dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n");

		pb->legacy = true;
		pb->pwm = pwm_request(data->pwm_id, "pwm-backlight");
		pb->pwm = pwm_request(data->pwm_id, "pwm-backlight");
		if (IS_ERR(pb->pwm)) {
		if (IS_ERR(pb->pwm)) {
			dev_err(&pdev->dev, "unable to request legacy PWM\n");
			dev_err(&pdev->dev, "unable to request legacy PWM\n");
@@ -339,6 +340,8 @@ static int pwm_backlight_remove(struct platform_device *pdev)


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


	return 0;
	return 0;
}
}