From: Qasim Ijaz <qasdev00@gmail.com>
To: miquel.raynal@bootlin.com, Frank.Li@nxp.com,
alexandre.belloni@bootlin.com
Cc: linux-i3c@lists.infradead.org, imx@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [PATCH] i3c: master: svc: fix signed/unsigned mismatch in dynamic address assignment
Date: Sun, 9 Mar 2025 16:43:14 +0000 [thread overview]
Message-ID: <20250309164314.15039-1-qasdev00@gmail.com> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 1605 bytes --]
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")
Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
---
drivers/i3c/master/svc-i3c-master.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c
index f22fb9e75142..eea08f00d7ce 100644
--- a/drivers/i3c/master/svc-i3c-master.c
+++ b/drivers/i3c/master/svc-i3c-master.c
@@ -998,9 +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)
+ 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
[-- Attachment #2: Type: text/plain, Size: 111 bytes --]
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
next reply other threads:[~2025-03-11 20:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-09 16:43 Qasim Ijaz [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-03-17 10:15 [PATCH] i3c: master: svc: fix signed/unsigned mismatch in dynamic address assignment Qasim Ijaz
2025-03-18 13:40 ` Frank Li
2025-03-18 14:41 ` Qasim Ijaz
2025-03-19 13:18 ` Frank Li
2025-03-20 22:01 ` Alexandre Belloni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250309164314.15039-1-qasdev00@gmail.com \
--to=qasdev00@gmail.com \
--cc=Frank.Li@nxp.com \
--cc=alexandre.belloni@bootlin.com \
--cc=imx@lists.linux.dev \
--cc=linux-i3c@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).