[PATCH] backlight: pwm_bl: Fix uninitialized variable

From: Daniel Thompson
Date: Mon Jul 16 2018 - 17:03:21 EST


Currently, if the DT does not define num-interpolated-steps then
num_steps is undefined and the interpolation code will deploy randomly.
Fix this.

Fixes: 573fe6d1c25c ("backlight: pwm_bl: Linear interpolation between
brightness-levels")
Reported-by: Marcel Ziswiler <marcel.ziswiler@xxxxxxxxxxx>
Signed-off-by: Daniel Thompson <daniel.thompson@xxxxxxxxxx>
Signed-off-by: Marcel Ziswiler <marcel.ziswiler@xxxxxxxxxxx>
Tested-by: Marcel Ziswiler <marcel.ziswiler@xxxxxxxxxxx>
---
drivers/video/backlight/pwm_bl.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 9ee4c1b735b2..e3c22b79fbcd 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -299,15 +299,14 @@ static int pwm_backlight_parse_dt(struct device *dev,
* interpolation between each of the values of brightness levels
* and creates a new pre-computed table.
*/
- of_property_read_u32(node, "num-interpolated-steps",
- &num_steps);
-
- /*
- * Make sure that there is at least two entries in the
- * brightness-levels table, otherwise we can't interpolate
- * between two points.
- */
- if (num_steps) {
+ if ((of_property_read_u32(node, "num-interpolated-steps",
+ &num_steps) == 0) && num_steps) {
+ /*
+ * Make sure that there is at least two entries in the
+ * brightness-levels table, otherwise we can't
+ * interpolate
+ * between two points.
+ */
if (data->max_brightness < 2) {
dev_err(dev, "can't interpolate\n");
return -EINVAL;
--
2.17.1