All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Derek J. Clark" <derekjohn.clark@gmail.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v6 3/4] HID: hid-msi: Add RGB control interface
Date: Mon, 18 May 2026 23:56:03 +0000	[thread overview]
Message-ID: <20260518235603.DC3E9C2BCB7@smtp.kernel.org> (raw)
In-Reply-To: <20260518222935.1802071-4-derekjohn.clark@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] Use-After-Free and NULL pointer dereference risks during RGB interface teardown.
- [High] Use-After-Free due to incorrect workqueue cancellation order.
- [Medium] Lifecycle mismatch of sysfs groups causes kernfs warnings on device removal.
- [Medium] Gamepad initialization is fully disabled if the RGB configuration read fails.
--

commit 1d7a0aec4b983c2c64bceb50fe253ae0e8e94c94
Author: Derek J. Clark <derekjohn.clark@gmail.com>
HID: hid-msi: Add RGB control interface

This commit adds an RGB control interface for MSI Claw devices, parsing
profile and effect data to mirror the RGB effects available in Windows.

> diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
> index e58d35dba5b40..4d267b896da72 100644
> --- a/drivers/hid/hid-msi.c
> +++ b/drivers/hid/hid-msi.c

[ ... ]

> @@ -846,16 +1372,44 @@ static void cfg_setup_fn(struct work_struct *work)
>  		return;
>  	}
>  
> -	/* Add sysfs attributes after we get the device state */
> -	ret = devm_device_add_group(&drvdata->hdev->dev, &claw_gamepad_attr_group);
> +	ret = claw_read_rgb_config(drvdata->hdev);
>  	if (ret) {
>  		dev_err(&drvdata->hdev->dev,
> -			"Failed to setup device, can't create gamepad attrs: %d\n", ret);
> +			"Failed to setup device, can't read RGB config: %d\n", ret);
>  		return;
>  	}

If claw_read_rgb_config() fails, it returns early and skips registering the 
gamepad attributes. Should core gamepad functionality (like button mapping)
break if the cosmetic RGB feature fails to initialize?

> -	drvdata->gamepad_registered = true;
> +
> +	/* Add sysfs attributes after we get the device state */
> +	if (!drvdata->gamepad_registered) {
> +		ret = devm_device_add_group(&drvdata->hdev->dev, &claw_gamepad_attr_group);
> +		if (ret) {
> +			dev_err(&drvdata->hdev->dev,
> +				"Failed to setup device, can't create gamepad attrs: %d\n", ret);
> +			return;
> +		}
> +		drvdata->gamepad_registered = true;
> +	}
> +
> +	/* Add and enable RGB interface once we have the device state */
> +	if (!drvdata->rgb_registered) {
> +		ret = devm_led_classdev_multicolor_register(&drvdata->hdev->dev, &drvdata->led_mc);
> +		if (ret) {
> +			dev_err(&drvdata->hdev->dev,
> +				"Failed to setup device, can't create led device: %d\n", ret);
> +			return;
> +		}
> +
> +		ret = devm_device_add_group(drvdata->led_mc.led_cdev.dev, &claw_rgb_attr_group);

Will this trigger a kernfs warning on device removal? 

The LED class device is unregistered via devres first, which calls 
device_del() and implicitly removes all sysfs entries. This makes the 
subsequent devres removal of claw_rgb_attr_group fail to find the directory, 
triggering a "can not remove '...', no directory" warning.

Would it be safer to assign this group to drvdata->led_mc.led_cdev.groups
before registration instead of using devm_device_add_group()?

> +		if (ret) {
> +			dev_err(&drvdata->hdev->dev,
> +				"Failed to setup device, can't create led attributes: %d\n", ret);
> +			return;
> +		}
> +		drvdata->rgb_registered = true;
> +	}
>  
>  	kobject_uevent(&drvdata->hdev->dev.kobj, KOBJ_CHANGE);
> +	kobject_uevent(&drvdata->led_mc.led_cdev.dev->kobj, KOBJ_CHANGE);
>  }

[ ... ]

> @@ -979,10 +1553,14 @@ static void claw_remove(struct hid_device *hdev)
>  		return;
>  	}
>  
> +	/* Block writes to brightness/multi_intensity during teardown */
> +	drvdata->led_mc.led_cdev.brightness_set = NULL;

Can this race with __led_set_brightness() in the LED subsystem? If the LED 
core checks the brightness_set pointer and finds it valid, but gets preempted
while this runs without locking, could it then jump to a NULL pointer?

>  	cancel_delayed_work_sync(&drvdata->cfg_setup);
>  	cancel_delayed_work_sync(&drvdata->cfg_resume);

Since cfg_resume_fn() schedules cfg_setup, is it possible for cfg_setup to 
be re-armed here? 

If cfg_resume is currently running, cancelling cfg_setup first does nothing, 
and then cfg_resume will queue cfg_setup again before completing. This could 
leave cfg_setup pending after the driver data is freed.

> +	cancel_delayed_work_sync(&drvdata->rgb_queue);
>  
>  	drvdata->gamepad_registered = false;
> +	drvdata->rgb_enabled = false;
>  
>  	hid_hw_close(hdev);
>  }

Because drvdata->rgb_registered remains true here, and the RGB sysfs 
attributes are devres-managed (meaning they persist until after claw_remove
returns), could a concurrent userspace write pass the rgb_registered check 
and call mod_delayed_work()? 

This would re-arm rgb_queue after it was cancelled, leading to a 
use-after-free when drvdata is eventually freed. Should 
drvdata->rgb_registered = false be set before cancelling the workqueue?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260518222935.1802071-1-derekjohn.clark@gmail.com?part=3

  reply	other threads:[~2026-05-18 23:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-18 22:29 [PATCH v6 0/4] Add MSI Claw HID Configuration Driver Derek J. Clark
2026-05-18 22:29 ` [PATCH v6 1/4] HID: hid-msi: Add MSI Claw configuration driver Derek J. Clark
2026-05-18 22:57   ` sashiko-bot
2026-05-18 22:29 ` [PATCH v6 2/4] HID: hid-msi: Add M-key mapping attributes Derek J. Clark
2026-05-18 23:29   ` sashiko-bot
2026-05-18 22:29 ` [PATCH v6 3/4] HID: hid-msi: Add RGB control interface Derek J. Clark
2026-05-18 23:56   ` sashiko-bot [this message]
2026-05-18 22:29 ` [PATCH v6 4/4] HID: hid-msi: Add Rumble Intensity Attributes Derek J. Clark
2026-05-19  0:22   ` sashiko-bot

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=20260518235603.DC3E9C2BCB7@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=derekjohn.clark@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.