From: Oleg Keri <okerixx@gmail.com>
To: "Derek J. Clark" <derekjohn.clark@gmail.com>,
Mark Pearson <mpearson-lenovo@squebb.ca>,
Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>,
Hans de Goede <hansg@kernel.org>,
Bernhard Seibold <mail@bernhard-seibold.de>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] HID: lenovo: allocate the trackpoint drvdata before exposing its sysfs attributes
Date: Thu, 10 Sep 2026 17:10:51 +0200 [thread overview]
Message-ID: <20260910151051.12975-3-okerixx@gmail.com> (raw)
In-Reply-To: <20260910151051.12975-1-okerixx@gmail.com>
lenovo_probe_tpkbd() creates its sysfs group before allocating the
lenovo_drvdata that every attribute handler dereferences through
hid_get_drvdata(), and drvdata is explicitly NULL at that point. A read of
e.g. the sensitivity attribute between the two steps is a NULL pointer
dereference.
Allocate and install the drvdata first, then create the group. The
allocation failure path no longer has a group to remove, so it returns
directly.
Fixes: c1dcad2d32d0 ("HID: Driver for Lenovo Keyboard with Trackpoint")
Link: https://lore.kernel.org/all/20260910064345.9BF1E1F000FF@smtp.kernel.org/
Signed-off-by: Oleg Keri <okerixx@gmail.com>
---
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c
index ff7c5ef..62bb805 100644
--- a/drivers/hid/hid-lenovo.c
+++ b/drivers/hid/hid-lenovo.c
@@ -1253,17 +1253,12 @@ static int lenovo_probe_tpkbd(struct hid_device *hdev)
if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 3, 0, 2))
return -ENODEV;
- ret = sysfs_create_group(&hdev->dev.kobj, &lenovo_attr_group_tpkbd);
- if (ret)
- hid_warn(hdev, "Could not create sysfs group: %d\n", ret);
-
data_pointer = devm_kzalloc(&hdev->dev,
sizeof(struct lenovo_drvdata),
GFP_KERNEL);
if (data_pointer == NULL) {
hid_err(hdev, "Could not allocate memory for driver data\n");
- ret = -ENOMEM;
- goto err;
+ return -ENOMEM;
}
// set same default values as windows driver
@@ -1272,6 +1267,10 @@ static int lenovo_probe_tpkbd(struct hid_device *hdev)
hid_set_drvdata(hdev, data_pointer);
+ ret = sysfs_create_group(&hdev->dev.kobj, &lenovo_attr_group_tpkbd);
+ if (ret)
+ hid_warn(hdev, "Could not create sysfs group: %d\n", ret);
+
ret = lenovo_register_leds(hdev);
if (ret)
goto err;
--
2.55.0
prev parent reply other threads:[~2026-09-10 15:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 15:10 [PATCH 0/2] HID: lenovo: two ordering fixes in remove() and tpkbd probe Oleg Keri
2026-09-10 15:10 ` [PATCH 1/2] HID: lenovo: stop the hardware before the per-model teardown Oleg Keri
2026-09-10 15:10 ` Oleg Keri [this message]
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=20260910151051.12975-3-okerixx@gmail.com \
--to=okerixx@gmail.com \
--cc=bentiss@kernel.org \
--cc=derekjohn.clark@gmail.com \
--cc=hansg@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mail@bernhard-seibold.de \
--cc=mpearson-lenovo@squebb.ca \
/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.