USB: wdm: fix WWAN integration issue
Subsystems (3)
v2 cover USB: wdm: fix WWAN integration issue
The original integration of WWAN left a few race conditions and deficiencies in error handling
V2: Added memory barriers Alan Stern pointed out the need for
PATCH v2 1/4 USB: wdm: handle IO errors in wdm_wwan_port_start
In case submitting the URB fails we must undo
what we've done so far.
--- drivers/usb/class/cdc-wdm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/usb/class/cdc-wdm.c +10 -1
@@ -831,6 +831,7 @@ static struct usb_class_driver wdm_class = {static int wdm_wwan_port_start (struct wwan_port *port) {struct wdm_device *desc =wwan_port_get_drvdata (port); +int rv;/* The interface is both exposed via the WWAN framework and as a * legacy usbmisc chardev. If chardev is already open, just fail
@@ -850,7 +851,15 @@ static int wdm_wwan_port_start(struct wwan_port *port)wwan_port_txon (port);/* Start getting events */ -return usb_submit_urb (desc->validity,GFP_KERNEL ); + rv =usb_submit_urb (desc->validity,GFP_KERNEL ); +if (rv <0 ) { +wwan_port_txoff (port); + desc->manage_power (desc->intf,0 ); +/* this must be last lest we race with chardev open */ +clear_bit (WDM_WWAN_IN_USE , &desc->flags); + } + +return rv; }static void wdm_wwan_port_stop (struct wwan_port *port)
Signature · 1 line
2.49.0
PATCH v2 2/4 USB: wdm: close race between wdm_open and wdm_wwan_port_stop
In reply to Oliver NeukumClearing WDM_WWAN_IN_USE must be the last action or we can open a chardev whose URBs are still poisoned
V2: added memory barriers
--- drivers/usb/class/cdc-wdm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/class/cdc-wdm.c +4 -2
@@ -728,7 +728,7 @@ static int wdm_open(struct inode *inode, struct file *file) rv = -EBUSY ; goto out; } - +smp_rmb ();/* ordered against wdm_wwan_port_stop() */ rv =usb_autopm_get_interface (desc->intf);if (rv <0 ) {dev_err (&desc->intf->dev,"Error autopm - %d\n" , rv);
@@ -870,8 +870,10 @@ static void wdm_wwan_port_stop(struct wwan_port *port)poison_urbs (desc); desc->manage_power (desc->intf,0 );clear_bit (WDM_READ , &desc->flags); -clear_bit (WDM_WWAN_IN_USE , &desc->flags);unpoison_urbs (desc); +smp_wmb ();/* ordered against wdm_open() */ +/* this must be last lest we open a poisoned device */ +clear_bit (WDM_WWAN_IN_USE , &desc->flags); }static void wdm_wwan_port_tx_complete (struct urb *urb)
Signature · 1 line
2.49.0
PATCH v2 3/4 USB: wdm: wdm_wwan_port_tx_complete mutex in atomic context
In reply to Oliver Neukumwdm_wwan_port_tx_complete is called from a completion handler with irqs disabled and possible in IRQ context usb_autopm_put_interface can take a mutex. Hence usb_autopm_put_interface_async must be used.
--- drivers/usb/class/cdc-wdm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/class/cdc-wdm.c +1 -1
@@ -881,7 +881,7 @@ static void wdm_wwan_port_tx_complete(struct urb *urb)struct sk_buff *skb = urb->context;struct wdm_device *desc =skb_shinfo (skb)->destructor_arg; -usb_autopm_put_interface (desc->intf); +usb_autopm_put_interface_async (desc->intf);wwan_port_txon (desc->wwanp);kfree_skb (skb); }
Signature · 1 line
2.49.0
PATCH v2 4/4 USB: wdm: add annotation
In reply to Oliver NeukumThis is not understandable without a comment on endianness
--- drivers/usb/class/cdc-wdm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/class/cdc-wdm.c +1 -1
@@ -911,7 +911,7 @@ static int wdm_wwan_port_tx(struct wwan_port *port, struct sk_buff *skb) req->bRequestType = (USB_DIR_OUT |USB_TYPE_CLASS |USB_RECIP_INTERFACE ); req->bRequest =USB_CDC_SEND_ENCAPSULATED_COMMAND ; req->wValue =0 ; - req->wIndex = desc->inum; + req->wIndex = desc->inum;/* already converted */ req->wLength =cpu_to_le16 (skb->len);skb_shinfo (skb)->destructor_arg = desc;
Signature · 1 line
2.49.0