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

From: Dmitry Torokhov

Date: Mon Nov 09 2026 - 01:13: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.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/hid/hid-logitech-hidpp.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 7ff7b7d8e2d2..83a408f91d8b 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -4739,7 +4739,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);
@@ -4753,7 +4753,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);
@@ -4811,8 +4811,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;
}

@@ -4820,13 +4818,10 @@ static void hidpp_remove(struct hid_device *hdev)
{
struct hidpp_device *hidpp = hid_get_drvdata(hdev);

- if (!hidpp)
- return hid_hw_stop(hdev);
-
- sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
-
- disable_work_sync(&hidpp->work);
- disable_work_sync(&hidpp->reset_hi_res_work);
+ if (hidpp) {
+ disable_work_sync(&hidpp->work);
+ disable_work_sync(&hidpp->reset_hi_res_work);
+ }

hid_hw_stop(hdev);
}
--
2.56.0.506.g506a7eabc5-goog