Skip to content

Commit 0152b29

Browse files
dtorJiri Kosina
authored andcommitted
HID: input: throttle battery uevents
The power_supply subsystem tends to emit uevent every time power_supply_changed() is called, so we should call this API only when battery strength reported by the device is actually different from the previous readings, otherwise we'll drown the system in uevents. Fixes: 581c448 ("HID: input: map digitizer battery usage") Signed-off-by: Dmitry Torokhov <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 0922386 commit 0152b29

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

drivers/hid/hid-input.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,15 +520,21 @@ static void hidinput_cleanup_battery(struct hid_device *dev)
520520

521521
static void hidinput_update_battery(struct hid_device *dev, int value)
522522
{
523+
int capacity;
524+
523525
if (!dev->battery)
524526
return;
525527

526528
if (value == 0 || value < dev->battery_min || value > dev->battery_max)
527529
return;
528530

529-
dev->battery_capacity = hidinput_scale_battery_capacity(dev, value);
530-
dev->battery_reported = true;
531-
power_supply_changed(dev->battery);
531+
capacity = hidinput_scale_battery_capacity(dev, value);
532+
533+
if (!dev->battery_reported || capacity != dev->battery_capacity) {
534+
dev->battery_capacity = capacity;
535+
dev->battery_reported = true;
536+
power_supply_changed(dev->battery);
537+
}
532538
}
533539
#else /* !CONFIG_HID_BATTERY_STRENGTH */
534540
static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,

0 commit comments

Comments
 (0)