[PATCH 5/5] HID: UNCTRL: only report to userspace on battery changes
From: Bishwa Bhusan Saha via B4 Relay
Date: Mon Oct 12 2026 - 16:16:20 EST
From: Bishwa Bhusan Saha <contact@xxxxxxxxxxxxxx>
This patch calls power_supply_changed() only when the reported
capacity or mode actually changes.
Signed-off-by: Bishwa Bhusan Saha <contact@xxxxxxxxxxxxxx>
Assisted-by: GLM:glm-5.3
---
drivers/hid/hid-unctrl-m1.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/hid-unctrl-m1.c b/drivers/hid/hid-unctrl-m1.c
index ff15384c0..df283cbae 100644
--- a/drivers/hid/hid-unctrl-m1.c
+++ b/drivers/hid/hid-unctrl-m1.c
@@ -324,6 +324,8 @@ static int unctrl_raw_event(struct hid_device *hdev, struct hid_report *report,
{
struct unctrl_dev *dev = hid_get_drvdata(hdev);
struct power_supply *battery = NULL;
+ bool changed;
+ u8 old_capacity, old_mode;
if (!dev || size < 8)
return 0;
@@ -338,14 +340,21 @@ static int unctrl_raw_event(struct hid_device *hdev, struct hid_report *report,
scoped_guard(spinlock_irqsave, &dev->lock) {
/* the receiver reports 0% while the mouse is switched off */
+ old_capacity = dev->battery_capacity;
+ old_mode = dev->mode;
+
dev->battery_capacity = min_t(u8, data[4], 100);
dev->mode = data[5];
dev->online = dev->battery_capacity != 0;
+
+ changed = dev->battery_capacity != old_capacity ||
+ dev->mode != old_mode;
+
battery = dev->battery;
}
/* only schedules a work, so this is safe from the completion path */
- if (battery)
+ if (battery && changed)
power_supply_changed(battery);
return 0;
--
2.56.0