[PATCH] drivers/led: handle sysfs errors
Signed-off-by: Jeff Garzik <jeff@garzik.org> Cc: Richard Purdie <rpurdie@rpsys.net> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
58ff407bee
commit
12fda16814
|
@ -91,6 +91,8 @@ EXPORT_SYMBOL_GPL(led_classdev_resume);
|
||||||
*/
|
*/
|
||||||
int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
|
int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
|
||||||
{
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
led_cdev->class_dev = class_device_create(leds_class, NULL, 0,
|
led_cdev->class_dev = class_device_create(leds_class, NULL, 0,
|
||||||
parent, "%s", led_cdev->name);
|
parent, "%s", led_cdev->name);
|
||||||
if (unlikely(IS_ERR(led_cdev->class_dev)))
|
if (unlikely(IS_ERR(led_cdev->class_dev)))
|
||||||
|
@ -99,8 +101,10 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
|
||||||
class_set_devdata(led_cdev->class_dev, led_cdev);
|
class_set_devdata(led_cdev->class_dev, led_cdev);
|
||||||
|
|
||||||
/* register the attributes */
|
/* register the attributes */
|
||||||
class_device_create_file(led_cdev->class_dev,
|
rc = class_device_create_file(led_cdev->class_dev,
|
||||||
&class_device_attr_brightness);
|
&class_device_attr_brightness);
|
||||||
|
if (rc)
|
||||||
|
goto err_out;
|
||||||
|
|
||||||
/* add to the list of leds */
|
/* add to the list of leds */
|
||||||
write_lock(&leds_list_lock);
|
write_lock(&leds_list_lock);
|
||||||
|
@ -110,16 +114,28 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
|
||||||
#ifdef CONFIG_LEDS_TRIGGERS
|
#ifdef CONFIG_LEDS_TRIGGERS
|
||||||
rwlock_init(&led_cdev->trigger_lock);
|
rwlock_init(&led_cdev->trigger_lock);
|
||||||
|
|
||||||
led_trigger_set_default(led_cdev);
|
rc = class_device_create_file(led_cdev->class_dev,
|
||||||
|
|
||||||
class_device_create_file(led_cdev->class_dev,
|
|
||||||
&class_device_attr_trigger);
|
&class_device_attr_trigger);
|
||||||
|
if (rc)
|
||||||
|
goto err_out_led_list;
|
||||||
|
|
||||||
|
led_trigger_set_default(led_cdev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printk(KERN_INFO "Registered led device: %s\n",
|
printk(KERN_INFO "Registered led device: %s\n",
|
||||||
led_cdev->class_dev->class_id);
|
led_cdev->class_dev->class_id);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
#ifdef CONFIG_LEDS_TRIGGERS
|
||||||
|
err_out_led_list:
|
||||||
|
class_device_remove_file(led_cdev->class_dev,
|
||||||
|
&class_device_attr_brightness);
|
||||||
|
list_del(&led_cdev->node);
|
||||||
|
#endif
|
||||||
|
err_out:
|
||||||
|
class_device_unregister(led_cdev->class_dev);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(led_classdev_register);
|
EXPORT_SYMBOL_GPL(led_classdev_register);
|
||||||
|
|
||||||
|
|
|
@ -123,6 +123,7 @@ static CLASS_DEVICE_ATTR(delay_off, 0644, led_delay_off_show,
|
||||||
static void timer_trig_activate(struct led_classdev *led_cdev)
|
static void timer_trig_activate(struct led_classdev *led_cdev)
|
||||||
{
|
{
|
||||||
struct timer_trig_data *timer_data;
|
struct timer_trig_data *timer_data;
|
||||||
|
int rc;
|
||||||
|
|
||||||
timer_data = kzalloc(sizeof(struct timer_trig_data), GFP_KERNEL);
|
timer_data = kzalloc(sizeof(struct timer_trig_data), GFP_KERNEL);
|
||||||
if (!timer_data)
|
if (!timer_data)
|
||||||
|
@ -134,10 +135,21 @@ static void timer_trig_activate(struct led_classdev *led_cdev)
|
||||||
timer_data->timer.function = led_timer_function;
|
timer_data->timer.function = led_timer_function;
|
||||||
timer_data->timer.data = (unsigned long) led_cdev;
|
timer_data->timer.data = (unsigned long) led_cdev;
|
||||||
|
|
||||||
class_device_create_file(led_cdev->class_dev,
|
rc = class_device_create_file(led_cdev->class_dev,
|
||||||
&class_device_attr_delay_on);
|
&class_device_attr_delay_on);
|
||||||
class_device_create_file(led_cdev->class_dev,
|
if (rc) goto err_out;
|
||||||
|
rc = class_device_create_file(led_cdev->class_dev,
|
||||||
&class_device_attr_delay_off);
|
&class_device_attr_delay_off);
|
||||||
|
if (rc) goto err_out_delayon;
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
err_out_delayon:
|
||||||
|
class_device_remove_file(led_cdev->class_dev,
|
||||||
|
&class_device_attr_delay_on);
|
||||||
|
err_out:
|
||||||
|
led_cdev->trigger_data = NULL;
|
||||||
|
kfree(timer_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void timer_trig_deactivate(struct led_classdev *led_cdev)
|
static void timer_trig_deactivate(struct led_classdev *led_cdev)
|
||||||
|
|
Loading…
Reference in New Issue