]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rapidio/tsi721: prevent a bad dereference in tsi721_db_dpc()
authorDan Carpenter <error27@gmail.com>
Fri, 8 May 2026 07:51:56 +0000 (10:51 +0300)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 29 May 2026 04:24:45 +0000 (21:24 -0700)
With a list_for_each() loop, if we don't find the item we are looking for
in the list, then the loop exits with the iterator, which is "dbell" in
this loop, pointing to invalid memory.

This code uses the "found" variable to determine if we have found the
doorbell we are looking for or not.  However, the problem that the "found"
variable needs to be set to false at the start of each iteration,
otherwise after the first correct doorbell, then everything is marked as
found.

Reset the "found" to false at the start of the iteration and move the
variable inside the loop.

Link: https://lore.kernel.org/af2WHMZiqMwdYveO@stanley.mountain
Fixes: 48618fb4e522 ("RapidIO: add mport driver for Tsi721 bridge")
Signed-off-by: Dan Carpenter <error27@gmail.com>
Cc: Alexandre Bounine <alex.bou9@gmail.com>
Cc: Chul Kim <chul.kim@idt.com>
Cc: Matt Porter <mporter@kernel.crashing.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/rapidio/devices/tsi721.c

index 66331e67cf4efc9e18480b391d2addc25b682364..71b87bf8c31d8554db6824e4596532dc33717a63 100644 (file)
@@ -394,7 +394,6 @@ static void tsi721_db_dpc(struct work_struct *work)
                                                    idb_work);
        struct rio_mport *mport;
        struct rio_dbell *dbell;
-       int found = 0;
        u32 wr_ptr, rd_ptr;
        u64 *idb_entry;
        u32 regval;
@@ -412,6 +411,8 @@ static void tsi721_db_dpc(struct work_struct *work)
        rd_ptr = ioread32(priv->regs + TSI721_IDQ_RP(IDB_QUEUE)) % IDB_QSIZE;
 
        while (wr_ptr != rd_ptr) {
+               int found = 0;
+
                idb_entry = (u64 *)(priv->idb_base +
                                        (TSI721_IDB_ENTRY_SIZE * rd_ptr));
                rd_ptr++;