lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <r20q42n6-n65r-3151-s194-10222o3o6s6s@xreary.bet>
Date: Tue, 14 Oct 2025 12:25:25 +0200 (CEST)
From: Jiri Kosina <jikos@...nel.org>
To: Dmitry Torokhov <dmitry.torokhov@...il.com>
cc: Benjamin Tissoires <bentiss@...nel.org>, 
    卢国宏 <luguohong@...omi.com>, kenalba@...gle.com, 
    linux-input@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] HID: hid-input: only ignore 0 battery events for
 digitizers

On Thu, 9 Oct 2025, Dmitry Torokhov wrote:

> Commit 581c4484769e ("HID: input: map digitizer battery usage") added
> handling of battery events for digitizers (typically for batteries
> presented in styli). Digitizers typically report correct battery levels
> only when stylus is actively touching the surface, and in other cases
> they may report battery level of 0. To avoid confusing consumers of the
> battery information the code was added to filer out reports with 0
> battery levels.
> 
> However there exist other kinds of devices that may legitimately report
> 0 battery levels. Fix this by filtering out 0-level reports only for
> digitizer usages, and continue reporting them for other kinds of devices
> (Smart Batteries, etc).
> 
> Reported-by: 卢国宏 <luguohong@...omi.com>
> Tested-by: 卢国宏 <luguohong@...omi.com>
> Fixes: 581c4484769e ("HID: input: map digitizer battery usage")
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@...il.com>
> ---
>  drivers/hid/hid-input.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
> index ff1784b5c2a4..ba3f6655af9e 100644
> --- a/drivers/hid/hid-input.c
> +++ b/drivers/hid/hid-input.c
> @@ -595,14 +595,18 @@ static void hidinput_cleanup_battery(struct hid_device *dev)
>  	dev->battery = NULL;
>  }
>  
> -static void hidinput_update_battery(struct hid_device *dev, int value)
> +static void hidinput_update_battery(struct hid_device *dev,
> +				    unsigned int usage, int value)
>  {
>  	int capacity;
>  
>  	if (!dev->battery)
>  		return;
>  
> -	if (value == 0 || value < dev->battery_min || value > dev->battery_max)
> +	if ((usage & HID_USAGE_PAGE) == HID_UP_DIGITIZER && value == 0)
> +		return;
> +
> +	if (value < dev->battery_min || value > dev->battery_max)
>  		return;
>  
>  	capacity = hidinput_scale_battery_capacity(dev, value);
> @@ -1518,7 +1522,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
>  		bool handled = hidinput_set_battery_charge_status(hid, usage->hid, value);
>  
>  		if (!handled)
> -			hidinput_update_battery(hid, value);
> +			hidinput_update_battery(hid, usage->hid, value);
>  
>  		return;

Hi Dmitry,

thanks for the fix. It doesn't apply cleanly on a reasonably recent tree 
though, as since e94536e1d1818b09 we're already propagating usage to 
hidinput_update_battery(), and we're issuing explicit call to 
power_supply_changed() as well.

Could you please refresh on a more recent codebase and resubmit? I could 
do that myself, but I guess you also have a way to test the patch with 
your use-case ... ?

Thanks,

-- 
Jiri Kosina
SUSE Labs


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ