public inbox for alsa-devel@alsa-project.org
 help / color / mirror / Atom feed
* [PATCH 1/2] ASoC: SOF: sof-client-probes: fix error codes in sof_probes_compr_copy()
@ 2022-07-06  7:23 Dan Carpenter
  2022-07-06  7:25 ` [PATCH 2/2] ASoC: SOF: sof-client-probes: cleanup tokenize_input() Dan Carpenter
  2022-07-06  9:05 ` [PATCH 1/2] ASoC: SOF: sof-client-probes: fix error codes in sof_probes_compr_copy() Péter Ujfalusi
  0 siblings, 2 replies; 11+ messages in thread
From: Dan Carpenter @ 2022-07-06  7:23 UTC (permalink / raw)
  To: Pierre-Louis Bossart
  Cc: alsa-devel, Kai Vehmanen, kernel-janitors, Bard Liao,
	Takashi Iwai, Peter Ujfalusi, Liam Girdwood, Ranjani Sridharan,
	Mark Brown, Daniel Baluta, sound-open-firmware

This function tries to return the number of bytes that it was able to
copy to the user.  However, because there are multiple calls to
copy_to_user() in a row that means the bytes are not necessarily
consecutive so it's not useful.  Just return -EFAULT instead.

Fixes: 3dc0d7091778 ("ASoC: SOF: Convert the generic probe support to SOF client")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 sound/soc/sof/sof-client-probes.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sound/soc/sof/sof-client-probes.c b/sound/soc/sof/sof-client-probes.c
index 1f1ea93a7fbf..679bc7d371fc 100644
--- a/sound/soc/sof/sof-client-probes.c
+++ b/sound/soc/sof/sof-client-probes.c
@@ -385,7 +385,6 @@ static int sof_probes_compr_copy(struct snd_soc_component *component,
 	struct snd_compr_runtime *rtd = cstream->runtime;
 	unsigned int offset, n;
 	void *ptr;
-	int ret;
 
 	if (count > rtd->buffer_size)
 		count = rtd->buffer_size;
@@ -395,14 +394,15 @@ static int sof_probes_compr_copy(struct snd_soc_component *component,
 	n = rtd->buffer_size - offset;
 
 	if (count < n) {
-		ret = copy_to_user(buf, ptr, count);
+		if (copy_to_user(buf, ptr, count))
+			return -EFAULT;
 	} else {
-		ret = copy_to_user(buf, ptr, n);
-		ret += copy_to_user(buf + n, rtd->dma_area, count - n);
+		if (copy_to_user(buf, ptr, n))
+			return -EFAULT;
+		if (copy_to_user(buf + n, rtd->dma_area, count - n))
+			return -EFAULT;
 	}
 
-	if (ret)
-		return count - ret;
 	return count;
 }
 
-- 
2.35.1


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

end of thread, other threads:[~2022-07-06 10:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-06  7:23 [PATCH 1/2] ASoC: SOF: sof-client-probes: fix error codes in sof_probes_compr_copy() Dan Carpenter
2022-07-06  7:25 ` [PATCH 2/2] ASoC: SOF: sof-client-probes: cleanup tokenize_input() Dan Carpenter
2022-07-06  9:27   ` Péter Ujfalusi
2022-07-06 10:44     ` Dan Carpenter
2022-07-06 10:56       ` Cezary Rojewski
2022-07-06  9:05 ` [PATCH 1/2] ASoC: SOF: sof-client-probes: fix error codes in sof_probes_compr_copy() Péter Ujfalusi
2022-07-06 10:00   ` Péter Ujfalusi
2022-07-06 10:21   ` Dan Carpenter
2022-07-06 10:31     ` Dan Carpenter
2022-07-06 10:36       ` Dan Carpenter
2022-07-06 10:41       ` Péter Ujfalusi

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