Skip to content

Commit 8fea0c8

Browse files
committed
usb: core: hcd: Convert from tasklet to BH workqueue
The only generic interface to execute asynchronously in the BH context is tasklet; however, it's marked deprecated and has some design flaws. To replace tasklets, BH workqueue support was recently added. A BH workqueue behaves similarly to regular workqueues except that the queued work items are executed in the BH context. This patch converts usb hcd from tasklet to BH workqueue. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: linux-usb@vger.kernel.org
1 parent 7245d24 commit 8fea0c8

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

drivers/usb/core/hcd.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,9 +1664,10 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
16641664
usb_put_urb(urb);
16651665
}
16661666

1667-
static void usb_giveback_urb_bh(struct tasklet_struct *t)
1667+
static void usb_giveback_urb_bh(struct work_struct *work)
16681668
{
1669-
struct giveback_urb_bh *bh = from_tasklet(bh, t, bh);
1669+
struct giveback_urb_bh *bh =
1670+
container_of(work, struct giveback_urb_bh, bh);
16701671
struct list_head local_list;
16711672

16721673
spin_lock_irq(&bh->lock);
@@ -1691,9 +1692,9 @@ static void usb_giveback_urb_bh(struct tasklet_struct *t)
16911692
spin_lock_irq(&bh->lock);
16921693
if (!list_empty(&bh->head)) {
16931694
if (bh->high_prio)
1694-
tasklet_hi_schedule(&bh->bh);
1695+
queue_work(system_bh_highpri_wq, &bh->bh);
16951696
else
1696-
tasklet_schedule(&bh->bh);
1697+
queue_work(system_bh_wq, &bh->bh);
16971698
}
16981699
bh->running = false;
16991700
spin_unlock_irq(&bh->lock);
@@ -1706,7 +1707,7 @@ static void usb_giveback_urb_bh(struct tasklet_struct *t)
17061707
* @status: completion status code for the URB.
17071708
*
17081709
* Context: atomic. The completion callback is invoked in caller's context.
1709-
* For HCDs with HCD_BH flag set, the completion callback is invoked in tasklet
1710+
* For HCDs with HCD_BH flag set, the completion callback is invoked in BH
17101711
* context (except for URBs submitted to the root hub which always complete in
17111712
* caller's context).
17121713
*
@@ -1725,7 +1726,7 @@ void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status)
17251726
struct giveback_urb_bh *bh;
17261727
bool running;
17271728

1728-
/* pass status to tasklet via unlinked */
1729+
/* pass status to BH via unlinked */
17291730
if (likely(!urb->unlinked))
17301731
urb->unlinked = status;
17311732

@@ -1747,9 +1748,9 @@ void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status)
17471748
if (running)
17481749
;
17491750
else if (bh->high_prio)
1750-
tasklet_hi_schedule(&bh->bh);
1751+
queue_work(system_bh_highpri_wq, &bh->bh);
17511752
else
1752-
tasklet_schedule(&bh->bh);
1753+
queue_work(system_bh_wq, &bh->bh);
17531754
}
17541755
EXPORT_SYMBOL_GPL(usb_hcd_giveback_urb);
17551756

@@ -2540,7 +2541,7 @@ static void init_giveback_urb_bh(struct giveback_urb_bh *bh)
25402541

25412542
spin_lock_init(&bh->lock);
25422543
INIT_LIST_HEAD(&bh->head);
2543-
tasklet_setup(&bh->bh, usb_giveback_urb_bh);
2544+
INIT_WORK(&bh->bh, usb_giveback_urb_bh);
25442545
}
25452546

25462547
struct usb_hcd *__usb_create_hcd(const struct hc_driver *driver,
@@ -2926,7 +2927,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
29262927
&& device_can_wakeup(&hcd->self.root_hub->dev))
29272928
dev_dbg(hcd->self.controller, "supports USB remote wakeup\n");
29282929

2929-
/* initialize tasklets */
2930+
/* initialize BHs */
29302931
init_giveback_urb_bh(&hcd->high_prio_bh);
29312932
hcd->high_prio_bh.high_prio = true;
29322933
init_giveback_urb_bh(&hcd->low_prio_bh);
@@ -3036,7 +3037,7 @@ void usb_remove_hcd(struct usb_hcd *hcd)
30363037
mutex_unlock(&usb_bus_idr_lock);
30373038

30383039
/*
3039-
* tasklet_kill() isn't needed here because:
3040+
* flush_work() isn't needed here because:
30403041
* - driver's disconnect() called from usb_disconnect() should
30413042
* make sure its URBs are completed during the disconnect()
30423043
* callback

include/linux/usb/hcd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct giveback_urb_bh {
5555
bool high_prio;
5656
spinlock_t lock;
5757
struct list_head head;
58-
struct tasklet_struct bh;
58+
struct work_struct bh;
5959
struct usb_host_endpoint *completing_ep;
6060
};
6161

0 commit comments

Comments
 (0)