From: "Derek J. Clark" <derekjohn.clark@gmail.com>
To: Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <bentiss@kernel.org>
Cc: "Pierre-Loup A . Griffais" <pgriffais@valvesoftware.com>,
"Derek J . Clark" <derekjohn.clark@gmail.com>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel@lists.opengamingcollective.org, stable@vger.kernel.org
Subject: [PATCH 07/10] HID: hid-lenovo-go-s: Move attribute init to after device query
Date: Mon, 14 Sep 2026 15:53:00 -0700 [thread overview]
Message-ID: <20260914225303.868569-8-derekjohn.clark@gmail.com> (raw)
In-Reply-To: <20260914225303.868569-1-derekjohn.clark@gmail.com>
Currently this driver registers attributes before the MCU is ready to
accept commands. This can lead to attribute access that blocks the MCU
in some rare cases.
Move attribute construction to gos_cfg_setup, after the device has been
queried. Gate creation to drvdata.gp_registered and
drvdata.rgb_registered so a resume before setup has run doesn't prevent
attribute creation or attempt to re-register the same attributes.
Fixes: a23f3497bf208c59ad ("HID: hid-lenovo-go-s: Add Lenovo Legion Go S Series HID Driver")
Cc: stable@vger.kernel.org
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
drivers/hid/hid-lenovo-go-s.c | 68 +++++++++++++++++++++++------------
1 file changed, 45 insertions(+), 23 deletions(-)
diff --git a/drivers/hid/hid-lenovo-go-s.c b/drivers/hid/hid-lenovo-go-s.c
index 6d98fff6d987..f1a0bcfcdb71 100644
--- a/drivers/hid/hid-lenovo-go-s.c
+++ b/drivers/hid/hid-lenovo-go-s.c
@@ -1452,6 +1452,7 @@ static struct led_classdev_mc gos_cdev_rgb = {
static void cfg_setup(struct work_struct *work)
{
+ bool gp_registered, rgb_registered;
int ret;
/* MCU */
@@ -1497,10 +1498,53 @@ static void cfg_setup(struct work_struct *work)
return;
}
+ /* Pairs with smp_store_release from below */
+ gp_registered = smp_load_acquire(&drvdata.gp_registered);
+ if (gp_registered)
+ goto try_rgb;
+
+ ret = sysfs_create_groups(&drvdata.hdev->dev.kobj, top_level_attr_groups);
+ if (ret) {
+ dev_err(&drvdata.hdev->dev,
+ "Failed to create gamepad configuration attributes: %i\n", ret);
+ goto try_rgb;
+ }
+
/* Pairs with smp_load_acquire in attribute show/store functions */
smp_store_release(&drvdata.gp_registered, true);
+ gp_registered = true;
+
+try_rgb:
+ /* Pairs with smp_store_release from below */
+ rgb_registered = smp_load_acquire(&drvdata.rgb_registered);
+ if (rgb_registered)
+ goto update_kobjects;
+
+ ret = devm_led_classdev_multicolor_register(&drvdata.hdev->dev, &gos_cdev_rgb);
+ if (ret) {
+ dev_err(&drvdata.hdev->dev,
+ "Failed to create RGB device: %i\n", ret);
+ goto update_kobjects;
+ }
+
+ ret = devm_device_add_group(gos_cdev_rgb.led_cdev.dev, &rgb_attr_group);
+ if (ret) {
+ dev_err(&drvdata.hdev->dev,
+ "Failed to create RGB configuration attributes: %i\n", ret);
+ goto update_kobjects;
+ }
+
+ drvdata.led_cdev = &gos_cdev_rgb.led_cdev;
+
/* Pairs with smp_load_acquire in attribute show/store functions */
smp_store_release(&drvdata.rgb_registered, true);
+ rgb_registered = true;
+
+update_kobjects:
+ if (gp_registered)
+ kobject_uevent(&drvdata.hdev->dev.kobj, KOBJ_CHANGE);
+ if (rgb_registered)
+ kobject_uevent(&drvdata.led_cdev->dev->kobj, KOBJ_CHANGE);
}
static int hid_gos_cfg_probe(struct hid_device *hdev,
@@ -1510,30 +1554,8 @@ static int hid_gos_cfg_probe(struct hid_device *hdev,
hid_set_drvdata(hdev, &drvdata);
drvdata.hdev = hdev;
- mutex_init(&drvdata.cfg_mutex);
-
- ret = sysfs_create_groups(&hdev->dev.kobj, top_level_attr_groups);
- if (ret) {
- dev_err_probe(&hdev->dev, ret,
- "Failed to create gamepad configuration attributes\n");
- return ret;
- }
-
- ret = devm_led_classdev_multicolor_register(&hdev->dev, &gos_cdev_rgb);
- if (ret) {
- dev_err_probe(&hdev->dev, ret, "Failed to create RGB device\n");
- return ret;
- }
-
- ret = devm_device_add_group(gos_cdev_rgb.led_cdev.dev, &rgb_attr_group);
- if (ret) {
- dev_err_probe(&hdev->dev, ret,
- "Failed to create RGB configuration attributes\n");
- return ret;
- }
-
- drvdata.led_cdev = &gos_cdev_rgb.led_cdev;
+ mutex_init(&drvdata.cfg_mutex);
init_completion(&drvdata.send_cmd_complete);
/* Executing calls prior to returning from probe will lock the MCU. Schedule
--
2.55.0
next prev parent reply other threads:[~2026-09-14 22:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 22:52 [PATCH 00/10] HID: hid-lenovo-go-s: Fix various bugs Derek J. Clark
2026-09-14 22:52 ` [PATCH 01/10] HID: hid-lenovo-go-s: Return ret instead of 0 in mcu_property_out() Derek J. Clark
2026-09-14 22:52 ` [PATCH 02/10] HID: hid-lenovo-go-s: Bound stale reply window before reusing send_cmd_complete Derek J. Clark
2026-09-14 22:52 ` [PATCH 03/10] HID: hid-lenovo-go-s: Prevent deadlock if device removed during setup Derek J. Clark
2026-09-14 22:52 ` [PATCH 04/10] HID: hid-lenovo-go-s: Use pm_ptr for reset_resume callback Derek J. Clark
2026-09-14 22:52 ` [PATCH 05/10] HID: hid-lenovo-go-s: Add kobject_uevent notify during reset-resume Derek J. Clark
2026-09-14 22:52 ` [PATCH 06/10] HID: hid-lenovo-go-s: Add suspend function and gate access under bool Derek J. Clark
2026-09-14 22:53 ` Derek J. Clark [this message]
2026-09-14 22:53 ` [PATCH 08/10] HID: hid-lenovo-go-s: Reorganize and rename hid_gos_cfg Derek J. Clark
2026-09-14 22:53 ` [PATCH 09/10] HID: hid-lenovo-go-s: Move static led_classdev_mc to drvdata struct Derek J. Clark
2026-09-14 22:53 ` [PATCH 10/10] HID: hid-lenovo-go-s: Use devm_kzalloc for drvdata Derek J. Clark
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=20260914225303.868569-8-derekjohn.clark@gmail.com \
--to=derekjohn.clark@gmail.com \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=kernel@lists.opengamingcollective.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pgriffais@valvesoftware.com \
--cc=stable@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®