All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: linux-input@vger.kernel.org
Cc: Stephen Boyd <swboyd@chromium.org>,
	benjamin.tissoires@redhat.com, Jiri Kosina <jikos@kernel.org>,
	Sean O'Brien <seobrien@chromium.org>,
	"Douglas Anderson linux-kernel @ vger . kernel . org" 
	<dianders@chromium.org>
Subject: [PATCH v5 1/5] HID: google: switch to devm when registering keyboard backlight LED
Date: Sun, 27 Feb 2022 23:54:42 -0800	[thread overview]
Message-ID: <20220228075446.466016-2-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20220228075446.466016-1-dmitry.torokhov@gmail.com>

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.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/hid/hid-google-hammer.c | 38 +++++++++++----------------------
 1 file changed, 13 insertions(+), 25 deletions(-)

diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c
index 0403beb3104b..e7da4e74b4bf 100644
--- a/drivers/hid/hid-google-hammer.c
+++ b/drivers/hid/hid-google-hammer.c
@@ -340,9 +340,9 @@ static int hammer_kbd_brightness_set_blocking(struct led_classdev *cdev,
 static int hammer_register_leds(struct hid_device *hdev)
 {
 	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)
 		return -ENOMEM;
 
@@ -356,26 +356,7 @@ static int hammer_register_leds(struct hid_device *hdev)
 	/* Set backlight to 0% initially. */
 	hammer_kbd_brightness_set_blocking(&kbd_backlight->cdev, 0);
 
-	error = 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);
-	}
+	return devm_led_classdev_register(&hdev->dev, &kbd_backlight->cdev);
 }
 
 #define HID_UP_GOOGLEVENDOR	0xffd10000
@@ -512,6 +493,11 @@ static void hammer_get_folded_state(struct hid_device *hdev)
 	kfree(buf);
 }
 
+static void hammer_stop(void *hdev)
+{
+	hid_hw_stop(hdev);
+}
+
 static int hammer_probe(struct hid_device *hdev,
 			const struct hid_device_id *id)
 {
@@ -525,6 +511,10 @@ static int hammer_probe(struct hid_device *hdev,
 	if (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
 	 * devices that have folded usage, even when nobody has opened the input
@@ -577,9 +567,7 @@ static void hammer_remove(struct hid_device *hdev)
 		spin_unlock_irqrestore(&cbas_ec_lock, flags);
 	}
 
-	hammer_unregister_leds(hdev);
-
-	hid_hw_stop(hdev);
+	/* Unregistering LEDs and stopping the hardware is done via devm */
 }
 
 static const struct hid_device_id hammer_devices[] = {
-- 
2.35.1.574.g5d30c73bfb-goog


  reply	other threads:[~2022-02-28  7:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-28  7:54 [PATCH v5 0/5] Input/HID: Consolidate ChromeOS Vivaldi keyboard logic Dmitry Torokhov
2022-02-28  7:54 ` Dmitry Torokhov [this message]
2022-02-28  7:54 ` [PATCH v5 2/5] Input: extract ChromeOS vivaldi physmap show function Dmitry Torokhov
2022-02-28  7:54 ` [PATCH v5 3/5] HID: google: extract Vivaldi hid feature mapping for use in hid-hammer Dmitry Torokhov
2022-02-28 20:56   ` Stephen Boyd
2022-02-28  7:54 ` [PATCH v5 4/5] HID: google: Add support for vivaldi to hid-hammer Dmitry Torokhov
2022-02-28  7:54 ` [PATCH v5 5/5] HID: google: modify HID device groups of eel Dmitry Torokhov
2022-02-28 20:57   ` Stephen Boyd
2022-03-01  6:55     ` Dmitry Torokhov
2022-03-02  1:52 ` [PATCH v5 0/5] Input/HID: Consolidate ChromeOS Vivaldi keyboard logic Stephen Boyd

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220228075446.466016-2-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=dianders@chromium.org \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=seobrien@chromium.org \
    --cc=swboyd@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.