Commit 87770780 authored by Philipp Zabel's avatar Philipp Zabel Committed by Lee Jones

backlight: pwm_bl: Fix broken PWM backlight for non-dt platforms

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: default avatarRobert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Acked-by: default avatarThierry Reding <thierry.reding@gmail.com>
Tested-by: default avatarRobert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
parent fcf13f0b
...@@ -198,8 +198,8 @@ static int pwm_backlight_probe(struct platform_device *pdev) ...@@ -198,8 +198,8 @@ static int pwm_backlight_probe(struct platform_device *pdev)
struct platform_pwm_backlight_data defdata; struct platform_pwm_backlight_data defdata;
struct backlight_properties props; struct backlight_properties props;
struct backlight_device *bl; struct backlight_device *bl;
struct device_node *node = pdev->dev.of_node;
struct pwm_bl_data *pb; struct pwm_bl_data *pb;
phandle phandle = pdev->dev.of_node->phandle;
int initial_blank = FB_BLANK_UNBLANK; int initial_blank = FB_BLANK_UNBLANK;
int ret; int ret;
...@@ -273,7 +273,7 @@ static int pwm_backlight_probe(struct platform_device *pdev) ...@@ -273,7 +273,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
* assume that another driver will enable the backlight at the * assume that another driver will enable the backlight at the
* appropriate time. Therefore, if it is disabled, keep it so. * 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_direction(pb->enable_gpio) == GPIOF_DIR_OUT &&
gpiod_get_value(pb->enable_gpio) == 0) gpiod_get_value(pb->enable_gpio) == 0)
initial_blank = FB_BLANK_POWERDOWN; initial_blank = FB_BLANK_POWERDOWN;
...@@ -287,12 +287,11 @@ static int pwm_backlight_probe(struct platform_device *pdev) ...@@ -287,12 +287,11 @@ static int pwm_backlight_probe(struct platform_device *pdev)
goto err_alloc; 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; initial_blank = FB_BLANK_POWERDOWN;
pb->pwm = devm_pwm_get(&pdev->dev, NULL); pb->pwm = devm_pwm_get(&pdev->dev, NULL);
if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER && !node) {
&& !pdev->dev.of_node) {
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->legacy = true;
pb->pwm = pwm_request(data->pwm_id, "pwm-backlight"); pb->pwm = pwm_request(data->pwm_id, "pwm-backlight");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment