LEDS: S3C24XX generate name if none given
Subsystems (2)
Generate a name if none is passed to the S3C24XX GPIO LED driver.
drivers/leds/leds-s3c24xx.c +10 -0
@@ -23,6 +23,8 @@/* our context */ struct s3c24xx_gpio_led { +char name[32 ]; +struct led_classdev cdev;struct s3c24xx_led_platdata *pdata; };
@@ -85,6 +87,14 @@ static int s3c24xx_led_probe(struct plat led->pdata = pdata; +/* create name if we where not passed one */ + +if (led->cdev.name ==NULL ) { +snprintf (led->name,sizeof (led->name),"%s.%d" , + dev->name, dev->id); + led->cdev.name = led->name; + } +/* no point in having a pull-up if we are always driving */ if (pdata->flags &S3C24XX_LEDF_TRISTATE ) {
Quoted 17 lines · Ben Dooks
Generate a name if none is passed to the S3C24XX GPIO LED driver.
Signed-off-by Ben Dooks <[email protected]>diff -urpN -X ../dontdiff
linux-2.6.19/drivers/leds/leds-s3c24xx.clinux-2.6.19-simtec1p22/drivers/leds/leds-s3c24xx.cdrivers/leds/leds-s3c24xx.c +2
-0@@ -23,6 +23,8 @@/* our context */ struct s3c24xx_gpio_led { +char name[32 ]; +struct led_classdev cdev;struct s3c24xx_led_platdata *pdata; };
drivers/leds/leds-s3c24xx.c static int s3c24xx_led_probe(struct plat · line 90
Quoted 4 lines
drivers/leds/leds-s3c24xx.c +1
-0@@ -85,6 +87,14 @@ static int s3c24xx_led_probe(struct plat led->pdata = pdata; +/* create name if we where not passed one */
^^^^^ "were"
rday
Quoted 8 lines · Ben Dooks
Generate a name if none is passed to the S3C24XX GPIO LED driver.
Signed-off-by Ben Dooks <[email protected]>diff -urpN -X ../dontdiff
linux-2.6.19/drivers/leds/leds-s3c24xx.clinux-2.6.19-simtec1p22/drivers/leds/leds-s3c24xx.c
drivers/leds/leds-s3c24xx.c line 28
Quoted 6 lines
drivers/leds/leds-s3c24xx.c +2
-0@@ -23,6 +23,8 @@/* our context */ struct s3c24xx_gpio_led { +char name[32 ]; +struct led_classdev cdev;
I'm not that keen on this since it wastes 32 bytes per LED when the platform code does declare the names. If you're happy with that, its up to you as the platform maintainer I guess but is there no nicer way to handle this? I'm mainly concerned about people copying this code into other drivers as then they'll all end up doing it...
Richard
Quoted 11 lines · Richard Purdie
Quoted 10 lines · Ben Dooks
Generate a name if none is passed to the S3C24XX GPIO LED driver.
Signed-off-by Ben Dooks <[email protected]>diff -urpN -X ../dontdiff
linux-2.6.19/drivers/leds/leds-s3c24xx.clinux-2.6.19-simtec1p22/drivers/leds/leds-s3c24xx.cdrivers/leds/leds-s3c24xx.c +0
-0@@ -23,6 +23,8 @@/* our context */
Quoted 10 lines
drivers/leds/leds-s3c24xx.c line 28
Quoted 4 lines
drivers/leds/leds-s3c24xx.c +2
-0struct s3c24xx_gpio_led { +char name[32 ]; +struct led_classdev cdev;I'm not that keen on this since it wastes 32 bytes per LED when the platform code does declare the names. If you're happy with that, its up to you as the platform maintainer I guess but is there no nicer way to handle this? I'm mainly concerned about people copying this code into other drivers as then they'll all end up doing it...
Ok, how about using kstrdup() on the name, like this:
drivers/leds/leds-s3c24xx.c +12 -0
@@ -59,6 +59,9 @@ static int s3c24xx_led_remove(struct pla {struct s3c24xx_gpio_led *led =pdev_to_gpio (dev); +if (led->cdev.name != led->pdata.name) +kfree (led->cdev.name); +led_classdev_unregister (&led->cdev);kfree (led);
@@ -85,6 +88,15 @@ static int s3c24xx_led_probe(struct plat led->pdata = pdata; +/* create name if we were not passed one */ + +if (led->cdev.name ==NULL ) { +char name[64 ]; + +snprintf (name,sizeof (name),"%s.%d" , dev->name, dev->id); + led->cdev.name =kstrdup (name); + } +/* no point in having a pull-up if we are always driving */ if (pdata->flags &S3C24XX_LEDF_TRISTATE ) {
Signature · 4 lines
Ben Q: What's a light-year? A: One-third less calories than a regular year.
Richard Purdie
Acked-byQuoted 8 lines · Ben Dooks
Quoted 5 lines · Richard Purdie
Quoted 4 lines · Ben Dooks
Generate a name if none is passed to the S3C24XX GPIO LED driver.
Signed-off-by Ben Dooks <[email protected]>Ok, how about using
kstrdup()on the name, like this:
Much better, thanks.
Creating a git tree to handle the LED patches properly is on my todo list...
Quoted 31 lines
diff -urpN -X ../dontdiff
linux-2.6.19/drivers/leds/leds-s3c24xx.clinux-2.6.19-simtec1p22/drivers/leds/leds-s3c24xx.cdrivers/leds/leds-s3c24xx.c +12
-0@@ -59,6 +59,9 @@ static int s3c24xx_led_remove(struct pla {struct s3c24xx_gpio_led *led =pdev_to_gpio (dev); +if (led->cdev.name != led->pdata.name) +kfree (led->cdev.name); +led_classdev_unregister (&led->cdev);kfree (led);@@ -85,6 +88,15 @@ static int s3c24xx_led_probe(struct plat led->pdata = pdata; +/* create name if we were not passed one */ + +if (led->cdev.name ==NULL ) { +char name[64 ]; + +snprintf (name,sizeof (name),"%s.%d" , dev->name, dev->id); + led->cdev.name =kstrdup (name); + } +/* no point in having a pull-up if we are always driving */ if (pdata->flags &S3C24XX_LEDF_TRISTATE ) {
Quoted 4 lines · On Mon, 15 Jan 2007 15:42:21 +0000 Ben Dooks <[email protected]> wrote:
Quoted 2 lines · Richard Purdie
Quoted 1 line · Ben Dooks
Generate a name if none is passed to the S3C24XX GPIO LED driver.
Wouldn't it be better to fix the callers to consistently pass in a name rather than hacking around fixing stuff up in the callee?
drivers/leds/leds-s3c24xx.c static int s3c24xx_led_probe(struct plat · line 99
Quoted 9 lines
drivers/leds/leds-s3c24xx.c +9
-0+/* create name if we were not passed one */ + +if (led->cdev.name ==NULL ) { +char name[64 ]; + +snprintf (name,sizeof (name),"%s.%d" , dev->name, dev->id); + led->cdev.name =kstrdup (name); + } +
Take a peek at kasprintf() ;)
Please include full-and-fresh changelog in each iteration of a patch, so poor patch-takers don't have to go making one up for you, thanks.