HID: thingm: switch to managed version of led_classdev_register
Simplify the code by switching to the managed version of led_classdev_register. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
This commit is contained in:
parent
3de68ce92b
commit
c46fab2870
|
@ -159,7 +159,8 @@ static int thingm_init_rgb(struct thingm_rgb *rgb)
|
||||||
rgb->red.ldev.brightness_set_blocking = thingm_led_set;
|
rgb->red.ldev.brightness_set_blocking = thingm_led_set;
|
||||||
rgb->red.rgb = rgb;
|
rgb->red.rgb = rgb;
|
||||||
|
|
||||||
err = led_classdev_register(&rgb->tdev->hdev->dev, &rgb->red.ldev);
|
err = devm_led_classdev_register(&rgb->tdev->hdev->dev,
|
||||||
|
&rgb->red.ldev);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -171,9 +172,10 @@ static int thingm_init_rgb(struct thingm_rgb *rgb)
|
||||||
rgb->green.ldev.brightness_set_blocking = thingm_led_set;
|
rgb->green.ldev.brightness_set_blocking = thingm_led_set;
|
||||||
rgb->green.rgb = rgb;
|
rgb->green.rgb = rgb;
|
||||||
|
|
||||||
err = led_classdev_register(&rgb->tdev->hdev->dev, &rgb->green.ldev);
|
err = devm_led_classdev_register(&rgb->tdev->hdev->dev,
|
||||||
|
&rgb->green.ldev);
|
||||||
if (err)
|
if (err)
|
||||||
goto unregister_red;
|
return err;
|
||||||
|
|
||||||
/* Register the blue diode */
|
/* Register the blue diode */
|
||||||
snprintf(rgb->blue.name, sizeof(rgb->blue.name),
|
snprintf(rgb->blue.name, sizeof(rgb->blue.name),
|
||||||
|
@ -183,28 +185,11 @@ static int thingm_init_rgb(struct thingm_rgb *rgb)
|
||||||
rgb->blue.ldev.brightness_set_blocking = thingm_led_set;
|
rgb->blue.ldev.brightness_set_blocking = thingm_led_set;
|
||||||
rgb->blue.rgb = rgb;
|
rgb->blue.rgb = rgb;
|
||||||
|
|
||||||
err = led_classdev_register(&rgb->tdev->hdev->dev, &rgb->blue.ldev);
|
err = devm_led_classdev_register(&rgb->tdev->hdev->dev,
|
||||||
if (err)
|
&rgb->blue.ldev);
|
||||||
goto unregister_green;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
unregister_green:
|
|
||||||
led_classdev_unregister(&rgb->green.ldev);
|
|
||||||
|
|
||||||
unregister_red:
|
|
||||||
led_classdev_unregister(&rgb->red.ldev);
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void thingm_remove_rgb(struct thingm_rgb *rgb)
|
|
||||||
{
|
|
||||||
led_classdev_unregister(&rgb->red.ldev);
|
|
||||||
led_classdev_unregister(&rgb->green.ldev);
|
|
||||||
led_classdev_unregister(&rgb->blue.ldev);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int thingm_probe(struct hid_device *hdev, const struct hid_device_id *id)
|
static int thingm_probe(struct hid_device *hdev, const struct hid_device_id *id)
|
||||||
{
|
{
|
||||||
struct thingm_device *tdev;
|
struct thingm_device *tdev;
|
||||||
|
@ -259,11 +244,8 @@ static int thingm_probe(struct hid_device *hdev, const struct hid_device_id *id)
|
||||||
rgb->tdev = tdev;
|
rgb->tdev = tdev;
|
||||||
rgb->num = tdev->fwinfo->first + i;
|
rgb->num = tdev->fwinfo->first + i;
|
||||||
err = thingm_init_rgb(rgb);
|
err = thingm_init_rgb(rgb);
|
||||||
if (err) {
|
if (err)
|
||||||
while (--i >= 0)
|
|
||||||
thingm_remove_rgb(tdev->rgb + i);
|
|
||||||
goto stop;
|
goto stop;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -273,17 +255,6 @@ error:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void thingm_remove(struct hid_device *hdev)
|
|
||||||
{
|
|
||||||
struct thingm_device *tdev = hid_get_drvdata(hdev);
|
|
||||||
int i;
|
|
||||||
|
|
||||||
hid_hw_stop(hdev);
|
|
||||||
|
|
||||||
for (i = 0; i < tdev->fwinfo->numrgb; ++i)
|
|
||||||
thingm_remove_rgb(tdev->rgb + i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct hid_device_id thingm_table[] = {
|
static const struct hid_device_id thingm_table[] = {
|
||||||
{ HID_USB_DEVICE(USB_VENDOR_ID_THINGM, USB_DEVICE_ID_BLINK1) },
|
{ HID_USB_DEVICE(USB_VENDOR_ID_THINGM, USB_DEVICE_ID_BLINK1) },
|
||||||
{ }
|
{ }
|
||||||
|
@ -293,7 +264,6 @@ MODULE_DEVICE_TABLE(hid, thingm_table);
|
||||||
static struct hid_driver thingm_driver = {
|
static struct hid_driver thingm_driver = {
|
||||||
.name = "thingm",
|
.name = "thingm",
|
||||||
.probe = thingm_probe,
|
.probe = thingm_probe,
|
||||||
.remove = thingm_remove,
|
|
||||||
.id_table = thingm_table,
|
.id_table = thingm_table,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue