Skip to content

Commit d950db3

Browse files
committed
HID: google: switch to devm when registering keyboard backlight LED
We can use devm to register keyboard backlight LED on hammer devices, this will allow us to use HID's driver data for something else later. Link: https://lore.kernel.org/r/20220228075446.466016-2-dmitry.torokhov@gmail.com Tested-by: Stephen Boyd <swboyd@chromium.org> # coachz, wormdingler Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent ce83563 commit d950db3

1 file changed

Lines changed: 13 additions & 25 deletions

File tree

drivers/hid/hid-google-hammer.c

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@ static int hammer_kbd_brightness_set_blocking(struct led_classdev *cdev,
340340
static int hammer_register_leds(struct hid_device *hdev)
341341
{
342342
struct hammer_kbd_leds *kbd_backlight;
343-
int error;
344343

345-
kbd_backlight = kzalloc(sizeof(*kbd_backlight), GFP_KERNEL);
344+
kbd_backlight = devm_kzalloc(&hdev->dev, sizeof(*kbd_backlight),
345+
GFP_KERNEL);
346346
if (!kbd_backlight)
347347
return -ENOMEM;
348348

@@ -356,26 +356,7 @@ static int hammer_register_leds(struct hid_device *hdev)
356356
/* Set backlight to 0% initially. */
357357
hammer_kbd_brightness_set_blocking(&kbd_backlight->cdev, 0);
358358

359-
error = led_classdev_register(&hdev->dev, &kbd_backlight->cdev);
360-
if (error)
361-
goto err_free_mem;
362-
363-
hid_set_drvdata(hdev, kbd_backlight);
364-
return 0;
365-
366-
err_free_mem:
367-
kfree(kbd_backlight);
368-
return error;
369-
}
370-
371-
static void hammer_unregister_leds(struct hid_device *hdev)
372-
{
373-
struct hammer_kbd_leds *kbd_backlight = hid_get_drvdata(hdev);
374-
375-
if (kbd_backlight) {
376-
led_classdev_unregister(&kbd_backlight->cdev);
377-
kfree(kbd_backlight);
378-
}
359+
return devm_led_classdev_register(&hdev->dev, &kbd_backlight->cdev);
379360
}
380361

381362
#define HID_UP_GOOGLEVENDOR 0xffd10000
@@ -512,6 +493,11 @@ static void hammer_get_folded_state(struct hid_device *hdev)
512493
kfree(buf);
513494
}
514495

496+
static void hammer_stop(void *hdev)
497+
{
498+
hid_hw_stop(hdev);
499+
}
500+
515501
static int hammer_probe(struct hid_device *hdev,
516502
const struct hid_device_id *id)
517503
{
@@ -525,6 +511,10 @@ static int hammer_probe(struct hid_device *hdev,
525511
if (error)
526512
return error;
527513

514+
error = devm_add_action(&hdev->dev, hammer_stop, hdev);
515+
if (error)
516+
return error;
517+
528518
/*
529519
* We always want to poll for, and handle tablet mode events from
530520
* devices that have folded usage, even when nobody has opened the input
@@ -577,9 +567,7 @@ static void hammer_remove(struct hid_device *hdev)
577567
spin_unlock_irqrestore(&cbas_ec_lock, flags);
578568
}
579569

580-
hammer_unregister_leds(hdev);
581-
582-
hid_hw_stop(hdev);
570+
/* Unregistering LEDs and stopping the hardware is done via devm */
583571
}
584572

585573
static const struct hid_device_id hammer_devices[] = {

0 commit comments

Comments
 (0)