Skip to content

Commit 3b2ac81

Browse files
nxpfranklialexandrebelloni
authored andcommitted
i3c: master: svc: fix possible assignment of the same address to two devices
svc_i3c_master_do_daa() { ... for (i = 0; i < dev_nb; i++) { ret = i3c_master_add_i3c_dev_locked(m, addrs[i]); if (ret) goto rpm_out; } } If two devices (A and B) are detected in DAA and address 0xa is assigned to device A and 0xb to device B, a failure in i3c_master_add_i3c_dev_locked() for device A (addr: 0xa) could prevent device B (addr: 0xb) from being registered on the bus. The I3C stack might still consider 0xb a free address. If a subsequent Hotjoin occurs, 0xb might be assigned to Device A, causing both devices A and B to use the same address 0xb, violating the I3C specification. The return value for i3c_master_add_i3c_dev_locked() should not be checked because subsequent steps will scan the entire I3C bus, independent of whether i3c_master_add_i3c_dev_locked() returns success. If device A registration fails, there is still a chance to register device B. i3c_master_add_i3c_dev_locked() can reset DAA if a failure occurs while retrieving device information. Cc: stable@kernel.org Fixes: 317bacf ("i3c: master: add enable(disable) hot join in sys entry") Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: Frank Li <Frank.Li@nxp.com> Link: https://lore.kernel.org/r/20241002-svc-i3c-hj-v6-6-7e6e1d3569ae@nxp.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 3ca5291 commit 3b2ac81

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

drivers/i3c/master/svc-i3c-master.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,12 +1103,27 @@ static int svc_i3c_master_do_daa(struct i3c_master_controller *m)
11031103
if (ret)
11041104
goto rpm_out;
11051105

1106-
/* Register all devices who participated to the core */
1107-
for (i = 0; i < dev_nb; i++) {
1108-
ret = i3c_master_add_i3c_dev_locked(m, addrs[i]);
1109-
if (ret)
1110-
goto rpm_out;
1111-
}
1106+
/*
1107+
* Register all devices who participated to the core
1108+
*
1109+
* If two devices (A and B) are detected in DAA and address 0xa is assigned to
1110+
* device A and 0xb to device B, a failure in i3c_master_add_i3c_dev_locked()
1111+
* for device A (addr: 0xa) could prevent device B (addr: 0xb) from being
1112+
* registered on the bus. The I3C stack might still consider 0xb a free
1113+
* address. If a subsequent Hotjoin occurs, 0xb might be assigned to Device A,
1114+
* causing both devices A and B to use the same address 0xb, violating the I3C
1115+
* specification.
1116+
*
1117+
* The return value for i3c_master_add_i3c_dev_locked() should not be checked
1118+
* because subsequent steps will scan the entire I3C bus, independent of
1119+
* whether i3c_master_add_i3c_dev_locked() returns success.
1120+
*
1121+
* If device A registration fails, there is still a chance to register device
1122+
* B. i3c_master_add_i3c_dev_locked() can reset DAA if a failure occurs while
1123+
* retrieving device information.
1124+
*/
1125+
for (i = 0; i < dev_nb; i++)
1126+
i3c_master_add_i3c_dev_locked(m, addrs[i]);
11121127

11131128
/* Configure IBI auto-rules */
11141129
ret = svc_i3c_update_ibirules(master);

0 commit comments

Comments
 (0)