Skip to contentSkip to conversation

pwm: lp3943: Fix an incorrect type in lp3943_pwm_parse_dt()

PATCH In review Jiapeng Chong 3 participants 3 messages Aug 9, 2024 – Aug 10, 2024 PWM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pwm: lp3943: Fix an incorrect type in lp3943_pwm_parse_dt()

The return value from the call to of_property_count_u32_elems() is int. However, the return value is being assigned to an u32 variable 'num_outputs', so making 'num_outputs' an int.

./drivers/pwm/pwm-lp3943.c:238:6-17: WARNING: Unsigned expression compared with zero: num_outputs <= 0.

---
 drivers/pwm/pwm-lp3943.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/pwm/pwm-lp3943.c +1 -2
index f0e94c9e5956..90b0733c00c1 100644
@@ -218,8 +218,7 @@ static int lp3943_pwm_parse_dt(struct device *dev,
 	struct lp3943_platform_data *pdata;
 	struct lp3943_pwm_map *pwm_map;
 	enum lp3943_pwm_output *output;
-	int i, err, count = 0;
-	u32 num_outputs;
+	int i, err, num_outputs, count = 0;
 
 	if (!node)
 		return -EINVAL;
Signature · 1 line
2.32.0.3.g01195cf9f
#1 lore raw

Hello Jiapeng,

Quoted 5 lines · Jiapeng Chong

The return value from the call to of_property_count_u32_elems() is int. However, the return value is being assigned to an u32 variable 'num_outputs', so making 'num_outputs' an int.

./drivers/pwm/pwm-lp3943.c:238:6-17: WARNING: Unsigned expression compared with zero: num_outputs <= 0.

Which tool does emit this warning? My test build (with C=1 and W=1) doesn't emit it.

Quoted 3 lines

This problem was introduced in a commit in next:

Fixes d6a56f3bb650 ("pwm: lp3943: Use of_property_count_u32_elems() to get property length")

Rob: I guess this wasn't the only conversion of this type. Maybe these others suffer from the same problem?!

Quoted 9 lines
---
  drivers/pwm/pwm-lp3943.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/pwm/pwm-lp3943.c +0 -0
index f0e94c9e5956..90b0733c00c1 100644

drivers/pwm/pwm-lp3943.c static int lp3943_pwm_parse_dt(struct device *dev, · line 224

Quoted 9 lines
drivers/pwm/pwm-lp3943.c +1 -2
@@ -218,8 +218,7 @@ static int lp3943_pwm_parse_dt(struct device *dev,
  	struct lp3943_platform_data *pdata;
  	struct lp3943_pwm_map *pwm_map;
  	enum lp3943_pwm_output *output;
-	int i, err, count = 0;
-	u32 num_outputs;
+	int i, err, num_outputs, count = 0;
 
  	if (!node)
  		return -EINVAL;

Nitpick (maybe even a subjective one):
While touching num_outputs, its scope could be reduced to the for loop.

Best regards
Uwe

#2 lore raw

Hello,

Quoted 14 lines · Uwe Kleine-König
Quoted 5 lines · Jiapeng Chong

The return value from the call to of_property_count_u32_elems() is int. However, the return value is being assigned to an u32 variable 'num_outputs', so making 'num_outputs' an int.

./drivers/pwm/pwm-lp3943.c:238:6-17: WARNING: Unsigned expression compared with zero: num_outputs <= 0.

Which tool does emit this warning? My test build (with C=1 and W=1) doesn't emit it.

Quoted 3 lines
Quoted 7 lines

This problem was introduced in a commit in next:

Fixes d6a56f3bb650 ("pwm: lp3943: Use of_property_count_u32_elems() to get

property length")

Rob: I guess this wasn't the only conversion of this type. Maybe these others suffer from the same problem?!

I hoped for some more feedback, but anyhow: Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-next

with the Fixes line.

Best regards
Uwe