Commit 199fb21d authored by David Brownell's avatar David Brownell Committed by Richard Purdie

leds: bugfixes for leds-gpio

Three bugfixes to the leds-gpio driver, plus minor whitespace tweaks:

 - Do the INIT_WORK() before registering each LED, so if its trigger
   becomes immediately active it can schedule work without oopsing..

 - Use normal registration, not platform_driver_probe(), so that
   devices appearing "late" (hotplug type) can still be bound.

 - Mark the driver remove code as "__devexit", preventing oopses
   when the underlying device is removed.

These issues came up when using this driver with some GPIO expanders
living on serial busses, which act unlike "normal" platform devices:
they can appear and vanish along with the serial bus driver.
Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarRichard Purdie <rpurdie@rpsys.net>
parent c11eef21
...@@ -60,7 +60,7 @@ static void gpio_led_set(struct led_classdev *led_cdev, ...@@ -60,7 +60,7 @@ static void gpio_led_set(struct led_classdev *led_cdev,
gpio_set_value(led_dat->gpio, level); gpio_set_value(led_dat->gpio, level);
} }
static int __init gpio_led_probe(struct platform_device *pdev) static int gpio_led_probe(struct platform_device *pdev)
{ {
struct gpio_led_platform_data *pdata = pdev->dev.platform_data; struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
struct gpio_led *cur_led; struct gpio_led *cur_led;
...@@ -93,13 +93,13 @@ static int __init gpio_led_probe(struct platform_device *pdev) ...@@ -93,13 +93,13 @@ static int __init gpio_led_probe(struct platform_device *pdev)
gpio_direction_output(led_dat->gpio, led_dat->active_low); gpio_direction_output(led_dat->gpio, led_dat->active_low);
INIT_WORK(&led_dat->work, gpio_led_work);
ret = led_classdev_register(&pdev->dev, &led_dat->cdev); ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
if (ret < 0) { if (ret < 0) {
gpio_free(led_dat->gpio); gpio_free(led_dat->gpio);
goto err; goto err;
} }
INIT_WORK(&led_dat->work, gpio_led_work);
} }
platform_set_drvdata(pdev, leds_data); platform_set_drvdata(pdev, leds_data);
...@@ -110,17 +110,17 @@ err: ...@@ -110,17 +110,17 @@ err:
if (i > 0) { if (i > 0) {
for (i = i - 1; i >= 0; i--) { for (i = i - 1; i >= 0; i--) {
led_classdev_unregister(&leds_data[i].cdev); led_classdev_unregister(&leds_data[i].cdev);
cancel_work_sync(&leds_data[i].work);
gpio_free(leds_data[i].gpio); gpio_free(leds_data[i].gpio);
} }
} }
flush_scheduled_work();
kfree(leds_data); kfree(leds_data);
return ret; return ret;
} }
static int __exit gpio_led_remove(struct platform_device *pdev) static int __devexit gpio_led_remove(struct platform_device *pdev)
{ {
int i; int i;
struct gpio_led_platform_data *pdata = pdev->dev.platform_data; struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
...@@ -130,6 +130,7 @@ static int __exit gpio_led_remove(struct platform_device *pdev) ...@@ -130,6 +130,7 @@ static int __exit gpio_led_remove(struct platform_device *pdev)
for (i = 0; i < pdata->num_leds; i++) { for (i = 0; i < pdata->num_leds; i++) {
led_classdev_unregister(&leds_data[i].cdev); led_classdev_unregister(&leds_data[i].cdev);
cancel_work_sync(&leds_data[i].work);
gpio_free(leds_data[i].gpio); gpio_free(leds_data[i].gpio);
} }
...@@ -172,7 +173,8 @@ static int gpio_led_resume(struct platform_device *pdev) ...@@ -172,7 +173,8 @@ static int gpio_led_resume(struct platform_device *pdev)
#endif #endif
static struct platform_driver gpio_led_driver = { static struct platform_driver gpio_led_driver = {
.remove = __exit_p(gpio_led_remove), .probe = gpio_led_probe,
.remove = __devexit_p(gpio_led_remove),
.suspend = gpio_led_suspend, .suspend = gpio_led_suspend,
.resume = gpio_led_resume, .resume = gpio_led_resume,
.driver = { .driver = {
...@@ -183,7 +185,7 @@ static struct platform_driver gpio_led_driver = { ...@@ -183,7 +185,7 @@ static struct platform_driver gpio_led_driver = {
static int __init gpio_led_init(void) static int __init gpio_led_init(void)
{ {
return platform_driver_probe(&gpio_led_driver, gpio_led_probe); return platform_driver_register(&gpio_led_driver);
} }
static void __exit gpio_led_exit(void) static void __exit gpio_led_exit(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment