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 v2 09/11] HID: hid-lenovo-go-s: Move static led_classdev_mc to drvdata struct
Date: Fri, 16 Oct 2026 18:39:54 -0700 [thread overview]
Message-ID: <20261017013956.2440130-10-derekjohn.clark@gmail.com> (raw)
In-Reply-To: <20261017013956.2440130-1-derekjohn.clark@gmail.com>
In the next patch I will switch drvdata from static global to a
devm_kzalloc struct. In preparation for that, move the led_classdev_mc
to be a member of the gos_cfg_drvdata struct. As part of that effort,
provide a constant name when accessing it and access the led_classdev
through the led_classdev_mc.
Fixes: be6d7dbb368ba840d7 ("HID: hid-lenovo-go-s: Add RGB LED control interface")
Cc: stable@vger.kernel.org
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
drivers/hid/hid-lenovo-go-s.c | 77 +++++++++++++++++------------------
1 file changed, 38 insertions(+), 39 deletions(-)
diff --git a/drivers/hid/hid-lenovo-go-s.c b/drivers/hid/hid-lenovo-go-s.c
index 136372eb6e6b..2e938dd5e77c 100644
--- a/drivers/hid/hid-lenovo-go-s.c
+++ b/drivers/hid/hid-lenovo-go-s.c
@@ -61,7 +61,7 @@ static struct gos_cfg_drvdata {
u8 tp_en;
/* RGB Variables */
- struct led_classdev *led_cdev;
+ struct led_classdev_mc led_mc;
bool rgb_registered;
u8 rgb_profile;
u8 rgb_effect;
@@ -348,7 +348,7 @@ static int hid_gos_pl_test_event(struct command_report *cmd_rep)
static int hid_gos_light_event(struct command_report *cmd_rep)
{
- struct led_classdev_mc *mc_cdev;
+ struct led_classdev_mc *led_mc;
int ret = 0;
switch (cmd_rep->sub_cmd) {
@@ -363,12 +363,12 @@ static int hid_gos_light_event(struct command_report *cmd_rep)
case USR_LIGHT_PROFILE_1:
case USR_LIGHT_PROFILE_2:
case USR_LIGHT_PROFILE_3:
- mc_cdev = lcdev_to_mccdev(drvdata.led_cdev);
+ led_mc = &drvdata.led_mc;
drvdata.rgb_effect = cmd_rep->data[0];
- mc_cdev->subled_info[0].intensity = cmd_rep->data[1];
- mc_cdev->subled_info[1].intensity = cmd_rep->data[2];
- mc_cdev->subled_info[2].intensity = cmd_rep->data[3];
- drvdata.led_cdev->brightness = cmd_rep->data[4];
+ led_mc->subled_info[0].intensity = cmd_rep->data[1];
+ led_mc->subled_info[1].intensity = cmd_rep->data[2];
+ led_mc->subled_info[2].intensity = cmd_rep->data[3];
+ led_mc->led_cdev.brightness = cmd_rep->data[4];
drvdata.rgb_speed = cmd_rep->data[5];
ret = 0;
break;
@@ -931,7 +931,7 @@ static ssize_t rgb_effect_store(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{
- struct led_classdev_mc *mc_cdev = lcdev_to_mccdev(drvdata.led_cdev);
+ struct led_classdev_mc *led_mc = &drvdata.led_mc;
enum rgb_config_index index;
bool rgb_registered;
u8 effect;
@@ -949,10 +949,10 @@ static ssize_t rgb_effect_store(struct device *dev,
effect = ret;
index = drvdata.rgb_profile + 2;
u8 rgb_profile[6] = { effect,
- mc_cdev->subled_info[0].intensity,
- mc_cdev->subled_info[1].intensity,
- mc_cdev->subled_info[2].intensity,
- drvdata.led_cdev->brightness,
+ led_mc->subled_info[0].intensity,
+ led_mc->subled_info[1].intensity,
+ led_mc->subled_info[2].intensity,
+ led_mc->led_cdev.brightness,
drvdata.rgb_speed };
ret = rgb_cfg_call(drvdata.hdev, SET_RGB_CFG, index, rgb_profile, 6);
@@ -1003,7 +1003,7 @@ static ssize_t rgb_speed_store(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{
- struct led_classdev_mc *mc_cdev = lcdev_to_mccdev(drvdata.led_cdev);
+ struct led_classdev_mc *led_mc = &drvdata.led_mc;
enum rgb_config_index index;
bool rgb_registered;
int val = 0;
@@ -1023,10 +1023,10 @@ static ssize_t rgb_speed_store(struct device *dev,
index = drvdata.rgb_profile + 2;
u8 rgb_profile[6] = { drvdata.rgb_effect,
- mc_cdev->subled_info[0].intensity,
- mc_cdev->subled_info[1].intensity,
- mc_cdev->subled_info[2].intensity,
- drvdata.led_cdev->brightness,
+ led_mc->subled_info[0].intensity,
+ led_mc->subled_info[1].intensity,
+ led_mc->subled_info[2].intensity,
+ led_mc->led_cdev.brightness,
val };
ret = rgb_cfg_call(drvdata.hdev, SET_RGB_CFG, index, rgb_profile, 6);
@@ -1189,7 +1189,7 @@ static ssize_t rgb_profile_range_show(struct device *dev,
static void hid_gos_brightness_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
- struct led_classdev_mc *mc_cdev = lcdev_to_mccdev(drvdata.led_cdev);
+ struct led_classdev_mc *led_mc = &drvdata.led_mc;
enum rgb_config_index index;
bool rgb_registered;
int ret;
@@ -1206,9 +1206,9 @@ static void hid_gos_brightness_set(struct led_classdev *led_cdev,
index = drvdata.rgb_profile + 2;
u8 rgb_profile[6] = { drvdata.rgb_effect,
- mc_cdev->subled_info[0].intensity,
- mc_cdev->subled_info[1].intensity,
- mc_cdev->subled_info[2].intensity,
+ led_mc->subled_info[0].intensity,
+ led_mc->subled_info[1].intensity,
+ led_mc->subled_info[2].intensity,
brightness,
drvdata.rgb_speed };
@@ -1448,17 +1448,6 @@ static struct mc_subled gos_rgb_subled_info[] = {
},
};
-static struct led_classdev_mc gos_cdev_rgb = {
- .led_cdev = {
- .name = "go_s:rgb:joystick_rings",
- .brightness = 0x50,
- .max_brightness = 0x64,
- .brightness_set = hid_gos_brightness_set,
- },
- .num_colors = ARRAY_SIZE(gos_rgb_subled_info),
- .subled_info = gos_rgb_subled_info,
-};
-
static int cfg_query_device(void)
{
int ret;
@@ -1544,14 +1533,12 @@ static void cfg_setup(struct work_struct *work)
}
if (!drvdata.rgb_registered) {
- 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;
ret = led_classdev_multicolor_register(&drvdata.hdev->dev,
- &gos_cdev_rgb);
+ &drvdata.led_mc);
if (ret) {
dev_err(&drvdata.hdev->dev, "Failed to create RGB device: %i\n",
ret);
@@ -1560,14 +1547,14 @@ static void cfg_setup(struct work_struct *work)
smp_store_release(&drvdata.rgb_registered, false);
rgb_registered = false;
} else {
- ret = devm_device_add_group(gos_cdev_rgb.led_cdev.dev,
+ ret = devm_device_add_group(drvdata.led_mc.led_cdev.dev,
&rgb_attr_group);
if (ret) {
dev_err(&drvdata.hdev->dev,
"Failed to create RGB configuration attributes: %i\n",
ret);
- led_classdev_multicolor_unregister(&gos_cdev_rgb);
+ led_classdev_multicolor_unregister(&drvdata.led_mc);
/* Pairs with smp_load_acquire in attribute show/store functions */
smp_store_release(&drvdata.rgb_registered, false);
@@ -1579,7 +1566,7 @@ static void cfg_setup(struct work_struct *work)
if (gp_registered)
kobject_uevent(&drvdata.hdev->dev.kobj, KOBJ_CHANGE);
if (rgb_registered)
- kobject_uevent(&drvdata.led_cdev->dev->kobj, KOBJ_CHANGE);
+ kobject_uevent(&drvdata.led_mc.led_cdev.dev->kobj, KOBJ_CHANGE);
}
static int hid_gos_cfg_probe(struct hid_device *hdev,
@@ -1593,6 +1580,18 @@ static int hid_gos_cfg_probe(struct hid_device *hdev,
mutex_init(&drvdata.cfg_mutex);
init_completion(&drvdata.send_cmd_complete);
+ /* Device is hardwired and name is guaranteed to be unique */
+ drvdata.led_mc.led_cdev.name = "go_s:rgb:joystick_rings";
+ drvdata.led_mc.led_cdev.brightness = 0x50;
+ drvdata.led_mc.led_cdev.max_brightness = 0x64;
+ drvdata.led_mc.led_cdev.color = LED_COLOR_ID_RGB;
+ drvdata.led_mc.led_cdev.brightness_set = hid_gos_brightness_set;
+ drvdata.led_mc.num_colors = 3;
+ drvdata.led_mc.subled_info = devm_kmemdup(&hdev->dev, gos_rgb_subled_info,
+ sizeof(gos_rgb_subled_info), GFP_KERNEL);
+ if (!drvdata.led_mc.subled_info)
+ return -ENOMEM;
+
/* Executing calls prior to returning from probe will lock the MCU. Schedule
* initial data call after probe has completed and MCU can accept calls.
*/
@@ -1616,7 +1615,7 @@ static void hid_gos_cfg_remove(struct hid_device *hdev)
/* Pairs with smp_store_release in cfg_setup */
rgb_registered = smp_load_acquire(&drvdata.rgb_registered);
if (rgb_registered)
- led_classdev_multicolor_unregister(&gos_cdev_rgb);
+ led_classdev_multicolor_unregister(&drvdata.led_mc);
hid_hw_close(hdev);
hid_hw_stop(hdev);
--
2.55.0
next prev parent reply other threads:[~2026-10-17 1:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-17 1:39 [PATCH v2 00/11] HID: hid-lenovo-go-s: Fix various bugs Derek J. Clark
2026-10-17 1:39 ` [PATCH v2 01/11] HID: hid-lenovo-go-s: Return ret instead of 0 in mcu_property_out() Derek J. Clark
2026-10-17 1:39 ` [PATCH v2 02/11] HID: hid-lenovo-go-s: Bound stale reply window before reusing send_cmd_complete Derek J. Clark
2026-10-17 1:39 ` [PATCH v2 03/11] HID: hid-lenovo-go-s: Prevent deadlock if device removed during setup Derek J. Clark
2026-10-17 1:39 ` [PATCH v2 04/11] HID: hid-lenovo-go-s: Use pm_ptr for reset_resume callback Derek J. Clark
2026-10-17 1:39 ` [PATCH v2 05/11] HID: hid-lenovo-go-s: Add kobject_uevent notify during reset-resume Derek J. Clark
2026-10-17 1:39 ` [PATCH v2 06/11] HID: hid-lenovo-go-s: Add suspend function and gate access under bool Derek J. Clark
2026-10-17 2:03 ` sashiko-bot
2026-10-17 1:39 ` [PATCH v2 07/11] HID: hid-lenovo-go-s: Move attribute init to after device query Derek J. Clark
2026-10-17 2:07 ` sashiko-bot
2026-10-17 1:39 ` [PATCH v2 08/11] HID: hid-lenovo-go-s: Reorganize and rename hid_gos_cfg Derek J. Clark
2026-10-17 1:39 ` Derek J. Clark [this message]
2026-10-17 2:14 ` [PATCH v2 09/11] HID: hid-lenovo-go-s: Move static led_classdev_mc to drvdata struct sashiko-bot
2026-10-17 1:39 ` [PATCH v2 10/11] HID: hid-lenovo-go-s: Use devm_kzalloc for drvdata Derek J. Clark
2026-10-17 2:23 ` sashiko-bot
2026-10-17 1:39 ` [PATCH v2 11/11] HID: hid-lenovo-go-s: Stop and close device on probe failure 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=20261017013956.2440130-10-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