Skip to content

Commit c46fab2

Browse files
hkallweitJiri Kosina
authored andcommitted
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 <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 3de68ce commit c46fab2

File tree

1 file changed

+8
-38
lines changed

1 file changed

+8
-38
lines changed

drivers/hid/hid-thingm.c

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ static int thingm_init_rgb(struct thingm_rgb *rgb)
159159
rgb->red.ldev.brightness_set_blocking = thingm_led_set;
160160
rgb->red.rgb = rgb;
161161

162-
err = led_classdev_register(&rgb->tdev->hdev->dev, &rgb->red.ldev);
162+
err = devm_led_classdev_register(&rgb->tdev->hdev->dev,
163+
&rgb->red.ldev);
163164
if (err)
164165
return err;
165166

@@ -171,9 +172,10 @@ static int thingm_init_rgb(struct thingm_rgb *rgb)
171172
rgb->green.ldev.brightness_set_blocking = thingm_led_set;
172173
rgb->green.rgb = rgb;
173174

174-
err = led_classdev_register(&rgb->tdev->hdev->dev, &rgb->green.ldev);
175+
err = devm_led_classdev_register(&rgb->tdev->hdev->dev,
176+
&rgb->green.ldev);
175177
if (err)
176-
goto unregister_red;
178+
return err;
177179

178180
/* Register the blue diode */
179181
snprintf(rgb->blue.name, sizeof(rgb->blue.name),
@@ -183,28 +185,11 @@ static int thingm_init_rgb(struct thingm_rgb *rgb)
183185
rgb->blue.ldev.brightness_set_blocking = thingm_led_set;
184186
rgb->blue.rgb = rgb;
185187

186-
err = led_classdev_register(&rgb->tdev->hdev->dev, &rgb->blue.ldev);
187-
if (err)
188-
goto unregister_green;
189-
190-
return 0;
191-
192-
unregister_green:
193-
led_classdev_unregister(&rgb->green.ldev);
194-
195-
unregister_red:
196-
led_classdev_unregister(&rgb->red.ldev);
197-
188+
err = devm_led_classdev_register(&rgb->tdev->hdev->dev,
189+
&rgb->blue.ldev);
198190
return err;
199191
}
200192

201-
static void thingm_remove_rgb(struct thingm_rgb *rgb)
202-
{
203-
led_classdev_unregister(&rgb->red.ldev);
204-
led_classdev_unregister(&rgb->green.ldev);
205-
led_classdev_unregister(&rgb->blue.ldev);
206-
}
207-
208193
static int thingm_probe(struct hid_device *hdev, const struct hid_device_id *id)
209194
{
210195
struct thingm_device *tdev;
@@ -259,11 +244,8 @@ static int thingm_probe(struct hid_device *hdev, const struct hid_device_id *id)
259244
rgb->tdev = tdev;
260245
rgb->num = tdev->fwinfo->first + i;
261246
err = thingm_init_rgb(rgb);
262-
if (err) {
263-
while (--i >= 0)
264-
thingm_remove_rgb(tdev->rgb + i);
247+
if (err)
265248
goto stop;
266-
}
267249
}
268250

269251
return 0;
@@ -273,17 +255,6 @@ static int thingm_probe(struct hid_device *hdev, const struct hid_device_id *id)
273255
return err;
274256
}
275257

276-
static void thingm_remove(struct hid_device *hdev)
277-
{
278-
struct thingm_device *tdev = hid_get_drvdata(hdev);
279-
int i;
280-
281-
hid_hw_stop(hdev);
282-
283-
for (i = 0; i < tdev->fwinfo->numrgb; ++i)
284-
thingm_remove_rgb(tdev->rgb + i);
285-
}
286-
287258
static const struct hid_device_id thingm_table[] = {
288259
{ HID_USB_DEVICE(USB_VENDOR_ID_THINGM, USB_DEVICE_ID_BLINK1) },
289260
{ }
@@ -293,7 +264,6 @@ MODULE_DEVICE_TABLE(hid, thingm_table);
293264
static struct hid_driver thingm_driver = {
294265
.name = "thingm",
295266
.probe = thingm_probe,
296-
.remove = thingm_remove,
297267
.id_table = thingm_table,
298268
};
299269

0 commit comments

Comments
 (0)