[PATCH v3 17/18] HID: logitech-hidpp: manage ps_attribute_group with devm_device_add_group()

From: Dmitry Torokhov

Date: Fri Nov 20 2026 - 03:46:45 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 261022e4088b..5c2d967246e9 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -4625,7 +4625,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);
@@ -4639,7 +4639,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);
@@ -4698,8 +4698,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;
}

@@ -4708,22 +4706,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.1.750.gf70dc682cf-goog