]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
leds: uleds: Return -EFAULT on copy_to_user() failure
authorYousef Alhouseen <alhouseenyousef@gmail.com>
Thu, 21 May 2026 18:12:05 +0000 (20:12 +0200)
committerLee Jones <lee@kernel.org>
Wed, 17 Jun 2026 10:29:45 +0000 (11:29 +0100)
uleds_read() copies the current brightness value to userspace but
ignores copy_to_user() failures. It then clears the pending update and
reports a successful full read even when no data was copied.

Return -EFAULT when the copy fails and leave the update pending so a
later read can retry.

Signed-off-by: Yousef Alhouseen <alhouseenyousef@gmail.com>
Link: https://patch.msgid.link/20260521181205.15130-1-alhouseenyousef@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>
drivers/leds/uleds.c

index ace71ffc0591f11edf5fc62fc3744af84e8cf8cd..470015e3f80203070c4c0ecb446525f8f55b4a11 100644 (file)
@@ -147,10 +147,13 @@ static ssize_t uleds_read(struct file *file, char __user *buffer, size_t count,
                } else if (!udev->new_data && (file->f_flags & O_NONBLOCK)) {
                        retval = -EAGAIN;
                } else if (udev->new_data) {
-                       retval = copy_to_user(buffer, &udev->brightness,
-                                             sizeof(udev->brightness));
-                       udev->new_data = false;
-                       retval = sizeof(udev->brightness);
+                       if (copy_to_user(buffer, &udev->brightness,
+                                        sizeof(udev->brightness))) {
+                               retval = -EFAULT;
+                       } else {
+                               udev->new_data = false;
+                               retval = sizeof(udev->brightness);
+                       }
                }
 
                mutex_unlock(&udev->mutex);