Skip to contentSkip to conversation

i3c: master: svc: Fix i3c_master_get_free_addr return check

PATCH Applied Stanley Chu 4 participants 5 messages Mar 10, 2025 – Mar 18, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i3c: master: svc: Fix i3c_master_get_free_addr return check

From: Stanley Chu <[email protected]>

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")
---
 drivers/i3c/master/svc-i3c-master.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/i3c/master/svc-i3c-master.c +5 -4
index f22fb9e75142..1d1f351b9a85 100644
@@ -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);
 
 			/*
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Stanley Chu

From: Stanley Chu <[email protected]>

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.

Quoted 8 lines

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

Fixes 4008a74e0f9b ("i3c: master: svc: Fix npcm845 FIFO empty issue")

---

Quoted 39 lines
 drivers/i3c/master/svc-i3c-master.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/i3c/master/svc-i3c-master.c +5 -5
index f22fb9e75142..1d1f351b9a85 100644
@@ -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);
 
 			/*
--

2.34.1

--
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c

maintainer Applied
#2 lore raw
In reply to Stanley Chu
Quoted 9 lines · Stanley Chu

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.

[...]

Applied, thanks!

[1/1] i3c: master: svc: Fix i3c_master_get_free_addr return check

      https://git.kernel.org/abelloni/c/d6cb667b8e15

Best regards,

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw
Quoted 9 lines · Alexandre Belloni
Quoted 8 lines · Stanley Chu

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.

Quoted 13 lines
Quoted 1 line

[...]

Applied, thanks!

[1/1] i3c: master: svc: Fix i3c_master_get_free_addr return check

      https://git.kernel.org/abelloni/c/d6cb667b8e15

Best regards,

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Hi Alexandre,

I sent a fix for this issue on the 9th March, which is before the patch Stanley sent which was sent on the 10th March.

You can view my orignal patch here:

https://lore.kernel.org/all/[email protected]/

Thanks
Qasim

Quoted 5 lines
Signature · 4 lines
-- 
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#4 lore raw
Quoted 24 lines · Qasim Ijaz
Quoted 9 lines · Alexandre Belloni
Quoted 8 lines · Stanley Chu

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.

Quoted 13 lines
Quoted 1 line

[...]

Applied, thanks!

[1/1] i3c: master: svc: Fix i3c_master_get_free_addr return check

      https://git.kernel.org/abelloni/c/d6cb667b8e15

Best regards,

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Quoted 9 lines

Hi Alexandre,

I sent a fix for this issue on the 9th March, which is before the patch Stanley sent which was sent on the 10th March.

You can view my orignal patch here:

https://lore.kernel.org/all/[email protected]/

The issue is that you then resent the patch with the same topic which superseded your original patch. But the resend was missing a blank line so I could not apply it immediately and I later applied the other one.

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com