From patchwork Thu Aug 10 19:47:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9894561 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A3CAC60348 for ; Thu, 10 Aug 2017 19:48:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D57F28B7F for ; Thu, 10 Aug 2017 19:48:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81E7028B83; Thu, 10 Aug 2017 19:48:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F6AD28B7F for ; Thu, 10 Aug 2017 19:48:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753169AbdHJTsA (ORCPT ); Thu, 10 Aug 2017 15:48:00 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36945 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753122AbdHJTr7 (ORCPT ); Thu, 10 Aug 2017 15:47:59 -0400 Received: by mail-pf0-f196.google.com with SMTP id p13so1516822pfd.4; Thu, 10 Aug 2017 12:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=HrMrHaFGUxdu6GkjZln4eDJO9euOF9vo8xjh2jvWZJ8=; b=Xy/ZdiscN26iKCRX5QTTj6snYtoSVQW6YBA0I8/EbXl+DcKwpQ1dfRN9IPpSHqYH1O 7j+Xu+tzGycwtRfhAamLDQb0uIYydV9c1RHXIEJFyCuwmpe+H4K6tj/jhAPfXFRPdAyX aOLIP5Kb2j+M20Cx4zqgMvJ3fmuYHC7+PH6Dh9S+gxotiV3nnZVkO5AFh8IyIWpACWXP KsHOKBMtUPLFrkqPL+rQDTQfcWLY5cWOl5GxmO6xzeRlgUTnDtGvg+T9oqGIMBOsknTo rbJvmUF7RHYmMfDBmHA5mqkZWSszUseTkpXCvfIsPIWMk5YHdvMp0HW/p8T8s7bdF2ka X/Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=HrMrHaFGUxdu6GkjZln4eDJO9euOF9vo8xjh2jvWZJ8=; b=EqSiWmsA4XH3o5ffL7XLuowKshpYH5Dr4dmjngOOQD5IC1eHCHDEBx/FqCj/RnbCyc 6m4VUQLcmYdseDMci6jHcmV7tJbF4rW5nA9ymplrKftjN30gIgU+OFqZxDY4KbZ4p2O2 ACUktffTQNpMP1ivXvOPq8dvUm+CV7ZgnweJW0XHv87aSv22OuOSRgwMtCcO96J2R3WL r4lyxHCsymKyjIESbet8ghCf/jYCW3ILNxKsc3GXWSc1oXmvGQL6fooPr8LoIXcC57sN EB/qjyI63Lo7/i6VreBZWd2hHQ0oWO+9HrPL47v/EvhpKAFcKhXeHkcQFwY+yTMRxqES lX5A== X-Gm-Message-State: AHYfb5ih3lV5Pbyy7Xnzid1V8THlhxpuGWME9ryjxq+7nABJtIZCm4Me 31Yy1QL3xOr+pjg4LUw= X-Received: by 10.84.213.2 with SMTP id f2mr14930645pli.192.1502394478888; Thu, 10 Aug 2017 12:47:58 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1611:6dd9:c49a:3023:1379]) by smtp.gmail.com with ESMTPSA id c80sm11505169pfb.141.2017.08.10.12.47.58 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 10 Aug 2017 12:47:58 -0700 (PDT) Date: Thu, 10 Aug 2017 12:47:56 -0700 From: Dmitry Torokhov To: Jiri Kosina Cc: Benjamin Tissoires , Jason Gerecke , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: input: throttle battery uevents Message-ID: <20170810194756.GA15567@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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,