Skip to content

Commit 7645422

Browse files
committed
HSD#22021259142: i3c: dw-i3c: Treat TX/RX length mismatch as M0 error
Enhance error handling for Common Command Code (CCC) operations in the DesignWare I3C master driver: * Define GET_MRL_MIN_LEN (2) for validating GETMRL responses. * In dw_i3c_ccc_get(), treat an RX length smaller than the expected payload length or smaller than GET_MRL_MIN_LEN for GETMRL as an M0 (frame) error and return -EIO. * In dw_i3c_ccc_set(), similarly map RX length mismatches to I3C_ERROR_M0. These changes improve robustness by flagging incomplete or malformed responses during CCC transfers rather than silently accepting truncated data. Signed-off-by: Adrian Ng Ho Yin <adrianhoyin.ng@altera.com>
1 parent 3fd633e commit 7645422

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@
226226

227227
#define GET_IBI_SIR_BIT_INDEX(x) ((((x) & 0x1F) + (((x) >> 5) & 0x03)) % 32)
228228

229+
#define GET_MRL_MIN_LEN 2
230+
229231
struct dw_i3c_cmd {
230232
u32 cmd_lo;
231233
u32 cmd_hi;
@@ -774,7 +776,8 @@ static int dw_i3c_ccc_set(struct dw_i3c_master *master,
774776
xfer->cmds[0].error == RESPONSE_ERROR_ADDRESS_NACK)
775777
ccc->err = I3C_ERROR_M2;
776778

777-
if (xfer->cmds[0].error == RESPONSE_ERROR_FRAME)
779+
if (xfer->cmds[0].error == RESPONSE_ERROR_FRAME ||
780+
(cmd->rx_len < ccc->dests[0].payload.len))
778781
ccc->err = I3C_ERROR_M0;
779782

780783
dw_i3c_master_free_xfer(xfer);
@@ -787,6 +790,7 @@ static int dw_i3c_ccc_get(struct dw_i3c_master *master, struct i3c_ccc_cmd *ccc)
787790
struct dw_i3c_xfer *xfer;
788791
struct dw_i3c_cmd *cmd;
789792
int ret, pos;
793+
bool rx_len_mismatch;
790794

791795
pos = dw_i3c_master_get_addr_pos(master, ccc->dests[0].addr);
792796
if (pos < 0)
@@ -820,8 +824,15 @@ static int dw_i3c_ccc_get(struct dw_i3c_master *master, struct i3c_ccc_cmd *ccc)
820824
xfer->cmds[0].error == RESPONSE_ERROR_ADDRESS_NACK)
821825
ccc->err = I3C_ERROR_M2;
822826

823-
if (xfer->cmds[0].error == RESPONSE_ERROR_FRAME)
827+
if (ccc->id == I3C_CCC_GETMRL)
828+
rx_len_mismatch = (cmd->rx_len < GET_MRL_MIN_LEN);
829+
else
830+
rx_len_mismatch = (cmd->rx_len < ccc->dests[0].payload.len);
831+
832+
if (xfer->cmds[0].error == RESPONSE_ERROR_FRAME || rx_len_mismatch) {
824833
ccc->err = I3C_ERROR_M0;
834+
ret = -EIO;
835+
}
825836

826837
dw_i3c_master_free_xfer(xfer);
827838

0 commit comments

Comments
 (0)