[PATCH] HID: input: throttle battery uevents

From: Dmitry Torokhov
Date: Thu Aug 10 2017 - 15:48:06 EST


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: 581c4484769e ("HID: input: map digitizer battery usage")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/hid/hid-input.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 27d8442b017d..199f6a01fc62 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -520,15 +520,21 @@ static void hidinput_cleanup_battery(struct hid_device *dev)

static void hidinput_update_battery(struct hid_device *dev, int value)
{
+ int capacity;
+
if (!dev->battery)
return;

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

- dev->battery_capacity = hidinput_scale_battery_capacity(dev, value);
- dev->battery_reported = true;
- power_supply_changed(dev->battery);
+ capacity = hidinput_scale_battery_capacity(dev, value);
+
+ if (!dev->battery_reported || capacity != dev->battery_capacity) {
+ dev->battery_capacity = capacity;
+ dev->battery_reported = true;
+ power_supply_changed(dev->battery);
+ }
}
#else /* !CONFIG_HID_BATTERY_STRENGTH */
static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
--
2.14.0.434.g98096fd7a8-goog


--
Dmitry