diff mbox series

ASoC: SOF: Clean up sof_ipc_flood_dfs_write()

Message ID a35dded2-392b-4ccb-9dbb-d782ac9b6547@moroto.mountain (mailing list archive)
State Accepted
Commit 2cfa0eea2675ce569dc80d2c0d2d644a452b77b3
Headers show
Series ASoC: SOF: Clean up sof_ipc_flood_dfs_write() | expand

Commit Message

Dan Carpenter April 4, 2024, 7:34 a.m. UTC
This function doesn't support partial writes so using
simple_write_to_buffer() doesn't really make sense.  It's better to
just use copy_from_user().

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 sound/soc/sof/sof-client-ipc-flood-test.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Comments

Peter Ujfalusi April 4, 2024, 3:12 p.m. UTC | #1
On 04/04/2024 10:34, Dan Carpenter wrote:
> This function doesn't support partial writes so using
> simple_write_to_buffer() doesn't really make sense.  It's better to
> just use copy_from_user().
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Thanks, it makes sense.

Acked-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>

> ---
>  sound/soc/sof/sof-client-ipc-flood-test.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/sound/soc/sof/sof-client-ipc-flood-test.c b/sound/soc/sof/sof-client-ipc-flood-test.c
> index c0d6723aed59..1b2e9e25a836 100644
> --- a/sound/soc/sof/sof-client-ipc-flood-test.c
> +++ b/sound/soc/sof/sof-client-ipc-flood-test.c
> @@ -160,15 +160,20 @@ static ssize_t sof_ipc_flood_dfs_write(struct file *file, const char __user *buf
>  	unsigned long ipc_count = 0;
>  	struct dentry *dentry;
>  	int err;
> -	size_t size;
>  	char *string;
>  	int ret;
>  
> +	if (*ppos != 0)
> +		return -EINVAL;
> +
>  	string = kzalloc(count + 1, GFP_KERNEL);
>  	if (!string)
>  		return -ENOMEM;
>  
> -	size = simple_write_to_buffer(string, count, ppos, buffer, count);
> +	if (copy_from_user(string, buffer, count)) {
> +		ret = -EFAULT;
> +		goto out;
> +	}
>  
>  	/*
>  	 * write op is only supported for ipc_flood_count or
> @@ -198,7 +203,7 @@ static ssize_t sof_ipc_flood_dfs_write(struct file *file, const char __user *buf
>  	/* limit max duration/ipc count for flood test */
>  	if (flood_duration_test) {
>  		if (!ipc_duration_ms) {
> -			ret = size;
> +			ret = count;
>  			goto out;
>  		}
>  
> @@ -207,7 +212,7 @@ static ssize_t sof_ipc_flood_dfs_write(struct file *file, const char __user *buf
>  			ipc_duration_ms = MAX_IPC_FLOOD_DURATION_MS;
>  	} else {
>  		if (!ipc_count) {
> -			ret = size;
> +			ret = count;
>  			goto out;
>  		}
>  
> @@ -231,9 +236,9 @@ static ssize_t sof_ipc_flood_dfs_write(struct file *file, const char __user *buf
>  	if (err < 0)
>  		dev_err_ratelimited(dev, "debugfs write failed to idle %d\n", err);
>  
> -	/* return size if test is successful */
> +	/* return count if test is successful */
>  	if (ret >= 0)
> -		ret = size;
> +		ret = count;
>  out:
>  	kfree(string);
>  	return ret;
Mark Brown April 4, 2024, 4:58 p.m. UTC | #2
On Thu, 04 Apr 2024 10:34:53 +0300, Dan Carpenter wrote:
> This function doesn't support partial writes so using
> simple_write_to_buffer() doesn't really make sense.  It's better to
> just use copy_from_user().
> 
> 

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: SOF: Clean up sof_ipc_flood_dfs_write()
      commit: 2cfa0eea2675ce569dc80d2c0d2d644a452b77b3

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
diff mbox series

Patch

diff --git a/sound/soc/sof/sof-client-ipc-flood-test.c b/sound/soc/sof/sof-client-ipc-flood-test.c
index c0d6723aed59..1b2e9e25a836 100644
--- a/sound/soc/sof/sof-client-ipc-flood-test.c
+++ b/sound/soc/sof/sof-client-ipc-flood-test.c
@@ -160,15 +160,20 @@  static ssize_t sof_ipc_flood_dfs_write(struct file *file, const char __user *buf
 	unsigned long ipc_count = 0;
 	struct dentry *dentry;
 	int err;
-	size_t size;
 	char *string;
 	int ret;
 
+	if (*ppos != 0)
+		return -EINVAL;
+
 	string = kzalloc(count + 1, GFP_KERNEL);
 	if (!string)
 		return -ENOMEM;
 
-	size = simple_write_to_buffer(string, count, ppos, buffer, count);
+	if (copy_from_user(string, buffer, count)) {
+		ret = -EFAULT;
+		goto out;
+	}
 
 	/*
 	 * write op is only supported for ipc_flood_count or
@@ -198,7 +203,7 @@  static ssize_t sof_ipc_flood_dfs_write(struct file *file, const char __user *buf
 	/* limit max duration/ipc count for flood test */
 	if (flood_duration_test) {
 		if (!ipc_duration_ms) {
-			ret = size;
+			ret = count;
 			goto out;
 		}
 
@@ -207,7 +212,7 @@  static ssize_t sof_ipc_flood_dfs_write(struct file *file, const char __user *buf
 			ipc_duration_ms = MAX_IPC_FLOOD_DURATION_MS;
 	} else {
 		if (!ipc_count) {
-			ret = size;
+			ret = count;
 			goto out;
 		}
 
@@ -231,9 +236,9 @@  static ssize_t sof_ipc_flood_dfs_write(struct file *file, const char __user *buf
 	if (err < 0)
 		dev_err_ratelimited(dev, "debugfs write failed to idle %d\n", err);
 
-	/* return size if test is successful */
+	/* return count if test is successful */
 	if (ret >= 0)
-		ret = size;
+		ret = count;
 out:
 	kfree(string);
 	return ret;