Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aldo Ariel Panzardo" <qwe.aldo@gmail.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v3] HID: wacom: validate battery range before scaling
Date: Fri, 06 Nov 2026 21:44:54 +0000	[thread overview]
Message-ID: <sashiko-outbox-202297@kernel.org> (raw)
In-Reply-To: <20261106213526.3393779-1-qwe.aldo@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] HID: wacom: out-of-range battery values dropped in
  wacom_wac_event()
--

commit d917c200b45c05631d5073d9e5d68f13f31acf
Author: Aldo Ariel Panzardo <qwe.aldo@gmail.com>

HID: wacom: validate battery range before scaling

This commit moves battery percentage scaling into a helper that checks for
a non-positive logical range, subtracts the logical minimum, and clamps the
computed percentage to [0, 100].

> diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
> index 361738bb87253..36bab07a72dba 100644
> --- a/drivers/hid/wacom_wac.c
> +++ b/drivers/hid/wacom_wac.c
> @@ -1960,6 +1960,16 @@ static void wacom_wac_battery_usage_mapping(struct hid_device *hdev,
>  	return;
>  }
>  
> +static __s32 wacom_wac_battery_percentage(struct hid_field *field, __s32 value)
> +{
> +	__s32 range = field->logical_maximum - field->logical_minimum;
> +
> +	if (range <= 0)
> +		return 0;
> +
> +	return clamp_val((value - field->logical_minimum) * 100 / range, 0, 100);
> +}

[Severity: Medium]
Can an out-of-range battery reading ever reach this clamp_val()?

wacom_wac_battery_percentage() is only called from wacom_wac_battery_event(),
whose sole caller wacom_wac_event() drops any value outside the logical
limits before checking WACOM_BATTERY_USAGE():

drivers/hid/wacom_wac.c:wacom_wac_event() {
    ...
	if (value > field->logical_maximum || value < field->logical_minimum)
		return;

	/* usage tests must precede field tests */
	if (WACOM_BATTERY_USAGE(usage))
		wacom_wac_battery_event(hdev, field, usage, value);
    ...
}

As a result, battery reports outside [field->logical_minimum,
field->logical_maximum] are still discarded in wacom_wac_event() without
setting WACOM_QUIRK_BATTERY or updating battery_capacity, and value is
already within bounds whenever wacom_wac_battery_percentage() runs.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261106213526.3393779-1-qwe.aldo@gmail.com?part=1

  reply	other threads:[~2026-11-06 21:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15  4:12 [PATCH] HID: wacom: validate battery range before scaling Aldo Ariel Panzardo
2026-09-15  4:20 ` sashiko-bot
2026-09-15  4:25 ` [PATCH v2] " Aldo Ariel Panzardo
2026-11-06 19:48   ` Jason Gerecke
2026-11-06 21:35     ` [PATCH v3] " Aldo Ariel Panzardo
2026-11-06 21:44       ` sashiko-bot [this message]
2026-11-07  1:26       ` [PATCH v4] " Aldo Ariel Panzardo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-202297@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=qwe.aldo@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox