]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: core: make use of simple_write_to_buffer()
authorNuno Sá <nuno.sa@analog.com>
Tue, 18 Feb 2025 10:31:26 +0000 (10:31 +0000)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 4 Mar 2025 13:17:50 +0000 (13:17 +0000)
Instead of open coding (kind of) simple_write_to_buffer(), use it.

While at it, use ascii representation to terminate the string as that is
the more common way of doing it.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20250218-dev-iio-misc-v1-2-bf72b20a1eb8@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/industrialio-core.c

index a2117ad1337d55468c0f21c274fcbedd352c97ff..b9f4113ae5fc3ee1ef76be6808cc437286690dae 100644 (file)
@@ -410,11 +410,12 @@ static ssize_t iio_debugfs_write_reg(struct file *file,
        char buf[80];
        int ret;
 
-       count = min(count, sizeof(buf) - 1);
-       if (copy_from_user(buf, userbuf, count))
-               return -EFAULT;
+       ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf,
+                                    count);
+       if (ret < 0)
+               return ret;
 
-       buf[count] = 0;
+       buf[count] = '\0';
 
        ret = sscanf(buf, "%i %i", &reg, &val);