Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Helge Bahmann" <hcb@chaoticmind.net>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH 2/2] amd-sfh-tabletmode: interpret sfh tablet mode hid report
Date: Tue, 21 Jul 2026 14:41:29 +0000	[thread overview]
Message-ID: <20260721144129.F1FA11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <14202195.uLZWGnKmhe@zephyr>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Unconditional `field->hidinput` dereference and tablet mode state corruption due to unconstrained `.event` callback.
- [High] The Kconfig symbol `INPUT_AMD_SFH_TABLETMODE` is missing a dependency on `HID`.
--

--- Patch [2]: [PATCH 2/2] amd-sfh-tabletmode: interpret sfh tablet mode hid report ---
commit 981d61514e0f554ad31b2f14f7fb391c059df340
Author: Helge Bahmann <hcb@chaoticmind.net>

amd-sfh-tabletmode: interpret sfh tablet mode hid report
    
Add a driver that hooks into the tablet mode hid reports
generated by the amd-sfh-hid driver. This enables tablet
mode switching on e.g. Asus Vivobook devices.

> diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
> index 94a753fcb64fa..5a1dacd6f7b9c 100644
> --- a/drivers/input/misc/Kconfig
> +++ b/drivers/input/misc/Kconfig
> @@ -1003,4 +1003,15 @@ config INPUT_STPMIC1_ONKEY
>  	  To compile this driver as a module, choose M here: the
>  	  module will be called stpmic1_onkey.
>  
> +config INPUT_AMD_SFH_TABLETMODE
> +	tristate "AMD sensor fusion hub tablet mode driver"

[Severity: High]
Is it possible this Kconfig entry is missing a depends on HID?

If the HID subsystem is disabled or configured as a module while this driver
is built-in, could this result in linking errors for HID core functions like
hid_register_driver() and hid_parse()?

> +	help
> +	  Say Y to enable support of the tablet mode switch driver for

[ ... ]

> diff --git a/drivers/input/misc/amd_sfh_tabletmode.c b/drivers/input/misc/amd_sfh_tabletmode.c
> new file mode 100644
> index 0000000000000..ee1207372207c
> --- /dev/null
> +++ b/drivers/input/misc/amd_sfh_tabletmode.c

[ ... ]

> +static int amd_sfh_tabletmode_event(struct hid_device *hid, struct hid_field *field,
> +				    struct hid_usage *usage, __s32 value)
> +{
> +	input_report_switch(field->hidinput->input, SW_TABLET_MODE, value);

[Severity: High]
Does this unconditionally dereference field->hidinput, which could be NULL
for unmapped usages?

Because the driver struct below lacks a .usage_table, hid_match_usage()
will default to true for all usages, meaning this callback intercepts every
incoming HID report field. This could lead to a NULL pointer dereference,
and will also blindly emit a SW_TABLET_MODE event for any report, causing
standard buttons or battery reports to randomly toggle tablet mode.

Since .input_mapping already maps the usage to EV_SW, allowing the generic
HID core to automatically report the event, could this callback be removed
entirely?

> +
> +	return 0;
> +}
> +
> +static const struct hid_device_id amd_sfh_tabletmode_devices[] = {
> +	{ HID_DEVICE(BUS_AMD_SFH, HID_GROUP_GENERIC, AMD_SFH_HID_VENDOR, AMD_SFH_HID_PRODUCT) },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(hid, amd_sfh_tabletmode_devices);
> +
> +static struct hid_driver amd_sfh_tabletmode_driver = {
> +	.name = "amd_sfh_tabletmode",
> +	.id_table = amd_sfh_tabletmode_devices,
> +	.probe = amd_sfh_tabletmode_probe,
> +	.remove = amd_sfh_tabletmode_remove,
> +	.input_mapping = amd_sfh_tabletmode_input_mapping,
> +	.event = amd_sfh_tabletmode_event,

[Severity: High]
Should this struct include a .usage_table?

Without it, all device usages are routed to the .event callback above.

> +};

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/ecadaac8-e222-420a-ac5b-4d529fb3317e@amd.com?part=2

  reply	other threads:[~2026-07-21 14:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-27  6:22 [PATCH] amd-sfh-hid: tablet mode switch and asus quirk Helge Bahmann
2026-05-12 16:06 ` Jiri Kosina
2026-05-12 17:09   ` Basavaraj Natikar
2026-05-14  7:59   ` Helge Bahmann
2026-06-10 17:12     ` Basavaraj Natikar
2026-06-12  4:22       ` Helge Bahmann
2026-07-21 14:28       ` [PATCH 0/2] asus vivobook tablet mode Helge Bahmann
2026-07-21 17:52         ` Basavaraj Natikar
2026-07-21 14:29       ` [PATCH 1/2] amd-sfh-hid: tablet mode hid report and asus quirk Helge Bahmann
2026-07-21 14:47         ` sashiko-bot
2026-07-21 14:29       ` [PATCH 2/2] amd-sfh-tabletmode: interpret sfh tablet mode hid report Helge Bahmann
2026-07-21 14:41         ` sashiko-bot [this message]
2026-06-10 16:33 ` [PATCH] amd-sfh-hid: tablet mode switch and asus quirk Jiri Kosina

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=20260721144129.F1FA11F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=hcb@chaoticmind.net \
    --cc=linux-input@vger.kernel.org \
    --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