Skip to contentSkip to conversation

i3c: dw: use COMMAND_PORT_TRANSFER_ARG instead of hardcoding

PATCH Applied Jisheng Zhang 4 participants 4 messages Aug 13 – Aug 18

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

PATCH 1/1 i3c: dw: use COMMAND_PORT_TRANSFER_ARG instead of hardcoding

Use the well defined COMMAND_PORT_TRANSFER_ARG macro instead of hardcoding '1'.

---
 drivers/i3c/master/dw-i3c-master.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i3c/master/dw-i3c-master.c +1 -1
index 655693a2187e..6ba84a97765f 100644
@@ -876,7 +876,7 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
 		goto rpm_out;
 	}
 	cmd = &xfer->cmds[0];
-	cmd->cmd_hi = 0x1;
+	cmd->cmd_hi = COMMAND_PORT_TRANSFER_ARG;
 	cmd->cmd_lo = COMMAND_PORT_DEV_COUNT(master->maxdevs - pos) |
 		      COMMAND_PORT_DEV_INDEX(pos) |
 		      COMMAND_PORT_CMD(I3C_CCC_ENTDAA) |
Signature · 1 line
2.51.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing check for the transfer error status and timeout in dw_i3c_master_daa() leads to incorrectly registering ghost devices on an empty bus or upon hardware failure. --

--- Patch [1]: [PATCH] i3c: dw: use COMMAND_PORT_TRANSFER_ARG instead of hardcoding --- commit 22998f6bbcb44d600e23cd17f1e6c5b48d268e31
Author: Jisheng Zhang <[email protected]>

i3c: dw: use COMMAND_PORT_TRANSFER_ARG instead of hardcoding

This commit replaces the hardcoded value 1 with the well defined COMMAND_PORT_TRANSFER_ARG macro.

Quoted 13 lines
drivers/i3c/master/dw-i3c-master.c +1 -1
index 405089f181c4d..7038aa3bf4c7d 100644
@@ -921,7 +921,7 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
 		goto rpm_out;
 	}
 	cmd = &xfer->cmds[0];
-	cmd->cmd_hi = 0x1;
+	cmd->cmd_hi = COMMAND_PORT_TRANSFER_ARG;
 	cmd->cmd_lo = COMMAND_PORT_DEV_COUNT(master->maxdevs - pos) |
 		      COMMAND_PORT_DEV_INDEX(pos) |
 		      COMMAND_PORT_CMD(I3C_CCC_ENTDAA) |

[ ... ]

drivers/i3c/master/dw-i3c-master.c

Quoted 12 lines
drivers/i3c/master/dw-i3c-master.c +0 -0
 	dw_i3c_master_enqueue_xfer(master, xfer);
 	if (!wait_for_completion_timeout(&xfer->comp, XFER_TIMEOUT))
 		dw_i3c_master_dequeue_xfer(master, xfer);
 
 	/*
 	 * cmd->rx_len holds the number of addresses ENTDAA left unassigned.
 	 * On an empty bus rx_len == maxdevs, so avoid GENMASK(-1, 0).
 	 */
 	if (cmd->rx_len >= master->maxdevs)
 		newdevs = 0;
 	else
 		newdevs = GENMASK(master->maxdevs - cmd->rx_len - 1, 0);

[Severity: High]
This is a pre-existing issue, but I noticed a potential problem in how transfer errors and timeouts are handled here in dw_i3c_master_daa().

If wait_for_completion_timeout() times out due to a noisy or unresponsive I3C bus, the completion timeout and any hardware transfer errors appear to be ignored.

In a timeout scenario, cmd->rx_len remains 0. The code then falls through and calculates newdevs = GENMASK(...) using that zero value.

Could this cause the driver to incorrectly interpret the timeout as a successful discovery of devices for all free slots, leading it to register phantom devices?

Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

-- 
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
Reviewed-by on v1 1/1
#2 lore raw
In reply to Jisheng Zhang
Quoted 5 lines · Jisheng Zhang

Use the well defined COMMAND_PORT_TRANSFER_ARG macro instead of hardcoding '1'.

---

Quoted 19 lines
 drivers/i3c/master/dw-i3c-master.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i3c/master/dw-i3c-master.c +1 -2
index 655693a2187e..6ba84a97765f 100644
@@ -876,7 +876,7 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
 		goto rpm_out;
 	}
 	cmd = &xfer->cmds[0];
-	cmd->cmd_hi = 0x1;
+	cmd->cmd_hi = COMMAND_PORT_TRANSFER_ARG;
 	cmd->cmd_lo = COMMAND_PORT_DEV_COUNT(master->maxdevs - pos) |
 		      COMMAND_PORT_DEV_INDEX(pos) |
 		      COMMAND_PORT_CMD(I3C_CCC_ENTDAA) |
--

2.51.0

maintainer Applied
#3 lore raw
In reply to Jisheng Zhang
Quoted 2 lines · Jisheng Zhang

Use the well defined COMMAND_PORT_TRANSFER_ARG macro instead of hardcoding '1'.

Applied, thanks!

[1/1] i3c: dw: use COMMAND_PORT_TRANSFER_ARG instead of hardcoding

      https://git.kernel.org/i3c/c/942e9a5b676e

Best regards,

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