public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] soundwire: cadence: Don't overwrite msg->buf during write commands
@ 2022-09-16 10:35 Richard Fitzgerald
  2022-09-16 10:55 ` Pierre-Louis Bossart
  2022-09-20  5:00 ` Vinod Koul
  0 siblings, 2 replies; 3+ messages in thread
From: Richard Fitzgerald @ 2022-09-16 10:35 UTC (permalink / raw)
  To: vkoul, yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale
  Cc: alsa-devel, linux-kernel, patches, 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().

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 drivers/soundwire/cadence_master.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/soundwire/cadence_master.c b/drivers/soundwire/cadence_master.c
index be9cd47f31ec..3ef472049980 100644
--- a/drivers/soundwire/cadence_master.c
+++ b/drivers/soundwire/cadence_master.c
@@ -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;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] soundwire: cadence: Don't overwrite msg->buf during write commands
  2022-09-16 10:35 [PATCH] soundwire: cadence: Don't overwrite msg->buf during write commands Richard Fitzgerald
@ 2022-09-16 10:55 ` Pierre-Louis Bossart
  2022-09-20  5:00 ` Vinod Koul
  1 sibling, 0 replies; 3+ messages in thread
From: Pierre-Louis Bossart @ 2022-09-16 10:55 UTC (permalink / raw)
  To: Richard Fitzgerald, vkoul, yung-chuan.liao, sanyog.r.kale
  Cc: patches, alsa-devel, linux-kernel



On 9/16/22 12:35, Richard Fitzgerald wrote:
> 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().
> 
> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>

Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

> ---
>  drivers/soundwire/cadence_master.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/soundwire/cadence_master.c b/drivers/soundwire/cadence_master.c
> index be9cd47f31ec..3ef472049980 100644
> --- a/drivers/soundwire/cadence_master.c
> +++ b/drivers/soundwire/cadence_master.c
> @@ -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;
>  }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] soundwire: cadence: Don't overwrite msg->buf during write commands
  2022-09-16 10:35 [PATCH] soundwire: cadence: Don't overwrite msg->buf during write commands Richard Fitzgerald
  2022-09-16 10:55 ` Pierre-Louis Bossart
@ 2022-09-20  5:00 ` Vinod Koul
  1 sibling, 0 replies; 3+ messages in thread
From: Vinod Koul @ 2022-09-20  5:00 UTC (permalink / raw)
  To: Richard Fitzgerald
  Cc: yung-chuan.liao, pierre-louis.bossart, sanyog.r.kale, alsa-devel,
	linux-kernel, patches

On 16-09-22, 11:35, Richard Fitzgerald wrote:
> 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

-- 
~Vinod

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-20  5:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-16 10:35 [PATCH] soundwire: cadence: Don't overwrite msg->buf during write commands Richard Fitzgerald
2022-09-16 10:55 ` Pierre-Louis Bossart
2022-09-20  5:00 ` Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox