Skip to contentSkip to conversation

soundwire: cadence: Don't overwrite msg->buf during write commands

PATCH Applied Richard Fitzgerald 3 participants 3 messages Sep 16, 2022 – Sep 20, 2022 SoundWire

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soundwire: cadence: Don't overwrite msg->buf during write commands

The buf passed in struct sdw_msg must only be written for a READ, in that case the RDATA part of the response is the data value of the register.

For a write command there is no RDATA, and buf should be assumed to be const and unmodifable. The original caller should not expect its data buffer to be corrupted by an sdw_nwrite().

---
 drivers/soundwire/cadence_master.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/soundwire/cadence_master.c +6 -3
index be9cd47f31ec..3ef472049980 100644
@@ -544,9 +544,12 @@ cdns_fill_msg_resp(struct sdw_cdns *cdns,
 		return SDW_CMD_IGNORED;
 	}
 
-	/* fill response */
-	for (i = 0; i < count; i++)
-		msg->buf[i + offset] = FIELD_GET(CDNS_MCP_RESP_RDATA, cdns->response_buf[i]);
+	if (msg->flags == SDW_MSG_FLAG_READ) {
+		/* fill response */
+		for (i = 0; i < count; i++)
+			msg->buf[i + offset] = FIELD_GET(CDNS_MCP_RESP_RDATA,
+							 cdns->response_buf[i]);
+	}
 
 	return SDW_CMD_OK;
 }
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Richard Fitzgerald

The buf passed in struct sdw_msg must only be written for a READ, in that case the RDATA part of the response is the data value of the register.

For a write command there is no RDATA, and buf should be assumed to be const and unmodifable. The original caller should not expect its data buffer to be corrupted by an sdw_nwrite().

Quoted 24 lines
---
 drivers/soundwire/cadence_master.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/soundwire/cadence_master.c +6 -3
index be9cd47f31ec..3ef472049980 100644
@@ -544,9 +544,12 @@ cdns_fill_msg_resp(struct sdw_cdns *cdns,
 		return SDW_CMD_IGNORED;
 	}
 
-	/* fill response */
-	for (i = 0; i < count; i++)
-		msg->buf[i + offset] = FIELD_GET(CDNS_MCP_RESP_RDATA, cdns->response_buf[i]);
+	if (msg->flags == SDW_MSG_FLAG_READ) {
+		/* fill response */
+		for (i = 0; i < count; i++)
+			msg->buf[i + offset] = FIELD_GET(CDNS_MCP_RESP_RDATA,
+							 cdns->response_buf[i]);
+	}
 
 	return SDW_CMD_OK;
 }
maintainer Applied
#2 lore raw
In reply to Richard Fitzgerald
Quoted 7 lines · Richard Fitzgerald

The buf passed in struct sdw_msg must only be written for a READ, in that case the RDATA part of the response is the data value of the register.

For a write command there is no RDATA, and buf should be assumed to be const and unmodifable. The original caller should not expect its data buffer to be corrupted by an sdw_nwrite().

Applied, thanks

Signature · 1 line
~Vinod