HID: steelseries: refactor probe() and remove()
PATCH 1/1 HID: steelseries: refactor probe() and remove()
steelseries_srws1_probe() still does not use devm_kzalloc() and devm_led_classdev_register(), so there is a lot of code to safely manage heap, which reduces readability and may cause memory leaks due to minor patch mistakes in the future.
Therefore, it should be changed to use devm_kzalloc() and devm_led_classdev_register() to easily and safely manage heap.
Also, the current steelseries driver mainly checks sd->quriks to determine which product a specific HID device is, which is not the correct way.
remove(), unlike probe(), does not receive struct hid_device_id as an argument, so it must check hdev unconditionally to know which product it is.
However, since struct steelseries_device and struct steelseries_srws1_data have different structures, if SRWS1 is removed in remove(), converts hdev->dev, which is initialized to struct steelseries_srws1_data, to struct steelseries_device and uses it. This causes various memory-related bugs as completely unexpected values exist in member variables of the structure.
Therefore, in order to modify probe() and remove() to work properly, Arctis 1, 9 should be added to HID_USB_DEVICE and some functions should be modified to check hdev->product when determining HID device product.
--- drivers/hid/hid-ids.h | 2 + drivers/hid/hid-quirks.c | 2 + drivers/hid/hid-steelseries.c | 109 ++++++++++++---------------------- 3 files changed, 43 insertions(+), 70 deletions(-)
drivers/hid/hid-ids.h +2 -0
@@ -1289,6 +1289,8 @@#define USB_VENDOR_ID_STEELSERIES 0x1038#define USB_DEVICE_ID_STEELSERIES_SRWS1 0x1410 +#define USB_DEVICE_ID_STEELSERIES_ARCTIS_1 0x12b6 +#define USB_DEVICE_ID_STEELSERIES_ARCTIS_9 0x12c2#define USB_VENDOR_ID_SUN 0x0430#define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab
drivers/hid/hid-quirks.c +2 -0
@@ -691,6 +691,8 @@ static const struct hid_device_id hid_have_special_driver[] = {#endif #if IS_ENABLED(CONFIG_HID_STEELSERIES) { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1) }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_ARCTIS_1) }, + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_ARCTIS_9) }, #endif #if IS_ENABLED(CONFIG_HID_SUNPLUS) { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
drivers/hid/hid-steelseries.c +39 -70
231 lines not on this page · raw message
--
Quoted 22 lines · Jeongjun Park
steelseries_srws1_probe()still does not usedevm_kzalloc()anddevm_led_classdev_register(), so there is a lot of code to safely manage heap, which reduces readability and may cause memory leaks due to minor patch mistakes in the future.Therefore, it should be changed to use
devm_kzalloc()anddevm_led_classdev_register()to easily and safely manage heap.Also, the current steelseries driver mainly checks
sd->quriksto determine which product a specific HID device is, which is not the correct way.
remove(), unlikeprobe(), does not receive structhid_device_idas an argument, so it must check hdev unconditionally to know which product it is.However, since struct
steelseries_deviceand structsteelseries_srws1_datahave different structures, if SRWS1 is removed inremove(), convertshdev->dev, which is initialized to structsteelseries_srws1_data, to structsteelseries_deviceand uses it. This causes various memory-related bugs as completely unexpected values exist in member variables of the structure.
Quoted 6 lines
Therefore, in order to modify
probe()andremove()to work properly, Arctis 1, 9 should be added toHID_USB_DEVICEand some functions should be modified to checkhdev->productwhen determining HID device product.Fixes a0c76896c3fb ("HID: steelseries: Add support for Arctis 1 XBox")Signed-off-by Jeongjun Park <[email protected]>
Applied to hid.git#for-6.18/steelseries, thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs
Hello Jiri,
Quoted 25 lines · Jiri Kosina
Quoted 22 lines · Jeongjun Park
steelseries_srws1_probe()still does not usedevm_kzalloc()anddevm_led_classdev_register(), so there is a lot of code to safely manage heap, which reduces readability and may cause memory leaks due to minor patch mistakes in the future.Therefore, it should be changed to use
devm_kzalloc()anddevm_led_classdev_register()to easily and safely manage heap.Also, the current steelseries driver mainly checks
sd->quriksto determine which product a specific HID device is, which is not the correct way.
remove(), unlikeprobe(), does not receive structhid_device_idas an argument, so it must check hdev unconditionally to know which product it is.However, since struct
steelseries_deviceand structsteelseries_srws1_datahave different structures, if SRWS1 is removed inremove(), convertshdev->dev, which is initialized to structsteelseries_srws1_data, to structsteelseries_deviceand uses it. This causes various memory-related bugs as completely unexpected values exist in member variables of the structure.
Quoted 9 lines
Quoted 6 lines
Therefore, in order to modify
probe()andremove()to work properly, Arctis 1, 9 should be added toHID_USB_DEVICEand some functions should be modified to checkhdev->productwhen determining HID device product.Fixes a0c76896c3fb ("HID: steelseries: Add support for Arctis 1 XBox")Signed-off-by Jeongjun Park <[email protected]>Applied to hid.git#for-6.18/steelseries, thanks.
I think this patch should be applied to 6.17 rc, not 6.18.
This is because while this patch primarily addresses a potential memory leak, it also addresses a memory corruption vuln that occurs when using the SRWS1 device.
Therefore, it should be patched quickly in the rc release, and the stable release, where this bug exists, should also receive this patch.
Quoted 4 lines
--
Jiri Kosina
SUSE Labs
Regards,
Jeongjun Park