1fe685cd992050216348cb35a067f6593ccfc821
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0977-USB-gadget-f_hid-avoid-crashes-and-log-spam.patch
1 From 22198e801db7542c59098a75bdab120bcbc42652 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Wed, 30 Sep 2020 19:23:43 +0100
4 Subject: [PATCH] USB: gadget: f_hid: avoid crashes and log spam
5
6 Disconnecting and reconnecting the USB cable can lead to crashes and a
7 variety of kernel log spam. Try to fix or minimise both.
8
9 See: https://github.com/raspberrypi/linux/issues/3870
10
11 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
12 ---
13 drivers/usb/gadget/function/f_hid.c | 18 +++++++++++++++++-
14 1 file changed, 17 insertions(+), 1 deletion(-)
15
16 --- a/drivers/usb/gadget/function/f_hid.c
17 +++ b/drivers/usb/gadget/function/f_hid.c
18 @@ -344,6 +344,11 @@ static ssize_t f_hidg_write(struct file
19
20 spin_lock_irqsave(&hidg->write_spinlock, flags);
21
22 + if (!hidg->req) {
23 + spin_unlock_irqrestore(&hidg->write_spinlock, flags);
24 + return -ESHUTDOWN;
25 + }
26 +
27 #define WRITE_COND (!hidg->write_pending)
28 try_again:
29 /* write queue */
30 @@ -364,7 +369,13 @@ try_again:
31 count = min_t(unsigned, count, hidg->report_length);
32
33 spin_unlock_irqrestore(&hidg->write_spinlock, flags);
34 - status = copy_from_user(req->buf, buffer, count);
35 + if (req) {
36 + status = copy_from_user(req->buf, buffer, count);
37 + } else {
38 + ERROR(hidg->func.config->cdev, "hidg->req is NULL\n");
39 + status = -ESHUTDOWN;
40 + goto release_write_pending;
41 + }
42
43 if (status != 0) {
44 ERROR(hidg->func.config->cdev,
45 @@ -393,6 +404,11 @@ try_again:
46
47 spin_unlock_irqrestore(&hidg->write_spinlock, flags);
48
49 + if (!hidg->in_ep->enabled) {
50 + ERROR(hidg->func.config->cdev, "in_ep is disabled\n");
51 + status = -ESHUTDOWN;
52 + goto release_write_pending;
53 + }
54 status = usb_ep_queue(hidg->in_ep, req, GFP_ATOMIC);
55 if (status < 0) {
56 ERROR(hidg->func.config->cdev,