bug in lp3944_led_set_brightness()
Hi Antonio,
I was going through some Sparse warnings and this one seems pretty valid.
drivers/leds/leds-lp3944.c +292 23:
warning: mixing different enum types
284 static void lp3944_led_set_brightness(struct led_classdev *led_cdev,
285 enum led_brightness brightness)
286 {
287 struct lp3944_led_data *led = ldev_to_led(led_cdev);
288
289 dev_dbg(&led->client->dev, "%s: %s, %d\n",
290 __func__, led_cdev->name, brightness);
291
292 led->status = brightness;
^^^^^^^^^^^^^^^^^^^^^^^^
293 schedule_work(&led->work);
294 }led->status should be values between 0-3. brightness is 0, 127 and 255.
regards,
dan carpenter
Quoted 22 lines · On Wed, 5 Oct 2011 12:32:48 +0300 Dan Carpenter <[email protected]>…
Hi Antonio,
I was going through some Sparse warnings and this one seems pretty valid.
drivers/leds/leds-lp3944.c+292 23:
warning: mixing different enum types284 static void lp3944_led_set_brightness(struct led_classdev *led_cdev, 285 enum led_brightness brightness) 286 { 287 struct lp3944_led_data *led = ldev_to_led(led_cdev); 288 289 dev_dbg(&led->client->dev, "%s: %s, %d\n", 290 __func__, led_cdev->name, brightness); 291 292 led->status = brightness; ^^^^^^^^^^^^^^^^^^^^^^^^ 293 schedule_work(&led->work); 294 }
Quoted 3 lines
led->statusshould be values between 0-3. brightness is 0, 127 and 255.
Hi Dan, thanks for reporting that.
AFAICS this is not a problem _in_practice_ as lp3944_led_set_brightness () is called by the leds framework with brightness values already limited by max_brightness, so it is always 0 or 1 in our case. The sparse warning is not pretty tho, so I guess we can safely get rid of it anyways with:
led->status = !!brightness;
keeping track of LP3944_LED_STATUS_OFF and LP3944_LED_STATUS_ON only in lp3944_led_set_brightness() is OK, as the handling of DIM (blinking) mode[s] is in lp3944_led_set_blink().
I am following up with a patch in that direction tomorrow, after a test on the actual hardware.
This is the rationale behind the current code if it is of any interest:
in the development phase of the driver I was abusing brightness = {2,3} to trigger the hardware blinking function, but then I set the max_brightness to 1 and so this abusing mechanism became inactive and I must have forgotten about it.
Thanks again.
Regards,
Antonio
Signature · 8 lines
Antonio Ospite http://ao2.it PGP public key ID: 0x4553B001 A: Because it messes up the order in which people normally read text. See http://en.wikipedia.org/wiki/Posting_style Q: Why is top-posting such a bad thing?
PATCH 1/1 leds: leds-lp3944, fix "sparse" warning "mixing different enum types"
Fix a warning from "sparse":
drivers/leds/leds-lp3944.c:292:23: warning: mixing different enum typesdrivers/leds/leds-lp3944.c:292:23: int enum led_brightness versusdrivers/leds/leds-lp3944.c:292:23: int enum lp3944_status
Keeping track of LP3944_LED_STATUS_OFF and LP3944_LED_STATUS_ON only in lp3944_led_set_brightness() is OK, as the handling of DIM (blinking) mode[s] is in lp3944_led_set_blink().
--- drivers/leds/leds-lp3944.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/leds/leds-lp3944.c +1 -1
@@ -289,7 +289,7 @@ static void lp3944_led_set_brightness(struct led_classdev *led_cdev,dev_dbg (&led->client->dev,"%s: %s, %d\n" , __func__, led_cdev->name, brightness); - led->status = brightness; + led->status = !!brightness;schedule_work (&led->work); }
Signature · 1 line
1.7.6.3
Re: [PATCH] leds: leds-lp3944, fix "sparse" warning "mixing different enum types"
Quoted 6 lines · On Thu, 6 Oct 2011 23:34:44 +0200 Antonio Ospite <[email protected]>…
Fix a warning from "sparse":
drivers/leds/leds-lp3944.c:292:23: warning: mixing different enum typesdrivers/leds/leds-lp3944.c:292:23: int enumled_brightnessversusdrivers/leds/leds-lp3944.c:292:23: int enumlp3944_status
Quoted 6 lines
Keeping track of
LP3944_LED_STATUS_OFFandLP3944_LED_STATUS_ONonly inlp3944_led_set_brightness()is OK, as the handling of DIM (blinking) mode[s] is inlp3944_led_set_blink().Reported-by Dan Carpenter <[email protected]>Signed-off-by Antonio Ospite <[email protected]>
Ping.
Dan, did you receive this one? I can't see it in 3.2-rc2.
Regards,
Antonio.
Quoted 21 lines
--- drivers/leds/leds-lp3944.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/leds/leds-lp3944.c +1
-1@@ -289,7 +289,7 @@ static void lp3944_led_set_brightness(struct led_classdev *led_cdev,dev_dbg (&led->client->dev,"%s: %s, %d\n" , __func__, led_cdev->name, brightness); - led->status = brightness; + led->status = !!brightness;schedule_work (&led->work); }Signature · 1 line
1.7.6.3
Signature · 8 lines
Antonio Ospite http://ao2.it PGP public key ID: 0x4553B001 A: Because it messes up the order in which people normally read text. See http://en.wikipedia.org/wiki/Posting_style Q: Why is top-posting such a bad thing?
Re: [PATCH] leds: leds-lp3944, fix "sparse" warning "mixing different enum types"
Quoted 13 lines · Antonio Ospite
Quoted 10 lines · On Thu, 6 Oct 2011 23:34:44 +0200 Antonio Ospite <[email protected]>…
Fix a warning from "sparse":
drivers/leds/leds-lp3944.c:292:23: warning: mixing different enum typesdrivers/leds/leds-lp3944.c:292:23: int enumled_brightnessversusdrivers/leds/leds-lp3944.c:292:23: int enumlp3944_statusKeeping track of
LP3944_LED_STATUS_OFFandLP3944_LED_STATUS_ONonly inlp3944_led_set_brightness()is OK, as the handling of DIM (blinking) mode[s] is inlp3944_led_set_blink().
Quoted 5 lines
Quoted 2 lines
Reported-by Dan Carpenter <[email protected]>Signed-off-by Antonio Ospite <[email protected]>Ping.
Dan, did you receive this one? I can't see it in 3.2-rc2.
Richard is the maintainer, not me. But he's on the CC list as well so hopefully he can answer your question.
regards,
dan carpenter