Skip to content

Commit

Permalink
rtw88-usb: stop trying USB when device is gone
Browse files Browse the repository at this point in the history
This commit make the system survive after usb removal.
The first ENODEV or ENOENT will set a flag, and no attempts are made anymore.

Signed-off-by: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
  • Loading branch information
kurt-vd committed Dec 21, 2021
1 parent 96c142c commit e61eae7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
23 changes: 20 additions & 3 deletions usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ static int rtw_usb_ctrl_atomic(struct rtw_dev *rtwdev,
__u8 req_type, __u16 value, __u16 index,
void *databuf, __u16 size)
{
struct rtw_usb *rtwusb = (struct rtw_usb *)rtwdev->priv;
struct usb_ctrlrequest *dr = NULL;
struct rtw_usb_ctrlcb_t *ctx = NULL;
struct urb *urb = NULL;
bool done;
int ret = -ENOMEM;

if (rtwusb->usb_removed)
return -ENODEV;
ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC);
if (!ctx)
goto out;
Expand All @@ -102,7 +105,11 @@ static int rtw_usb_ctrl_atomic(struct rtw_dev *rtwdev,
usb_fill_control_urb(urb, dev, pipe, (unsigned char *)dr, databuf, size,
rtw_usb_ctrl_atomic_cb, ctx);
ret = usb_submit_urb(urb, GFP_ATOMIC);
if (unlikely(ret)) {
if (unlikely(ret == -ENODEV) || unlikely(ret == -ENOENT)) {
rtwusb->usb_removed = 1;
rtw_notice(rtwdev, "usb device removed");
goto err_free_urb;
} else if (unlikely(ret)) {
rtw_err(rtwdev, "failed to submit urb, ret=%d\n", ret);
goto err_free_urb;
}
Expand Down Expand Up @@ -628,6 +635,8 @@ static int rtw_usb_write_port(struct rtw_dev *rtwdev, u8 addr, u32 cnt,
unsigned int pipe;
int ret;

if (rtwusb->usb_removed)
return -ENODEV;
pipe = rtw_usb_get_pipe(rtwusb, addr);
urb = usb_alloc_urb(0, GFP_ATOMIC);
if (!urb)
Expand All @@ -636,7 +645,10 @@ static int rtw_usb_write_port(struct rtw_dev *rtwdev, u8 addr, u32 cnt,
usb_fill_bulk_urb(urb, usbd, pipe, skb->data, (int)cnt,
cb, context);
ret = usb_submit_urb(urb, GFP_ATOMIC);
if (unlikely(ret))
if (unlikely(ret == -ENODEV) || unlikely(ret == -ENOENT)) {
rtwusb->usb_removed = 1;
rtw_notice(rtwdev, "usb device removed");
} else if (unlikely(ret))
rtw_err(rtwdev, "failed to submit write urb, ret=%d\n", ret);
usb_free_urb(urb);

Expand Down Expand Up @@ -1024,6 +1036,8 @@ static void rtw_usb_read_port(struct rtw_dev *rtwdev, u8 addr,
u32 len;
int ret;

if (rtwusb->usb_removed)
return;
urb = usb_alloc_urb(0, GFP_ATOMIC);
if (!urb)
return;
Expand All @@ -1048,7 +1062,10 @@ static void rtw_usb_read_port(struct rtw_dev *rtwdev, u8 addr,
rtw_usb_read_port_complete,
rxcb);
ret = usb_submit_urb(urb, GFP_ATOMIC);
if (ret)
if (unlikely(ret == -ENODEV) || unlikely(ret == -ENOENT)) {
rtwusb->usb_removed = 1;
rtw_notice(rtwdev, "usb device removed");
} else if (ret)
rtw_err(rtwdev, "failed to submit USB urb, ret=%d\n", ret);

usb_free_urb(urb);
Expand Down
1 change: 1 addition & 0 deletions usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct rtw_usb {
u8 queue_to_pipe[8];
u8 usb_speed;
u8 usb_txagg_num;
u8 usb_removed;

struct workqueue_struct *txwq, *rxwq;

Expand Down

0 comments on commit e61eae7

Please sign in to comment.