]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iio: proximity: rfd77402: Fix completion race condition in IRQ mode
authorFelix Gu <ustc.gu@gmail.com>
Wed, 4 Mar 2026 14:14:32 +0000 (22:14 +0800)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 14 Mar 2026 11:15:32 +0000 (11:15 +0000)
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>
Reviewed-by: Shrikant Raskar <raskar.shree97@gmail.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/proximity/rfd77402.c

index 6afdbfca3e5a106598ec848bce31eaed0fbb40ee..81b8daf17a543713c2e1e406ef8f7216ecf5531d 100644 (file)
@@ -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);
+
        ret = i2c_smbus_write_byte_data(client, RFD77402_CMD_R,
                                        RFD77402_CMD_SINGLE |
                                        RFD77402_CMD_VALID);