From: Yousef Alhouseen Date: Thu, 21 May 2026 18:12:05 +0000 (+0200) Subject: leds: uleds: Return -EFAULT on copy_to_user() failure X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61ed78f55a46e12afd4b464c4ba736f55ff33c5e;p=thirdparty%2Fkernel%2Flinux.git 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 Link: https://patch.msgid.link/20260521181205.15130-1-alhouseenyousef@gmail.com Signed-off-by: Lee Jones --- diff --git a/drivers/leds/uleds.c b/drivers/leds/uleds.c index ace71ffc0591f..470015e3f8020 100644 --- a/drivers/leds/uleds.c +++ b/drivers/leds/uleds.c @@ -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);