[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230125-hid-unregister-leds-v2-5-689cc62fc878@diag.uniroma1.it>
Date: Tue, 31 Jan 2023 13:08:49 +0000
From: Pietro Borrello <borrello@...g.uniroma1.it>
To: Jiri Kosina <jikos@...nel.org>,
Benjamin Tissoires <benjamin.tissoires@...hat.com>,
Hanno Zulla <kontakt@...no.de>, Pavel Machek <pavel@....cz>,
Lee Jones <lee@...nel.org>,
Roderick Colenbrander <roderick.colenbrander@...y.com>,
Sven Eckelmann <sven@...fation.org>
Cc: linux-leds@...r.kernel.org,
Cristiano Giuffrida <c.giuffrida@...nl>,
"Bos, H.J." <h.j.bos@...nl>, Jakob Koschel <jkl820.git@...il.com>,
linux-input@...r.kernel.org, linux-kernel@...r.kernel.org,
Jiri Kosina <jkosina@...e.cz>,
Roderick Colenbrander <roderick@...kai.com>,
Pietro Borrello <borrello@...g.uniroma1.it>
Subject: [PATCH v2 5/5] HID: sony_remove: manually unregister leds
Unregister the LED controller before device removal, as
sony_led_set_brightness() may schedule sc->state_worker
after the structure has been freed, causing a use-after-free.
Fixes: 0a286ef27852 ("HID: sony: Add LED support for Sixaxis/Dualshock3 USB")
Signed-off-by: Pietro Borrello <borrello@...g.uniroma1.it>
Reviewed-by: Sven Eckelmann <sven@...fation.org>
---
drivers/hid/hid-sony.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 13125997ab5e..146677c8319c 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -3083,6 +3083,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
static void sony_remove(struct hid_device *hdev)
{
struct sony_sc *sc = hid_get_drvdata(hdev);
+ int n;
if (sc->quirks & (GHL_GUITAR_PS3WIIU | GHL_GUITAR_PS4)) {
del_timer_sync(&sc->ghl_poke_timer);
@@ -3100,6 +3101,13 @@ static void sony_remove(struct hid_device *hdev)
if (sc->hw_version_created)
device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version);
+ if (sc->quirks & SONY_LED_SUPPORT) {
+ for (n = 0; n < sc->led_count; n++) {
+ if (sc->leds[n])
+ devm_led_classdev_unregister(&hdev->dev, sc->leds[n]);
+ }
+ }
+
sony_cancel_work_sync(sc);
sony_remove_dev_list(sc);
--
2.25.1
Powered by blists - more mailing lists