All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Cc: alsa-devel@alsa-project.org,
	Kai Vehmanen <kai.vehmanen@linux.intel.com>,
	kernel-janitors@vger.kernel.org,
	Bard Liao <yung-chuan.liao@linux.intel.com>,
	Takashi Iwai <tiwai@suse.com>,
	Peter Ujfalusi <peter.ujfalusi@linux.intel.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
	Mark Brown <broonie@kernel.org>,
	Daniel Baluta <daniel.baluta@nxp.com>,
	sound-open-firmware@alsa-project.org
Subject: [PATCH 2/2] ASoC: SOF: sof-client-probes: cleanup tokenize_input()
Date: Wed, 6 Jul 2022 10:25:00 +0300	[thread overview]
Message-ID: <YsU4zCpaV7GBpHci@kili> (raw)
In-Reply-To: <YsU4dYXYYVsfs92J@kili>

The tokenize_input() function is cleaner if it uses strndup_user()
instead of simple_write_to_buffer().  The way it's written now, if
*ppos is non-zero then it returns -EIO but normally we would return
0 in that case.  It's easier to handle that in the callers.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 sound/soc/sof/sof-client-probes.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/sound/soc/sof/sof-client-probes.c b/sound/soc/sof/sof-client-probes.c
index 679bc7d371fc..6c922b683f67 100644
--- a/sound/soc/sof/sof-client-probes.c
+++ b/sound/soc/sof/sof-client-probes.c
@@ -461,24 +461,17 @@ static int strsplit_u32(char *buf, const char *delim, u32 **tkns, size_t *num_tk
 }
 
 static int tokenize_input(const char __user *from, size_t count,
-			  loff_t *ppos, u32 **tkns, size_t *num_tkns)
+			  u32 **tkns, size_t *num_tkns)
 {
 	char *buf;
 	int ret;
 
-	buf = kmalloc(count + 1, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-
-	ret = simple_write_to_buffer(buf, count, ppos, from, count);
-	if (ret != count) {
-		ret = ret >= 0 ? -EIO : ret;
-		goto exit;
-	}
+	buf = strndup_user(from, count + 1);
+	if (IS_ERR(buf))
+		return PTR_ERR(buf);
 
-	buf[count] = '\0';
 	ret = strsplit_u32(buf, ",", tkns, num_tkns);
-exit:
+
 	kfree(buf);
 	return ret;
 }
@@ -552,12 +545,15 @@ sof_probes_dfs_points_write(struct file *file, const char __user *from,
 	u32 *tkns;
 	int ret, err;
 
+	if (*ppos)
+		return 0;
+
 	if (priv->extractor_stream_tag == SOF_PROBES_INVALID_NODE_ID) {
 		dev_warn(dev, "no extractor stream running\n");
 		return -ENOENT;
 	}
 
-	ret = tokenize_input(from, count, ppos, &tkns, &num_tkns);
+	ret = tokenize_input(from, count, &tkns, &num_tkns);
 	if (ret < 0)
 		return ret;
 	bytes = sizeof(*tkns) * num_tkns;
@@ -607,12 +603,15 @@ sof_probes_dfs_points_remove_write(struct file *file, const char __user *from,
 	u32 *tkns;
 	int ret, err;
 
+	if (*ppos)
+		return 0;
+
 	if (priv->extractor_stream_tag == SOF_PROBES_INVALID_NODE_ID) {
 		dev_warn(dev, "no extractor stream running\n");
 		return -ENOENT;
 	}
 
-	ret = tokenize_input(from, count, ppos, &tkns, &num_tkns);
+	ret = tokenize_input(from, count, &tkns, &num_tkns);
 	if (ret < 0)
 		return ret;
 	if (!num_tkns) {
-- 
2.35.1


WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	Peter Ujfalusi <peter.ujfalusi@linux.intel.com>,
	Bard Liao <yung-chuan.liao@linux.intel.com>,
	Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
	Kai Vehmanen <kai.vehmanen@linux.intel.com>,
	Daniel Baluta <daniel.baluta@nxp.com>,
	Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>,
	sound-open-firmware@alsa-project.org,
	alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org
Subject: [PATCH 2/2] ASoC: SOF: sof-client-probes: cleanup tokenize_input()
Date: Wed, 6 Jul 2022 10:25:00 +0300	[thread overview]
Message-ID: <YsU4zCpaV7GBpHci@kili> (raw)
In-Reply-To: <YsU4dYXYYVsfs92J@kili>

The tokenize_input() function is cleaner if it uses strndup_user()
instead of simple_write_to_buffer().  The way it's written now, if
*ppos is non-zero then it returns -EIO but normally we would return
0 in that case.  It's easier to handle that in the callers.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 sound/soc/sof/sof-client-probes.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/sound/soc/sof/sof-client-probes.c b/sound/soc/sof/sof-client-probes.c
index 679bc7d371fc..6c922b683f67 100644
--- a/sound/soc/sof/sof-client-probes.c
+++ b/sound/soc/sof/sof-client-probes.c
@@ -461,24 +461,17 @@ static int strsplit_u32(char *buf, const char *delim, u32 **tkns, size_t *num_tk
 }
 
 static int tokenize_input(const char __user *from, size_t count,
-			  loff_t *ppos, u32 **tkns, size_t *num_tkns)
+			  u32 **tkns, size_t *num_tkns)
 {
 	char *buf;
 	int ret;
 
-	buf = kmalloc(count + 1, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-
-	ret = simple_write_to_buffer(buf, count, ppos, from, count);
-	if (ret != count) {
-		ret = ret >= 0 ? -EIO : ret;
-		goto exit;
-	}
+	buf = strndup_user(from, count + 1);
+	if (IS_ERR(buf))
+		return PTR_ERR(buf);
 
-	buf[count] = '\0';
 	ret = strsplit_u32(buf, ",", tkns, num_tkns);
-exit:
+
 	kfree(buf);
 	return ret;
 }
@@ -552,12 +545,15 @@ sof_probes_dfs_points_write(struct file *file, const char __user *from,
 	u32 *tkns;
 	int ret, err;
 
+	if (*ppos)
+		return 0;
+
 	if (priv->extractor_stream_tag == SOF_PROBES_INVALID_NODE_ID) {
 		dev_warn(dev, "no extractor stream running\n");
 		return -ENOENT;
 	}
 
-	ret = tokenize_input(from, count, ppos, &tkns, &num_tkns);
+	ret = tokenize_input(from, count, &tkns, &num_tkns);
 	if (ret < 0)
 		return ret;
 	bytes = sizeof(*tkns) * num_tkns;
@@ -607,12 +603,15 @@ sof_probes_dfs_points_remove_write(struct file *file, const char __user *from,
 	u32 *tkns;
 	int ret, err;
 
+	if (*ppos)
+		return 0;
+
 	if (priv->extractor_stream_tag == SOF_PROBES_INVALID_NODE_ID) {
 		dev_warn(dev, "no extractor stream running\n");
 		return -ENOENT;
 	}
 
-	ret = tokenize_input(from, count, ppos, &tkns, &num_tkns);
+	ret = tokenize_input(from, count, &tkns, &num_tkns);
 	if (ret < 0)
 		return ret;
 	if (!num_tkns) {
-- 
2.35.1


  reply	other threads:[~2022-07-06  7:26 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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:23 ` Dan Carpenter
2022-07-06  7:25 ` Dan Carpenter [this message]
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  9:27     ` Péter Ujfalusi
2022-07-06 10:44     ` Dan Carpenter
2022-07-06 10:44       ` Dan Carpenter
2022-07-06 10:56       ` Cezary Rojewski
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  9:05   ` Péter Ujfalusi
2022-07-06 10:00   ` Péter Ujfalusi
2022-07-06 10:00     ` Péter Ujfalusi
2022-07-06 10:21   ` Dan Carpenter
2022-07-06 10:21     ` Dan Carpenter
2022-07-06 10:31     ` Dan Carpenter
2022-07-06 10:31       ` Dan Carpenter
2022-07-06 10:36       ` Dan Carpenter
2022-07-06 10:36         ` Dan Carpenter
2022-07-06 10:41       ` Péter Ujfalusi
2022-07-06 10:41         ` Péter Ujfalusi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YsU4zCpaV7GBpHci@kili \
    --to=dan.carpenter@oracle.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=daniel.baluta@nxp.com \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=sound-open-firmware@alsa-project.org \
    --cc=tiwai@suse.com \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.