FAILED: patch "[PATCH] HID: sony: clean up device list on probe failure" failed to apply to 6.6-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 7c65699a3a311198a07659a614fe64d45924839e
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090344-gorged-agreeably-3d32@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 7c65699a3a311198a07659a614fe64d45924839e Mon Sep 17 00:00:00 2001
From: Doruk Tan Ozturk <[email protected]>
Date: Sun, 26 Jul 2026 14:45:51 +0200
Subject: [PATCH] HID: sony: clean up device list on probe failure
sony_input_configured() adds some controllers to sony_device_list before HID core registers their input devices. input_register_device() can fail after the callback returns successfully. sony_probe() then observes that HID_CLAIMED_INPUT is clear and unwinds, but only stops the HID hardware. The devres-managed sony_sc is freed while its list node remains linked, so the next matching controller traverses freed memory.
Initialize the list node and device ID to inactive states. Make list removal idempotent and run the driver-private cleanup on every probe failure path. This also makes a second cleanup safe when sony_input_configured() already unwound a partial initialization before sony_probe() handles the missing input claim.
Found by 0sec (https://0sec.ai) using automated source analysis; verified against the HID input registration and probe unwind paths.
drivers/hid/hid-sony.c +17 -16
@@ -1982,11 +1982,10 @@ static int sony_check_add_dev_list(struct sony_sc *sc)static void sony_remove_dev_list (struct sony_sc *sc) { -if (sc->list_node.next) { - scoped_guard(spinlock_irqsave, &sony_dev_list_lock) { -list_del (&(sc->list_node)); - } - } +guard (spinlock_irqsave)(&sony_dev_list_lock); + +if (!list_empty (&sc->list_node)) +list_del_init (&sc->list_node); }static int sony_get_bt_devaddr (struct sony_sc *sc)
@@ -2127,6 +2126,13 @@ static inline void sony_cancel_work_sync(struct sony_sc *sc) } } +static void sony_cleanup (struct sony_sc *sc) +{ +sony_cancel_work_sync (sc); +sony_remove_dev_list (sc); +sony_release_device_id (sc); +} +static int sony_input_configured (struct hid_device *hdev,struct hid_input *hidinput) {
@@ -2313,9 +2319,7 @@ static int sony_input_configured(struct hid_device *hdev, err_close:hid_hw_close (hdev); err_stop: -sony_cancel_work_sync (sc); -sony_remove_dev_list (sc); -sony_release_device_id (sc); +sony_cleanup (sc);return ret; }
@@ -2339,6 +2343,8 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)return -ENOMEM ;spin_lock_init (&sc->lock); +INIT_LIST_HEAD (&sc->list_node); + sc->device_id =-1 ; sc->quirks = quirks;hid_set_drvdata (hdev, sc);
@@ -2367,6 +2373,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) ret =hid_hw_start (hdev, connect_mask);if (ret) {hid_err (hdev,"hw start failed\n" ); +sony_cleanup (sc);return ret; }
@@ -2421,7 +2428,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) err:usb_free_urb (sc->ghl_urb); - +sony_cleanup (sc);hid_hw_stop (hdev);return ret; }
@@ -2436,13 +2443,7 @@ static void sony_remove(struct hid_device *hdev) }hid_hw_close (hdev); - -sony_cancel_work_sync (sc); - -sony_remove_dev_list (sc); - -sony_release_device_id (sc); - +sony_cleanup (sc);hid_hw_stop (hdev); }
Sasha Levin
maintainerPATCH 1/2 HID: sony: use guard() and scoped_guard()
From: Rosalie Wanders <[email protected]>
[ Upstream commit da4f817ad273bca9aefd8636d347a8c101069111 ]
This replaces the spin_lock_irqsave() and spin_unlock_irqrestore() calls with the RAII guard() and scoped_guard().
Stable-dep-of: 7c65699a3a31 ("HID: sony: clean up device list on probe failure")
--- drivers/hid/hid-sony.c | 53 ++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 31 deletions(-)
drivers/hid/hid-sony.c +22 -31
@@ -27,6 +27,7 @@* There will be no PIN request from the device. */ +#include <linux/cleanup.h> #include <linux/device.h> #include <linux/hid.h> #include <linux/module.h>
@@ -520,14 +521,12 @@ static void sony_set_leds(struct sony_sc *sc);static inline void sony_schedule_work (struct sony_sc *sc,enum sony_worker which) { -unsigned long flags; -switch (which) {case SONY_WORKER_STATE : -spin_lock_irqsave (&sc->lock, flags); -if (!sc->defer_initialization && sc->state_worker_initialized) -schedule_work (&sc->state_worker); -spin_unlock_irqrestore (&sc->lock, flags); + scoped_guard(spinlock_irqsave, &sc->lock) { +if (!sc->defer_initialization && sc->state_worker_initialized) +schedule_work (&sc->state_worker); + }break ; } }
@@ -796,7 +795,6 @@ static u8 *sony_report_fixup(struct hid_device *hdev, u8 *rdesc,static void sixaxis_parse_report (struct sony_sc *sc,u8 *rd,int size) {static const u8 sixaxis_battery_capacity[] = {0 ,1 ,25 ,50 ,75 ,100 }; -unsigned long flags;int offset;u8 battery_capacity;int battery_status;
@@ -818,10 +816,10 @@ static void sixaxis_parse_report(struct sony_sc *sc, u8 *rd, int size) battery_status =POWER_SUPPLY_STATUS_DISCHARGING ; } -spin_lock_irqsave (&sc->lock, flags); - sc->battery_capacity = battery_capacity; - sc->battery_status = battery_status; -spin_unlock_irqrestore (&sc->lock, flags); + scoped_guard(spinlock_irqsave, &sc->lock) { + sc->battery_capacity = battery_capacity; + sc->battery_status = battery_status; + }if (sc->quirks &SIXAXIS_CONTROLLER ) {int val;
@@ -1624,15 +1622,14 @@ static int sony_battery_get_property(struct power_supply *psy, union power_supply_propval *val) {struct sony_sc *sc =power_supply_get_drvdata (psy); -unsigned long flags;int ret =0 ;u8 battery_capacity;int battery_status; -spin_lock_irqsave (&sc->lock, flags); - battery_capacity = sc->battery_capacity; - battery_status = sc->battery_status; -spin_unlock_irqrestore (&sc->lock, flags); + scoped_guard(spinlock_irqsave, &sc->lock) { + battery_capacity = sc->battery_capacity; + battery_status = sc->battery_status; + }switch (psp) {case POWER_SUPPLY_PROP_PRESENT :
@@ -1714,10 +1711,9 @@ static inline int sony_compare_connection_type(struct sony_sc *sc0,static int sony_check_add_dev_list (struct sony_sc *sc) {struct sony_sc *entry; -unsigned long flags;int ret; -spin_lock_irqsave (&sony_dev_list_lock, flags); +guard (spinlock_irqsave)(&sony_dev_list_lock);list_for_each_entry (entry, &sony_device_list, list_node) { ret = memcmp(sc->mac_address, entry->mac_address,
@@ -1731,26 +1727,23 @@ static int sony_check_add_dev_list(struct sony_sc *sc)"controller with MAC address %pMR already connected\n" , sc->mac_address); } - goto unlock; + goto out; } } ret =0 ;list_add (&(sc->list_node), &sony_device_list); -unlock: -spin_unlock_irqrestore (&sony_dev_list_lock, flags); +out:return ret; }static void sony_remove_dev_list (struct sony_sc *sc) { -unsigned long flags; -if (sc->list_node.next) { -spin_lock_irqsave (&sony_dev_list_lock, flags); -list_del (&(sc->list_node)); -spin_unlock_irqrestore (&sony_dev_list_lock, flags); + scoped_guard(spinlock_irqsave, &sony_dev_list_lock) { +list_del (&(sc->list_node)); + } } }
@@ -1879,12 +1872,10 @@ static inline void sony_init_output_report(struct sony_sc *sc,static inline void sony_cancel_work_sync (struct sony_sc *sc) { -unsigned long flags; -if (sc->state_worker_initialized) { -spin_lock_irqsave (&sc->lock, flags); - sc->state_worker_initialized =0 ; -spin_unlock_irqrestore (&sc->lock, flags); + scoped_guard(spinlock_irqsave, &sc->lock) { + sc->state_worker_initialized =0 ; + }cancel_work_sync (&sc->state_worker); } }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 HID: sony: clean up device list on probe failure
From: Doruk Tan Ozturk <[email protected]>
[ Upstream commit 7c65699a3a311198a07659a614fe64d45924839e ]
sony_input_configured() adds some controllers to sony_device_list before HID core registers their input devices. input_register_device() can fail after the callback returns successfully. sony_probe() then observes that HID_CLAIMED_INPUT is clear and unwinds, but only stops the HID hardware. The devres-managed sony_sc is freed while its list node remains linked, so the next matching controller traverses freed memory.
Initialize the list node and device ID to inactive states. Make list removal idempotent and run the driver-private cleanup on every probe failure path. This also makes a second cleanup safe when sony_input_configured() already unwound a partial initialization before sony_probe() handles the missing input claim.
Found by 0sec (https://0sec.ai) using automated source analysis; verified against the HID input registration and probe unwind paths.
--- drivers/hid/hid-sony.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-)
drivers/hid/hid-sony.c +17 -16
@@ -1740,11 +1740,10 @@ static int sony_check_add_dev_list(struct sony_sc *sc)static void sony_remove_dev_list (struct sony_sc *sc) { -if (sc->list_node.next) { - scoped_guard(spinlock_irqsave, &sony_dev_list_lock) { -list_del (&(sc->list_node)); - } - } +guard (spinlock_irqsave)(&sony_dev_list_lock); + +if (!list_empty (&sc->list_node)) +list_del_init (&sc->list_node); }static int sony_get_bt_devaddr (struct sony_sc *sc)
@@ -1880,6 +1879,13 @@ static inline void sony_cancel_work_sync(struct sony_sc *sc) } } +static void sony_cleanup (struct sony_sc *sc) +{ +sony_cancel_work_sync (sc); +sony_remove_dev_list (sc); +sony_release_device_id (sc); +} +static int sony_input_configured (struct hid_device *hdev,struct hid_input *hidinput) {
@@ -2040,9 +2046,7 @@ static int sony_input_configured(struct hid_device *hdev, err_close:hid_hw_close (hdev); err_stop: -sony_cancel_work_sync (sc); -sony_remove_dev_list (sc); -sony_release_device_id (sc); +sony_cleanup (sc);return ret; }
@@ -2068,6 +2072,8 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) }spin_lock_init (&sc->lock); +INIT_LIST_HEAD (&sc->list_node); + sc->device_id =-1 ; sc->quirks = quirks;hid_set_drvdata (hdev, sc);
@@ -2096,6 +2102,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) ret =hid_hw_start (hdev, connect_mask);if (ret) {hid_err (hdev,"hw start failed\n" ); +sony_cleanup (sc);return ret; }
@@ -2147,7 +2154,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) err:usb_free_urb (sc->ghl_urb); - +sony_cleanup (sc);hid_hw_stop (hdev);return ret; }
@@ -2162,13 +2169,7 @@ static void sony_remove(struct hid_device *hdev) }hid_hw_close (hdev); - -sony_cancel_work_sync (sc); - -sony_remove_dev_list (sc); - -sony_release_device_id (sc); - +sony_cleanup (sc);hid_hw_stop (hdev); }
Signature · 1 line
2.53.0