Commit d950db3f authored by Dmitry Torokhov's avatar Dmitry Torokhov

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: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent ce835633
...@@ -340,9 +340,9 @@ static int hammer_kbd_brightness_set_blocking(struct led_classdev *cdev, ...@@ -340,9 +340,9 @@ static int hammer_kbd_brightness_set_blocking(struct led_classdev *cdev,
static int hammer_register_leds(struct hid_device *hdev) static int hammer_register_leds(struct hid_device *hdev)
{ {
struct hammer_kbd_leds *kbd_backlight; struct hammer_kbd_leds *kbd_backlight;
int error;
kbd_backlight = kzalloc(sizeof(*kbd_backlight), GFP_KERNEL); kbd_backlight = devm_kzalloc(&hdev->dev, sizeof(*kbd_backlight),
GFP_KERNEL);
if (!kbd_backlight) if (!kbd_backlight)
return -ENOMEM; return -ENOMEM;
...@@ -356,26 +356,7 @@ static int hammer_register_leds(struct hid_device *hdev) ...@@ -356,26 +356,7 @@ static int hammer_register_leds(struct hid_device *hdev)
/* Set backlight to 0% initially. */ /* Set backlight to 0% initially. */
hammer_kbd_brightness_set_blocking(&kbd_backlight->cdev, 0); hammer_kbd_brightness_set_blocking(&kbd_backlight->cdev, 0);
error = led_classdev_register(&hdev->dev, &kbd_backlight->cdev); return devm_led_classdev_register(&hdev->dev, &kbd_backlight->cdev);
if (error)
goto err_free_mem;
hid_set_drvdata(hdev, kbd_backlight);
return 0;
err_free_mem:
kfree(kbd_backlight);
return error;
}
static void hammer_unregister_leds(struct hid_device *hdev)
{
struct hammer_kbd_leds *kbd_backlight = hid_get_drvdata(hdev);
if (kbd_backlight) {
led_classdev_unregister(&kbd_backlight->cdev);
kfree(kbd_backlight);
}
} }
#define HID_UP_GOOGLEVENDOR 0xffd10000 #define HID_UP_GOOGLEVENDOR 0xffd10000
...@@ -512,6 +493,11 @@ static void hammer_get_folded_state(struct hid_device *hdev) ...@@ -512,6 +493,11 @@ static void hammer_get_folded_state(struct hid_device *hdev)
kfree(buf); kfree(buf);
} }
static void hammer_stop(void *hdev)
{
hid_hw_stop(hdev);
}
static int hammer_probe(struct hid_device *hdev, static int hammer_probe(struct hid_device *hdev,
const struct hid_device_id *id) const struct hid_device_id *id)
{ {
...@@ -525,6 +511,10 @@ static int hammer_probe(struct hid_device *hdev, ...@@ -525,6 +511,10 @@ static int hammer_probe(struct hid_device *hdev,
if (error) if (error)
return error; return error;
error = devm_add_action(&hdev->dev, hammer_stop, hdev);
if (error)
return error;
/* /*
* We always want to poll for, and handle tablet mode events from * We always want to poll for, and handle tablet mode events from
* devices that have folded usage, even when nobody has opened the input * devices that have folded usage, even when nobody has opened the input
...@@ -577,9 +567,7 @@ static void hammer_remove(struct hid_device *hdev) ...@@ -577,9 +567,7 @@ static void hammer_remove(struct hid_device *hdev)
spin_unlock_irqrestore(&cbas_ec_lock, flags); spin_unlock_irqrestore(&cbas_ec_lock, flags);
} }
hammer_unregister_leds(hdev); /* Unregistering LEDs and stopping the hardware is done via devm */
hid_hw_stop(hdev);
} }
static const struct hid_device_id hammer_devices[] = { static const struct hid_device_id hammer_devices[] = {
......
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