leds: uleds: Return -EFAULT on copy_to_user() failure

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>
This commit is contained in:
Yousef Alhouseen
2026-05-21 20:12:05 +02:00
committed by Lee Jones
parent b819dc7d8f
commit 61ed78f55a

View 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);