Skip to contentSkip to conversation

i3c: master: svc: fix signed/unsigned mismatch in dynamic address assignment

PATCH In review Qasim Ijaz 3 participants 5 messages Mar 17, 2025 – Mar 20, 2025

Subsystems (3)
lore
Share & tools
lore

Qasim Ijaz

author
#0 lore raw

PATCH 1/1 i3c: master: svc: fix signed/unsigned mismatch in dynamic address assignment

svc_i3c_master_do_daa_locked() declares dyn_addr as an unsigned int however it initialises it with i3c_master_get_free_addr() which returns a signed int type and then attempts to check if dyn_addr is less than 0. Unsigned integers cannot be less than 0, so the check is essentially redundant. Furthermore i3c_master_get_free_addr() could return -ENOMEM which an unsigned int cannot store.

Fix this by capturing the return value of i3c_master_get_free_addr() in a signed int ‘dyn_addr_ret’. If that value is negative, return an error. Otherwise, assign it to the unsigned int ‘dyn_addr’ once we know it’s valid.

Fixes 4008a74e0f9b ("i3c: master: svc: Fix npcm845 FIFO empty issue")
---
 drivers/i3c/master/svc-i3c-master.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i3c/master/svc-i3c-master.c +3 -2
index f22fb9e75142..eea08f00d7ce 100644
@@ -998,9 +998,10 @@ 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)
+			int dyn_addr_ret = i3c_master_get_free_addr(&master->base, last_addr + 1);
+			if (dyn_addr_ret < 0)
 				return -ENOSPC;
+			dyn_addr = dyn_addr_ret;
 
 			writel(dyn_addr, master->regs + SVC_I3C_MWDATAB);
 
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 7 lines · Qasim Ijaz

svc_i3c_master_do_daa_locked() declares dyn_addr as an unsigned int however it initialises it with i3c_master_get_free_addr() which returns a signed int type and then attempts to check if dyn_addr is less than 0. Unsigned integers cannot be less than 0, so the check is essentially redundant. Furthermore i3c_master_get_free_addr() could return -ENOMEM which an unsigned int cannot store.

Quoted 8 lines

Fix this by capturing the return value of i3c_master_get_free_addr() in a signed int ‘dyn_addr_ret’. If that value is negative, return an error. Otherwise, assign it to the unsigned int ‘dyn_addr’ once we know it’s valid.

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

---

Thank you for your patch, but similar one was already applied
https://lore.kernel.org/linux-i3c/[email protected]/T/#m5120e1c362e7e57f4cab139a45410fde421c2f37

Frank

Quoted 23 lines
 drivers/i3c/master/svc-i3c-master.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i3c/master/svc-i3c-master.c +3 -3
index f22fb9e75142..eea08f00d7ce 100644
@@ -998,9 +998,10 @@ 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)
+			int dyn_addr_ret = i3c_master_get_free_addr(&master->base, last_addr + 1);
+			if (dyn_addr_ret < 0)
 				return -ENOSPC;
+			dyn_addr = dyn_addr_ret;
 
 			writel(dyn_addr, master->regs + SVC_I3C_MWDATAB);
 
--

2.39.5

author
#2 lore raw
Quoted 13 lines · Frank Li
Quoted 12 lines · Qasim Ijaz

svc_i3c_master_do_daa_locked() declares dyn_addr as an unsigned int however it initialises it with i3c_master_get_free_addr() which returns a signed int type and then attempts to check if dyn_addr is less than 0. Unsigned integers cannot be less than 0, so the check is essentially redundant. Furthermore i3c_master_get_free_addr() could return -ENOMEM which an unsigned int cannot store.

Fix this by capturing the return value of i3c_master_get_free_addr() in a signed int ‘dyn_addr_ret’. If that value is negative, return an error. Otherwise, assign it to the unsigned int ‘dyn_addr’ once we know it’s valid.

Quoted 7 lines
Quoted 3 lines
Fixes 4008a74e0f9b ("i3c: master: svc: Fix npcm845 FIFO empty issue")

---

Thank you for your patch, but similar one was already applied
https://lore.kernel.org/linux-i3c/[email protected]/T/#m5120e1c362e7e57f4cab139a45410fde421c2f37

Hi Frank

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

You can view my orignal patch here:

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

Thanks
Qasim

Quoted 24 lines

Frank

Quoted 23 lines
 drivers/i3c/master/svc-i3c-master.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i3c/master/svc-i3c-master.c +3 -3
index f22fb9e75142..eea08f00d7ce 100644
@@ -998,9 +998,10 @@ 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)
+			int dyn_addr_ret = i3c_master_get_free_addr(&master->base, last_addr + 1);
+			if (dyn_addr_ret < 0)
 				return -ENOSPC;
+			dyn_addr = dyn_addr_ret;
 
 			writel(dyn_addr, master->regs + SVC_I3C_MWDATAB);
 
--

2.39.5

maintainer
#3 lore raw
Quoted 18 lines · Qasim Ijaz
Quoted 17 lines · Frank Li
Quoted 15 lines · Qasim Ijaz

svc_i3c_master_do_daa_locked() declares dyn_addr as an unsigned int however it initialises it with i3c_master_get_free_addr() which returns a signed int type and then attempts to check if dyn_addr is less than 0. Unsigned integers cannot be less than 0, so the check is essentially redundant. Furthermore i3c_master_get_free_addr() could return -ENOMEM which an unsigned int cannot store.

Fix this by capturing the return value of i3c_master_get_free_addr() in a signed int ‘dyn_addr_ret’. If that value is negative, return an error. Otherwise, assign it to the unsigned int ‘dyn_addr’ once we know it’s valid.

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

---

Quoted 8 lines
Quoted 3 lines

Thank you for your patch, but similar one was already applied
https://lore.kernel.org/linux-i3c/[email protected]/T/#m5120e1c362e7e57f4cab139a45410fde421c2f37

Hi Frank

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

Yes, but perfer original owner to fix this type minor fix.

https://lore.kernel.org/linux-i3c/[email protected]/T/#t

Frank

Quoted 36 lines

You can view my orignal patch here:

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

Thanks
Qasim

Quoted 19 lines

Frank

Quoted 18 lines
 drivers/i3c/master/svc-i3c-master.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i3c/master/svc-i3c-master.c +3 -2
index f22fb9e75142..eea08f00d7ce 100644
@@ -998,9 +998,10 @@ 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)
+			int dyn_addr_ret = i3c_master_get_free_addr(&master->base, last_addr + 1);
+			if (dyn_addr_ret < 0)
 				return -ENOSPC;
+			dyn_addr = dyn_addr_ret;
 
Quoted 5 lines
Quoted 5 lines
drivers/i3c/master/svc-i3c-master.c +0 -1
 			writel(dyn_addr, master->regs + SVC_I3C_MWDATAB);
 
--

2.39.5

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

#4 lore raw
Quoted 23 lines · Frank Li
Quoted 22 lines · Qasim Ijaz
Quoted 20 lines · Frank Li
Quoted 7 lines · Qasim Ijaz

svc_i3c_master_do_daa_locked() declares dyn_addr as an unsigned int however it initialises it with i3c_master_get_free_addr() which returns a signed int type and then attempts to check if dyn_addr is less than 0. Unsigned integers cannot be less than 0, so the check is essentially redundant. Furthermore i3c_master_get_free_addr() could return -ENOMEM which an unsigned int cannot store.

Quoted 8 lines

Fix this by capturing the return value of i3c_master_get_free_addr() in a signed int ‘dyn_addr_ret’. If that value is negative, return an error. Otherwise, assign it to the unsigned int ‘dyn_addr’ once we know it’s valid.

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

---

Thank you for your patch, but similar one was already applied
https://lore.kernel.org/linux-i3c/[email protected]/T/#m5120e1c362e7e57f4cab139a45410fde421c2f37

Quoted 7 lines
Quoted 4 lines

Hi Frank

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

Yes, but perfer original owner to fix this type minor fix.

This is absolutely not what I said, the first one that is sent and is applicable should be applied.

See how you didn't fix this trivial issue:

https://lore.kernel.org/linux-i3c/[email protected]/T/#u

Quoted 44 lines

https://lore.kernel.org/linux-i3c/[email protected]/T/#t

Frank

Quoted 36 lines

You can view my orignal patch here:

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

Thanks
Qasim

Quoted 19 lines

Frank

Quoted 18 lines
 drivers/i3c/master/svc-i3c-master.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i3c/master/svc-i3c-master.c +3 -2
index f22fb9e75142..eea08f00d7ce 100644
@@ -998,9 +998,10 @@ 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)
+			int dyn_addr_ret = i3c_master_get_free_addr(&master->base, last_addr + 1);
+			if (dyn_addr_ret < 0)
 				return -ENOSPC;
+			dyn_addr = dyn_addr_ret;
 
Quoted 5 lines
Quoted 5 lines
drivers/i3c/master/svc-i3c-master.c +0 -1
 			writel(dyn_addr, master->regs + SVC_I3C_MWDATAB);
 
--

2.39.5

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

Signature · 3 lines
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com