From: srinivas pandruvada <srinivas.pandruvada@linux.intel.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: jikos@kernel.org, bentiss@kernel.org,
linux-input@vger.kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, simeon@maryasin.name,
lixu.zhang@intel.com, crofts@kernel.org
Subject: Re: [PATCH v2 1/7] HID: sensor: hub: Synchronize callback removal with raw events
Date: Mon, 09 Nov 2026 09:32:06 -0800 [thread overview]
Message-ID: <4a773d0d614a7bed29fc7e2ab7f6e40d63407531.camel@linux.intel.com> (raw)
In-Reply-To: <20261107201319.0f496662@jic23-hlaptop>
On Sat, 2026-11-07 at 20:13 +0000, Jonathan Cameron wrote:
> On Wed, 4 Nov 2026 12:13:57 -0800
> Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> wrote:
>
> > Raw-event processing holds pdata->lock across callback lookup and
> > invocation, and takes dyn_callback_lock during lookup. Removal must
> > prevent both active callbacks and future lookups before client
> > state can
> > be released.
> >
> > Take pdata->lock before dyn_callback_lock, matching raw-event
> > order,
> > and unlink the callback while holding both locks. This ensures
> > active
> > raw-event callbacks have finished and prevents future lookups.
> >
> > Fixes: 401ca24fb34a ("HID: sensors: introduce sensor framework")
> > Reported-by: Семён Марьясин <simeon@maryasin.name>
> > Closes:
> > https://lore.kernel.org/all/CAM2dg7ewfVJSP4rFyhkCB1Rmd1+X56sAg=eUdbPthG2xrLqwQQ@mail.gmail.com/
> > Signed-off-by: Srinivas Pandruvada
> > <srinivas.pandruvada@linux.intel.com>
>
> Maybe a minimal fix is good for now, but I do note that we can
> make this code nicer with some guard() magic.
Yes guard() will be better here.
guard() can be a different cleanup as this should be done in whole
driver instead of this one function here. I will do a clean up patch
instead of fixes.
Thanks,
Srinivas
>
> Perhaps a follow up series to tidy this up.
>
> Things are getting very messy around this driver wrt to fix vs
> cleanup. Hopefully it won't cause too much of a problem in next
> until I can merge the fixes back after they go upstream.
>
> > ---
> > drivers/hid/hid-sensor-hub.c | 7 +++++--
> > 1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-
> > hub.c
> > index 6470a290ebfc..0c4884c5821f 100644
> > --- a/drivers/hid/hid-sensor-hub.c
> > +++ b/drivers/hid/hid-sensor-hub.c
> > @@ -173,7 +173,9 @@ int sensor_hub_remove_callback(struct
> > hid_sensor_hub_device *hsdev,
> > struct sensor_hub_data *pdata = hid_get_drvdata(hsdev-
> > >hdev);
> > unsigned long flags;
> >
> > - spin_lock_irqsave(&pdata->dyn_callback_lock, flags);
> > + /* Serialize callback removal with raw-event callback
> > execution. */
> > + spin_lock_irqsave(&pdata->lock, flags);
> > + spin_lock(&pdata->dynfunction_callback_lock);
>
> Do both of those with appropriate guard()
>
> > list_for_each_entry(callback, &pdata->dyn_callback_list,
> > list)
> > if (callback->usage_id == usage_id &&
> > callback->hsdev ==
> > hsdev) {
> I'd just go long!
> if (callback->usage_id == usage_id && callback-
> >hsdev == hsdev) {
>
>
> > @@ -181,7 +183,8 @@ int sensor_hub_remove_callback(struct
> > hid_sensor_hub_device *hsdev,
> > kfree(callback);
> > break;
> And we can return here.
>
> > }
> > - spin_unlock_irqrestore(&pdata->dyn_callback_lock, flags);
> > + spin_unlock(&pdata->dyn_callback_lock);
> > + spin_unlock_irqrestore(&pdata->lock, flags);
> >
> > return 0;
> > }
next prev parent reply other threads:[~2026-11-09 17:32 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 20:13 [PATCH v2 0/7] HID: sensor: custom: use-after-freec after remove Srinivas Pandruvada
2026-11-04 20:13 ` [PATCH v2 1/7] HID: sensor: hub: Synchronize callback removal with raw events Srinivas Pandruvada
2026-11-05 9:56 ` Joshua Crofts
2026-11-07 20:13 ` Jonathan Cameron
2026-11-09 17:32 ` srinivas pandruvada [this message]
2026-11-04 20:13 ` [PATCH v2 2/7] HID: sensor: custom: Set owner for misc device Srinivas Pandruvada
2026-11-05 9:57 ` Joshua Crofts
2026-11-04 20:13 ` [PATCH v2 3/7] HID: sensor: custom: Disable sensor before hub close on removal Srinivas Pandruvada
2026-11-05 10:21 ` Joshua Crofts
2026-11-04 20:14 ` [PATCH v2 4/7] HID: sensor: custom: Fix state lifetime during removal Srinivas Pandruvada
2026-11-07 20:21 ` Jonathan Cameron
2026-11-04 20:14 ` [PATCH v2 5/7] HID: sensor: custom: Serialize misc device reads Srinivas Pandruvada
2026-11-04 20:14 ` [PATCH v2 6/7] HID: sensor: custom: Register enable attribute after misc device Srinivas Pandruvada
2026-11-07 20:16 ` Jonathan Cameron
2026-11-09 0:47 ` Srinivas Pandruvada
2026-11-04 20:14 ` [PATCH v2 7/7] HID: sensor: hub: Remove clients before stopping hardware Srinivas Pandruvada
2026-11-07 20:08 ` [PATCH v2 0/7] HID: sensor: custom: use-after-freec after remove Jonathan Cameron
2026-11-09 8:52 ` Zhang, Lixu
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=4a773d0d614a7bed29fc7e2ab7f6e40d63407531.camel@linux.intel.com \
--to=srinivas.pandruvada@linux.intel.com \
--cc=bentiss@kernel.org \
--cc=crofts@kernel.org \
--cc=jic23@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lixu.zhang@intel.com \
--cc=simeon@maryasin.name \
/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
all inboxes | Powered by JetHome®