Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Basavaraj Natikar" <Basavaraj.Natikar@amd.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v2 4/5] HID: amd_sfh: Register tablet-mode auxiliary device
Date: Mon, 03 Aug 2026 15:16:53 +0000	[thread overview]
Message-ID: <20260803151654.66E9F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260803145801.3801862-5-Basavaraj.Natikar@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The tablet-mode auxiliary device is unregistered in the devres cleanup phase, which occurs after the parent driver has manually shut down the hardware in its `.remove` callback, creating a Use-After-Teardown window.
--

--- Patch [4]: [PATCH v2 4/5] HID: amd_sfh: Register tablet-mode auxiliary device ---
commit cb1f4966427e04f4389572394e9a4fb57915128b
Author: Basavaraj Natikar <Basavaraj.Natikar@amd.com>

HID: amd_sfh: Register tablet-mode auxiliary device
    
Register an auxiliary device when the operating-mode sensor is present,
so a dedicated input driver can bind to it and report the device posture.
This keeps the input handling out of the sensor transport driver.

> diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
> index 4b1cd260410d1..f6f016c8c6787 100644
> --- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
> +++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c
[ ... ]
> @@ -389,6 +391,50 @@ static const struct attribute_group *amd_sfh_groups[] = {
[ ... ]
> +static void amd_sfh_maybe_register_tm(struct amd_mp2_dev *mp2)
> +{
[ ... ]
> +	mp2->tm_auxdev = adev;
> +	if (devm_add_action_or_reset(&mp2->pdev->dev, amd_sfh_tm_cleanup, mp2))
> +		dev_warn(&mp2->pdev->dev, "tabletmode cleanup registration failed\n");
> +}
[ ... ]
> @@ -424,6 +471,7 @@ static void sfh_init_work(struct work_struct *work)
[ ... ]
>  static void amd_sfh_remove(struct pci_dev *pdev)
>  {
>  	struct amd_mp2_dev *mp2 = pci_get_drvdata(pdev);
>  
>  	flush_work(&mp2->work);
>  	if (mp2->init_done)
>  		mp2->mp2_ops->remove(mp2);

[Severity: High]
Does this create a use-after-teardown window on device unbind?

Because the tablet-mode auxiliary device cleanup is registered via
devm_add_action_or_reset() in amd_sfh_maybe_register_tm(), the auxiliary
device is only destroyed during the devres release phase.

Since devres cleanup runs after amd_sfh_remove() completes,
mp2->mp2_ops->remove(mp2) manually tears down the underlying hardware before
the auxiliary device is destroyed.

If the auxiliary driver's remove callback or userspace attempts to
interact with the device during this window between amd_sfh_remove() and the
devres cleanup phase, could they end up accessing disabled hardware?

>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260803145801.3801862-1-Basavaraj.Natikar@amd.com?part=4

  reply	other threads:[~2026-08-03 15:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 14:57 [PATCH v2 0/5] Add SW_TABLET_MODE support for AMD SFH convertibles Basavaraj Natikar
2026-08-03 14:57 ` [PATCH v2 1/5] HID: amd_sfh: Track MP2 version explicitly Basavaraj Natikar
2026-08-03 14:57 ` [PATCH v2 2/5] HID: amd_sfh: Serialize access to the shared emp2 pointer Basavaraj Natikar
2026-08-03 14:57 ` [PATCH v2 3/5] HID: amd_sfh: Add accessor to read the operating-mode sensor Basavaraj Natikar
2026-08-03 14:58 ` [PATCH v2 4/5] HID: amd_sfh: Register tablet-mode auxiliary device Basavaraj Natikar
2026-08-03 15:16   ` sashiko-bot [this message]
2026-08-03 14:58 ` [PATCH v2 5/5] Input: misc: Add AMD SFH tablet-mode switch driver Basavaraj Natikar
2026-08-03 16:18   ` Dmitry Torokhov
2026-08-03 17:42     ` Basavaraj Natikar

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=20260803151654.66E9F1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Basavaraj.Natikar@amd.com \
    --cc=dmitry.torokhov@gmail.com \
    --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