]> www.infradead.org Git - users/hch/misc.git/commitdiff
i3c: master: svc: Fix i3c_master_get_free_addr return check
authorStanley Chu <yschu@nuvoton.com>
Mon, 10 Mar 2025 02:33:04 +0000 (10:33 +0800)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Mon, 17 Mar 2025 22:46:06 +0000 (23:46 +0100)
The return value of i3c_master_get_free_addr is assigned to a variable
with wrong type, so it can't be negative. Use a signed integer for the
return value. If the value is negative, break the process and propagate
the error code.

This commit also fixes the uninitialized symbol 'dyn_addr', reported
by Smatch static checker.

Fixes: 4008a74e0f9b ("i3c: master: svc: Fix npcm845 FIFO empty issue")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/all/029e5ac0-5444-4a8e-bca4-cec55950d2b9@stanley.mountain/
Signed-off-by: Stanley Chu <yschu@nuvoton.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Link: https://lore.kernel.org/r/20250310023304.2335792-1-yschu@nuvoton.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/i3c/master/svc-i3c-master.c

index f22fb9e75142b2c0d5c15d6c2e1509fe606e9fbc..1d1f351b9a855e7492c38fcab9ebba2fdb017004 100644 (file)
@@ -940,7 +940,7 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master,
                                        u8 *addrs, unsigned int *count)
 {
        u64 prov_id[SVC_I3C_MAX_DEVS] = {}, nacking_prov_id = 0;
-       unsigned int dev_nb = 0, last_addr = 0, dyn_addr;
+       unsigned int dev_nb = 0, last_addr = 0, dyn_addr = 0;
        u32 reg;
        int ret, i;
 
@@ -998,10 +998,11 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master,
                         * filling within a few hundred nanoseconds, which is significantly
                         * faster compared to the 64 SCL clock cycles.
                         */
-                       dyn_addr = i3c_master_get_free_addr(&master->base, last_addr + 1);
-                       if (dyn_addr < 0)
-                               return -ENOSPC;
+                       ret = i3c_master_get_free_addr(&master->base, last_addr + 1);
+                       if (ret < 0)
+                               break;
 
+                       dyn_addr = ret;
                        writel(dyn_addr, master->regs + SVC_I3C_MWDATAB);
 
                        /*