Skip to contentSkip to conversation

leds: ti-lmu-common: Fix coccinelle issue in TI LMU

PATCH Superseded Dan Murphy 2 participants 6 messages Aug 23, 2019 – Aug 27, 2019 LED

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Dan Murphy

author
#0 lore raw

PATCH 1/1 leds: ti-lmu-common: Fix coccinelle issue in TI LMU

Fix the coccinelle issues found in the TI LMU common code

drivers/leds/leds-ti-lmu-common.c:97:20-29: WARNING: Unsigned expression compared with zero: ramp_down < 0 drivers/leds/leds-ti-lmu-common.c:97:5-12: WARNING: Unsigned expression compared with zero: ramp_up < 0

Fixes f717460ba4d7 ("leds: TI LMU: Add common code for TI LMU devices")
---
 drivers/leds/leds-ti-lmu-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/leds/leds-ti-lmu-common.c +1 -1
index adc7293004f1..c9ab40d5a6ba 100644
@@ -84,7 +84,7 @@ static int ti_lmu_common_convert_ramp_to_index(unsigned int usec)
 int ti_lmu_common_set_ramp(struct ti_lmu_bank *lmu_bank)
 {
 	struct regmap *regmap = lmu_bank->regmap;
-	u8 ramp, ramp_up, ramp_down;
+	int ramp, ramp_up, ramp_down;
 
 	if (lmu_bank->ramp_up_usec == 0 && lmu_bank->ramp_down_usec == 0) {
 		ramp_up = 0;
Signature · 1 line
2.22.0.214.g8dca754b1e
#1 lore raw

Hi Dan,

Thank you for the patch.

Quoted 4 lines · Dan Murphy

Fix the coccinelle issues found in the TI LMU common code

drivers/leds/leds-ti-lmu-common.c:97:20-29: WARNING: Unsigned expression compared with zero: ramp_down < 0 drivers/leds/leds-ti-lmu-common.c:97:5-12: WARNING: Unsigned expression compared with zero: ramp_up < 0

Wouldn't it make more sense to remove those pointless checks? Clearly a correct index of an array cannot be negative. Looking at the code I would make more int -> unsigned int conversions:

- ramp_table should be unsigned int
- ti_lmu_common_convert_ramp_to_index should return unsigned int

Quoted 20 lines
Fixes f717460ba4d7 ("leds: TI LMU: Add common code for TI LMU devices")
---
 drivers/leds/leds-ti-lmu-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/leds/leds-ti-lmu-common.c +1 -1
index adc7293004f1..c9ab40d5a6ba 100644
@@ -84,7 +84,7 @@ static int ti_lmu_common_convert_ramp_to_index(unsigned int usec)
 int ti_lmu_common_set_ramp(struct ti_lmu_bank *lmu_bank)
 {
 	struct regmap *regmap = lmu_bank->regmap;
-	u8 ramp, ramp_up, ramp_down;
+	int ramp, ramp_up, ramp_down;
 
 	if (lmu_bank->ramp_up_usec == 0 && lmu_bank->ramp_down_usec == 0) {
 		ramp_up = 0;
Signature · 2 lines
Best regards,
Jacek Anaszewski
author
#2 lore raw

Jacek

Quoted 7 lines · Jacek Anaszewski

Hi Dan,

Thank you for the patch.

Quoted 2 lines · Dan Murphy

Fix the coccinelle issues found in the TI LMU common code

Quoted 9 lines
Quoted 2 lines

drivers/leds/leds-ti-lmu-common.c:97:20-29: WARNING: Unsigned expression compared with zero: ramp_down < 0 drivers/leds/leds-ti-lmu-common.c:97:5-12: WARNING: Unsigned expression compared with zero: ramp_up < 0

Wouldn't it make more sense to remove those pointless checks? Clearly a correct index of an array cannot be negative. Looking at the code I would make more int -> unsigned int conversions:

- ramp_table should be unsigned int
- ti_lmu_common_convert_ramp_to_index should return unsigned int

Yeah I was going to just remove the code but when I was writing the original code my intent was

to extend the ramp call to allow other TI LMU driver to pass in the device specific ramp table.

But since I don't currently have any devices on my plate that require that I can just remove the code as well

Dan

[...]

#3 lore raw

Dan,

Quoted 21 lines · Dan Murphy

Jacek

Quoted 11 lines · Jacek Anaszewski

Hi Dan,

Thank you for the patch.

Quoted 6 lines · Dan Murphy

Fix the coccinelle issues found in the TI LMU common code

drivers/leds/leds-ti-lmu-common.c:97:20-29: WARNING: Unsigned expression compared with zero: ramp_down < 0 drivers/leds/leds-ti-lmu-common.c:97:5-12: WARNING: Unsigned expression compared with zero: ramp_up < 0

Quoted 7 lines

Wouldn't it make more sense to remove those pointless checks? Clearly a correct index of an array cannot be negative. Looking at the code I would make more int -> unsigned int conversions:

- ramp_table should be unsigned int
- ti_lmu_common_convert_ramp_to_index should return unsigned int

Quoted 8 lines

Yeah I was going to just remove the code but when I was writing the original code my intent was

to extend the ramp call to allow other TI LMU driver to pass in the device specific ramp table.

But since I don't currently have any devices on my plate that require that I can just remove the code as well

You don't need to remove, just do the conversions I proposed. Unless it introduces some other problems I am currently not aware of.

Signature · 2 lines
Best regards,
Jacek Anaszewski
author
#4 lore raw

Jacek

Quoted 27 lines · Jacek Anaszewski

Dan,

Quoted 24 lines · Dan Murphy

Jacek

Quoted 11 lines · Jacek Anaszewski

Hi Dan,

Thank you for the patch.

Quoted 6 lines · Dan Murphy

Fix the coccinelle issues found in the TI LMU common code

drivers/leds/leds-ti-lmu-common.c:97:20-29: WARNING: Unsigned expression compared with zero: ramp_down < 0 drivers/leds/leds-ti-lmu-common.c:97:5-12: WARNING: Unsigned expression compared with zero: ramp_up < 0

Quoted 7 lines

Wouldn't it make more sense to remove those pointless checks? Clearly a correct index of an array cannot be negative. Looking at the code I would make more int -> unsigned int conversions:

- ramp_table should be unsigned int
- ti_lmu_common_convert_ramp_to_index should return unsigned int

Yeah I was going to just remove the code but when I was writing the original code my intent was

Quoted 8 lines
Quoted 5 lines

to extend the ramp call to allow other TI LMU driver to pass in the device specific ramp table.

But since I don't currently have any devices on my plate that require that I can just remove the code as well

You don't need to remove, just do the conversions I proposed. Unless it introduces some other problems I am currently not aware of.

Well just converting those two would/did not fix the issue.

But actually there is only 1 possibility that could happen if the convert function returns -EINVAL

So the check should be

if (ramp_up == -EINVAL || ramp_down == -EINVAL)

Because ramp_up/down should never be less then zero otherwise.

Dan

#5 lore raw

Dan,

Quoted 33 lines · Dan Murphy

Jacek

Quoted 30 lines · Jacek Anaszewski

Dan,

Quoted 27 lines · Dan Murphy

Jacek

Quoted 11 lines · Jacek Anaszewski

Hi Dan,

Thank you for the patch.

Quoted 6 lines · Dan Murphy

Fix the coccinelle issues found in the TI LMU common code

drivers/leds/leds-ti-lmu-common.c:97:20-29: WARNING: Unsigned expression compared with zero: ramp_down < 0 drivers/leds/leds-ti-lmu-common.c:97:5-12: WARNING: Unsigned expression compared with zero: ramp_up < 0

Quoted 7 lines

Wouldn't it make more sense to remove those pointless checks? Clearly a correct index of an array cannot be negative. Looking at the code I would make more int -> unsigned int conversions:

- ramp_table should be unsigned int
- ti_lmu_common_convert_ramp_to_index should return unsigned int

Yeah I was going to just remove the code but when I was writing the original code my intent was

to extend the ramp call to allow other TI LMU driver to pass in the device specific ramp table.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

But since I don't currently have any devices on my plate that require that I can just remove the code as well

You don't need to remove, just do the conversions I proposed. Unless it introduces some other problems I am currently not aware of.

Well just converting those two would/did not fix the issue.

I implicitly assumed that you'd just drop the check since it would make no sense to check unsigned int for being lower than 0.

And I propose to not return any error code from ti_lmu_common_convert_ramp_to_index(), just make sure inside it you return sane value. Ramp should, well, ramp.

Quoted 14 lines

But actually there is only 1 possibility that could happen if the convert function returns -EINVAL

So the check should be

if (ramp_up == -EINVAL || ramp_down == -EINVAL)

Because ramp_up/down should never be less then zero otherwise.

Dan

Signature · 2 lines
Best regards,
Jacek Anaszewski