[PATCH v2] usb: gadget: f_hid: drop ERROR() on copy_from_user() failure

Linkai Gong posted 1 patch 1 month, 1 week ago
drivers/usb/gadget/function/f_hid.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH v2] usb: gadget: f_hid: drop ERROR() on copy_from_user() failure
Posted by Linkai Gong 1 month, 1 week ago
A failed copy_from_user() is a userspace fault, not a kernel error.
Do not spam the log, and return -EFAULT instead of -EINVAL.

Suggested-by: David Laight <david.laight.linux@gmail.com>
Signed-off-by: Linkai Gong <gonglinkai@kylinos.cn>
---
v2:
- Return -EFAULT instead of -EINVAL (David Laight)

 drivers/usb/gadget/function/f_hid.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 3c6b43d06a6d..b8e1c0e0f1a2 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -656,9 +656,8 @@ static int f_hidg_get_report(struct file *file, struct usb_hidg_report __user *b
 
 	if (copy_from_user(&entry->report_data, buffer,
 				sizeof(struct usb_hidg_report))) {
-		ERROR(cdev, "copy_from_user error\n");
 		kfree(entry);
-		return -EINVAL;
+		return -EFAULT;
 	}
 
 	report_id = entry->report_data.report_id;
-- 
2.25.1