hw/i3c/dw-i3c: Fix uninitialized data use in short transfer
PATCH 1/1 hw/i3c/dw-i3c: Fix uninitialized data use in short transfer
Coverity reports that dw_i3c_short_transfer() may pass an uninitialized buffer to dw_i3c_send().
The immediate cause is the use of data[len] += arg.byte0, which reads from an uninitialized element of the buffer. Replace this with a simple assignment.
Additionally, avoid calling dw_i3c_send() when the constructed payload length is zero. In that case the transfer has no data phase, so the controller can transition to the idle state directly.
This resolves the Coverity UNINIT warning and clarifies the handling of zero-length short transfers.
Resolves: Coverity CID 1645555
--- hw/i3c/dw-i3c.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
hw/i3c/dw-i3c.c +10 -4
@@ -1211,7 +1211,7 @@ static void dw_i3c_short_transfer(DWI3C *s, DWI3CTransferCmd cmd,* ignored. */ if (cmd.dbp) { - data[len] += arg.byte0; + data[len] = arg.byte0; len++; } }
@@ -1226,10 +1226,16 @@ static void dw_i3c_short_transfer(DWI3C *s, DWI3CTransferCmd cmd, len++; } -if (dw_i3c_send (s, data, len, &bytes_sent, is_i2c)) { - err =DW_I3C_RESP_QUEUE_ERR_I2C_NACK ; +if (len >0 ) { +if (dw_i3c_send (s, data, len, &bytes_sent, is_i2c)) { + err =DW_I3C_RESP_QUEUE_ERR_I2C_NACK ; + }else { +/* Only go to an idle state on a successful transfer. */ +ARRAY_FIELD_DP32 (s->regs,PRESENT_STATE ,CM_TFR_ST_STATUS , +DW_I3C_TRANSFER_STATE_IDLE ); + } }else { -/* Only go to an idle state on a successful transfer. */ +/* No payload bytes for this short transfer. */ ARRAY_FIELD_DP32 (s->regs,PRESENT_STATE ,CM_TFR_ST_STATUS ,DW_I3C_TRANSFER_STATE_IDLE ); }
Signature · 1 line
2.43.0
Quoted 11 lines · Jamin Lin
Coverity reports that
dw_i3c_short_transfer()may pass an uninitialized buffer todw_i3c_send().The immediate cause is the use of
data[len] += arg.byte0, which reads from an uninitialized element of the buffer. Replace this with a simple assignment.Additionally, avoid calling
dw_i3c_send()when the constructed payload length is zero. In that case the transfer has no data phase, so the controller can transition to the idle state directly.
Quoted 5 lines
This resolves the Coverity UNINIT warning and clarifies the handling of zero-length short transfers.
Resolves: Coverity CID 1645555
Signed-off-by Jamin Lin <[email protected]>
Quoted 37 lines
--- hw/i3c/dw-i3c.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)hw/i3c/dw-i3c.c +10
-4@@ -1211,7 +1211,7 @@ static void dw_i3c_short_transfer(DWI3C *s, DWI3CTransferCmd cmd,* ignored. */ if (cmd.dbp) { - data[len] += arg.byte0; + data[len] = arg.byte0; len++; } }@@ -1226,10 +1226,16 @@ static void dw_i3c_short_transfer(DWI3C *s, DWI3CTransferCmd cmd, len++; } -if (dw_i3c_send (s, data, len, &bytes_sent, is_i2c)) { - err =DW_I3C_RESP_QUEUE_ERR_I2C_NACK ; +if (len >0 ) { +if (dw_i3c_send (s, data, len, &bytes_sent, is_i2c)) { + err =DW_I3C_RESP_QUEUE_ERR_I2C_NACK ; + }else { +/* Only go to an idle state on a successful transfer. */ +ARRAY_FIELD_DP32 (s->regs,PRESENT_STATE ,CM_TFR_ST_STATUS , +DW_I3C_TRANSFER_STATE_IDLE ); + } }else { -/* Only go to an idle state on a successful transfer. */ +/* No payload bytes for this short transfer. */ ARRAY_FIELD_DP32 (s->regs,PRESENT_STATE ,CM_TFR_ST_STATUS ,DW_I3C_TRANSFER_STATE_IDLE ); }
Nabih Estefan (he/him) | Software Engineer | [email protected]
Quoted 12 lines · Jamin Lin
Coverity reports that
dw_i3c_short_transfer()may pass an uninitialized buffer todw_i3c_send().The immediate cause is the use of
data[len] += arg.byte0, which reads from an uninitialized element of the buffer. Replace this with a simple assignment.Additionally, avoid calling
dw_i3c_send()when the constructed payload length is zero. In that case the transfer has no data phase, so the controller can transition to the idle state directly.
Quoted 5 lines
This resolves the Coverity UNINIT warning and clarifies the handling of zero-length short transfers.
Resolves: Coverity CID 1645555
Signed-off-by Jamin Lin <[email protected]>
Thanks!
- Nabih
Quoted 39 lines
--- hw/i3c/dw-i3c.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)hw/i3c/dw-i3c.c +10
-5@@ -1211,7 +1211,7 @@ static void dw_i3c_short_transfer(DWI3C *s, DWI3CTransferCmd cmd,* ignored. */ if (cmd.dbp) { - data[len] += arg.byte0; + data[len] = arg.byte0; len++; } }@@ -1226,10 +1226,16 @@ static void dw_i3c_short_transfer(DWI3C *s, DWI3CTransferCmd cmd, len++; } -if (dw_i3c_send (s, data, len, &bytes_sent, is_i2c)) { - err =DW_I3C_RESP_QUEUE_ERR_I2C_NACK ; +if (len >0 ) { +if (dw_i3c_send (s, data, len, &bytes_sent, is_i2c)) { + err =DW_I3C_RESP_QUEUE_ERR_I2C_NACK ; + }else { +/* Only go to an idle state on a successful transfer. */ +ARRAY_FIELD_DP32 (s->regs,PRESENT_STATE ,CM_TFR_ST_STATUS , +DW_I3C_TRANSFER_STATE_IDLE ); + } }else { -/* Only go to an idle state on a successful transfer. */ +/* No payload bytes for this short transfer. */ ARRAY_FIELD_DP32 (s->regs,PRESENT_STATE ,CM_TFR_ST_STATUS ,DW_I3C_TRANSFER_STATE_IDLE ); } --2.43.0
Cédric Le Goater
AppliedQuoted 43 lines · Jamin Lin
Coverity reports that
dw_i3c_short_transfer()may pass an uninitialized buffer todw_i3c_send().The immediate cause is the use of
data[len] += arg.byte0, which reads from an uninitialized element of the buffer. Replace this with a simple assignment.Additionally, avoid calling
dw_i3c_send()when the constructed payload length is zero. In that case the transfer has no data phase, so the controller can transition to the idle state directly.This resolves the Coverity UNINIT warning and clarifies the handling of zero-length short transfers.
Resolves: Coverity CID 1645555
Signed-off-by Jamin Lin <[email protected]>--- hw/i3c/dw-i3c.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)hw/i3c/dw-i3c.c +5
-3@@ -1211,7 +1211,7 @@ static void dw_i3c_short_transfer(DWI3C *s, DWI3CTransferCmd cmd,* ignored. */ if (cmd.dbp) { - data[len] += arg.byte0; + data[len] = arg.byte0; len++; } }@@ -1226,10 +1226,16 @@ static void dw_i3c_short_transfer(DWI3C *s, DWI3CTransferCmd cmd, len++; } -if (dw_i3c_send (s, data, len, &bytes_sent, is_i2c)) { - err =DW_I3C_RESP_QUEUE_ERR_I2C_NACK ; +if (len >0 ) { +if (dw_i3c_send (s, data, len, &bytes_sent, is_i2c)) { + err =DW_I3C_RESP_QUEUE_ERR_I2C_NACK ; + }else {
hw/i3c/dw-i3c.c static void dw_i3c_short_transfer(DWI3C *s, DWI3CTransferCmd cmd, · line 1241
Quoted 10 lines
hw/i3c/dw-i3c.c +5
-1+/* Only go to an idle state on a successful transfer. */ +ARRAY_FIELD_DP32 (s->regs,PRESENT_STATE ,CM_TFR_ST_STATUS , +DW_I3C_TRANSFER_STATE_IDLE ); + } }else { -/* Only go to an idle state on a successful transfer. */ +/* No payload bytes for this short transfer. */ ARRAY_FIELD_DP32 (s->regs,PRESENT_STATE ,CM_TFR_ST_STATUS ,DW_I3C_TRANSFER_STATE_IDLE ); }
Applied to aspeed-next.
Thanks,
C.