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
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.
9 See: https://github.com/raspberrypi/linux/issues/3870
11 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
13 drivers/usb/gadget/function/f_hid.c | 18 +++++++++++++++++-
14 1 file changed, 17 insertions(+), 1 deletion(-)
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
20 spin_lock_irqsave(&hidg->write_spinlock, flags);
23 + spin_unlock_irqrestore(&hidg->write_spinlock, flags);
27 #define WRITE_COND (!hidg->write_pending)
30 @@ -364,7 +369,13 @@ try_again:
31 count = min_t(unsigned, count, hidg->report_length);
33 spin_unlock_irqrestore(&hidg->write_spinlock, flags);
34 - status = copy_from_user(req->buf, buffer, count);
36 + status = copy_from_user(req->buf, buffer, count);
38 + ERROR(hidg->func.config->cdev, "hidg->req is NULL\n");
39 + status = -ESHUTDOWN;
40 + goto release_write_pending;
44 ERROR(hidg->func.config->cdev,
45 @@ -393,6 +404,11 @@ try_again:
47 spin_unlock_irqrestore(&hidg->write_spinlock, flags);
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;
54 status = usb_ep_queue(hidg->in_ep, req, GFP_ATOMIC);
56 ERROR(hidg->func.config->cdev,