[PATCH v2 32/33] HID: logitech-hidpp: manage ps_attribute_group with devm_device_add_group()
From: Dmitry Torokhov
Date: Wed Nov 11 2026 - 02:07:28 EST
Managing the power-supply sysfs attribute group manually requires
explicit cleanup in both probe failure paths and device removal, even
though all surrounding device state uses devres.
Switch to devm_device_add_group() while keeping synchronous creation
before connecting subdrivers and non-fatal warning behavior on failure.
Drop the manual removal calls, eliminate the empty start-failure unwind
label in probe, and simplify device removal accordingly.
Tested-by: Gideon Heinz <gideonheinz02@xxxxxxxxx>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/hid/hid-logitech-hidpp.c | 35 +++++++++++++++--------------------
1 file changed, 15 insertions(+), 20 deletions(-)
diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index be3c2649b0e3..019b917c3b90 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -4638,7 +4638,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
return ret;
/* indicates we are handling the battery properties in the kernel */
- ret = sysfs_create_group(&hdev->dev.kobj, &ps_attribute_group);
+ ret = devm_device_add_group(&hdev->dev, &ps_attribute_group);
if (ret)
hid_warn(hdev, "Cannot allocate sysfs group for %s\n",
hdev->name);
@@ -4652,7 +4652,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
ret = hid_hw_start(hdev, 0);
if (ret) {
hid_err(hdev, "hw start failed\n");
- goto hid_hw_start_fail;
+ return ret;
}
ret = hid_hw_open(hdev);
@@ -4711,8 +4711,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
hid_hw_close(hdev);
hid_hw_open_fail:
hid_hw_stop(hdev);
-hid_hw_start_fail:
- sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
return ret;
}
@@ -4721,22 +4719,19 @@ static void hidpp_remove(struct hid_device *hdev)
struct hidpp_device *hidpp = hid_get_drvdata(hdev);
bool claimed_input;
- if (!hidpp)
- return hid_hw_stop(hdev);
-
- sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
-
- claimed_input = hdev->claimed & HID_CLAIMED_INPUT;
- hdev->claimed &= ~HID_CLAIMED_INPUT;
- if (claimed_input)
- hidpp->input = NULL;
-
- hid_device_io_start(hdev);
- disable_work_sync(&hidpp->work);
- disable_work_sync(&hidpp->reset_hi_res_work);
- if (claimed_input)
- hidinput_disconnect(hdev);
- hid_device_io_stop(hdev);
+ if (hidpp) {
+ claimed_input = hdev->claimed & HID_CLAIMED_INPUT;
+ hdev->claimed &= ~HID_CLAIMED_INPUT;
+ if (claimed_input)
+ hidpp->input = NULL;
+
+ hid_device_io_start(hdev);
+ disable_work_sync(&hidpp->work);
+ disable_work_sync(&hidpp->reset_hi_res_work);
+ if (claimed_input)
+ hidinput_disconnect(hdev);
+ hid_device_io_stop(hdev);
+ }
hid_hw_stop(hdev);
}
--
2.56.0.542.g3ef89b7020-goog