From: "Pandruvada, Srinivas" <srinivas.pandruvada@intel.com>
To: "ch@murgatroid.com" <ch@murgatroid.com>
Cc: "joshua.crofts1@gmail.com" <joshua.crofts1@gmail.com>,
"dlechner@baylibre.com" <dlechner@baylibre.com>,
"nuno.sa@analog.com" <nuno.sa@analog.com>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"jic23@kernel.org" <jic23@kernel.org>,
"jikos@kernel.org" <jikos@kernel.org>,
"andy@kernel.org" <andy@kernel.org>,
"bentiss@kernel.org" <bentiss@kernel.org>,
"stable@vger.kernel.org" <stable@vger.kernel.org>,
"Zhang, Lixu" <lixu.zhang@intel.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-input@vger.kernel.org" <linux-input@vger.kernel.org>
Subject: Re: [PATCH v3 1/3] HID: hid-sensor-hub: Synchronize callback removal with raw events
Date: Mon, 26 Oct 2026 15:17:31 +0000 [thread overview]
Message-ID: <76a9ab9657249508821a0f023f56f1d1b2da61ac.camel@intel.com> (raw)
In-Reply-To: <CACw0PsaJr6E0Y3AXoGKDUiKp4vsaA+GEJjPqEhYuSoKqDp1jUA@mail.gmail.com>
On Wed, 2026-10-21 at 18:58 -0700, Christopher Hoover wrote:
> > Is this issue actually reproduced or it was found by some AI
> > tools?
>
> Real life. I wedged my kernel several times with an MCP2221A usb
> i2c bridge.
>
>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> On Wed, Oct 21, 2026 at 6:22 PM Srinivas Pandruvada
> <srinivas.pandruvada@linux.intel.com> wrote:
> >
> > On Sun, 2026-10-18 at 19:34 -0700, Christopher Hoover wrote:
> > > sensor_hub_raw_event() holds pdata->lock while it looks a
> > > callback up
> > > in dyn_callback_list and calls its capture_sample() and
> > > send_event().
> > > sensor_hub_remove_callback() takes only dyn_callback_lock, so it
> > > can
> > > unlink a callback and return while another CPU is between the
> > > lookup
> > > and the call. The sensor drivers remove their callback in
> > > .remove()
> >
> > Two spaces before "The".
> >
> > > and keep the struct hid_sensor_hub_callbacks in memory that
> > > devres
> > > frees right after, so a report racing an unbind can call through
> > > freed function pointers.
> > >
> > > Take pdata->lock in sensor_hub_remove_callback() too, outside
> > > dyn_callback_lock as in sensor_hub_raw_event(), so the removal
> > > waits
> > > for a report in flight. pdata->lock is otherwise only taken in
> > > sensor_hub_raw_event(), and callbacks are removed from process
> > > context.
> > >
> > > Fixes: 401ca24fb34a ("HID: sensors: introduce sensor framework")
> > > Cc: stable@vger.kernel.org
> > > Signed-off-by: Christopher Hoover <ch@murgatroid.com>
> > > Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
> > > ---
> > > drivers/hid/hid-sensor-hub.c | 12 ++++++++++--
> > > 1 file changed, 10 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-
> > > sensor-
> > > hub.c
> > > index 6470a290ebfc..7cf9f398592e 100644
> > > --- a/drivers/hid/hid-sensor-hub.c
> > > +++ b/drivers/hid/hid-sensor-hub.c
> > > @@ -173,7 +173,14 @@ 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);
> > > + /*
> > > + * sensor_hub_raw_event() holds pdata->lock while it looks
> > > up a
> > > + * callback and calls it. Taking it here too means no
> > > report is
> > > + * still using the callback once it is unlinked, so its
> > > owner may
> > > + * free it as soon as this returns.
> > > + */
> > > + spin_lock_irqsave(&pdata->lock, flags);
> > > + spin_lock(&pdata->dyn_callback_lock);
> > > list_for_each_entry(callback, &pdata->dyn_callback_list,
> > > list)
> > > if (callback->usage_id == usage_id &&
> > > callback->hsdev ==
> > > hsdev) {
> > > @@ -181,7 +188,8 @@ int sensor_hub_remove_callback(struct
> > > hid_sensor_hub_device *hsdev,
> > > kfree(callback);
> > > break;
> > > }
> > > - spin_unlock_irqrestore(&pdata->dyn_callback_lock, flags);
> > > + spin_unlock(&pdata->dyn_callback_lock);
> > > + spin_unlock_irqrestore(&pdata->lock, flags);
> > >
> >
> > The patch looks fine. Is this issue actually reproduced or it was
> > found
> > by some AI tools?
> >
> > Thanks,
> > Srinivas
> >
> > > return 0;
> > > }
next prev parent reply other threads:[~2026-10-26 15:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 2:34 [PATCH v3 0/3] iio: hid-sensors: fix shared callbacks in temperature and humidity Christopher Hoover
2026-10-19 2:34 ` [PATCH v3 1/3] HID: hid-sensor-hub: Synchronize callback removal with raw events Christopher Hoover
2026-10-22 1:21 ` Srinivas Pandruvada
2026-10-22 1:58 ` Christopher Hoover
2026-10-26 15:17 ` Pandruvada, Srinivas [this message]
2026-10-22 14:13 ` Andy Shevchenko
2026-10-19 2:34 ` [PATCH v3 2/3] iio: temperature: hid-sensor-temperature: Use per-instance callbacks Christopher Hoover
2026-10-19 10:57 ` Andy Shevchenko
2026-10-19 2:34 ` [PATCH v3 3/3] iio: humidity: hid-sensor-humidity: " Christopher Hoover
2026-10-19 10:58 ` Andy Shevchenko
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=76a9ab9657249508821a0f023f56f1d1b2da61ac.camel@intel.com \
--to=srinivas.pandruvada@intel.com \
--cc=andy@kernel.org \
--cc=bentiss@kernel.org \
--cc=ch@murgatroid.com \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=jikos@kernel.org \
--cc=joshua.crofts1@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lixu.zhang@intel.com \
--cc=nuno.sa@analog.com \
--cc=stable@vger.kernel.org \
/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®