From: Jonathan Cameron <jic23@kernel.org>
To: Shrikant <raskar.shree97@gmail.com>
Cc: "Felix Gu" <ustc.gu@gmail.com>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: proximity: rfd77402: Fix completion race condition in IRQ mode
Date: Sat, 14 Mar 2026 11:17:48 +0000 [thread overview]
Message-ID: <20260314111748.3f7e3c4e@jic23-huawei> (raw)
In-Reply-To: <CAHc1_P63xwVnn1mO8Qwxq=r9L32JFdS_hqigWKU3gHMeweN9eA@mail.gmail.com>
On Mon, 9 Mar 2026 22:32:58 +0530
Shrikant <raskar.shree97@gmail.com> wrote:
> On Wed, Mar 4, 2026 at 7:44 PM Felix Gu <ustc.gu@gmail.com> wrote:
> >
> > In IRQ mode, the completion was being reinitialized after the
> > measurement command had already been sent to the hardware. This
> > created a race condition where the IRQ handler could call complete()
> > before reinit_completion() was executed. Consequently,
> > wait_for_completion_timeout() would fail to see the signal and wait
> > until it timed out.
> >
> > Move reinit_completion() to occur before the measurement command is
> > triggered to ensure the synchronization primitive is ready to
> > capture the interrupt.
> >
> > Fixes: dc81be96a73a ("iio: proximity: rfd77402: Add interrupt handling support")
> > Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> > ---
> > drivers/iio/proximity/rfd77402.c | 7 ++++---
> > 1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/iio/proximity/rfd77402.c b/drivers/iio/proximity/rfd77402.c
> > index 6afdbfca3e5a..81b8daf17a54 100644
> > --- a/drivers/iio/proximity/rfd77402.c
> > +++ b/drivers/iio/proximity/rfd77402.c
> > @@ -173,10 +173,8 @@ static int rfd77402_wait_for_result(struct rfd77402_data *data)
> > struct i2c_client *client = data->client;
> > int val, ret;
> >
> > - if (data->irq_en) {
> > - reinit_completion(&data->completion);
> > + if (data->irq_en)
> > return rfd77402_wait_for_irq(data);
> > - }
> >
> > /*
> > * As per RFD77402 datasheet section '3.1.1 Single Measure', the
> > @@ -204,6 +202,9 @@ static int rfd77402_measure(struct rfd77402_data *data)
> > if (ret < 0)
> > return ret;
> >
> > + if (data->irq_en)
> > + reinit_completion(&data->completion);
> > +
> Looks good to me.
> Reviewed-by: Shrikant Raskar <raskar.shree97@gmail.com>
>
Applied to the fixes-togreg branch of iio.git. Note I just sent a pull
request on that so will probably rebase after that (hopefully) gets
merged into char-misc-linus.
Thanks,
Jonathan
> Regards,
> Shrikant
prev parent reply other threads:[~2026-03-14 11:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 14:14 [PATCH] iio: proximity: rfd77402: Fix completion race condition in IRQ mode Felix Gu
2026-03-07 17:07 ` Jonathan Cameron
2026-03-09 17:02 ` Shrikant
2026-03-14 11:17 ` Jonathan Cameron [this message]
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=20260314111748.3f7e3c4e@jic23-huawei \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=raskar.shree97@gmail.com \
--cc=ustc.gu@gmail.com \
/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