Skip to contentSkip to conversation

staging: gdm724x: gdm_mux: Remove create_workqueue()

PATCH Superseded Amitoj Kaur Chawla 2 participants 4 messages Feb 11, 2016 – Feb 12, 2016 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: gdm724x: gdm_mux: Remove create_workqueue()

Remove deprecated create_workqueue() by using system_wq since we do not require a dedicated workqueue here.

---
 drivers/staging/gdm724x/gdm_mux.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)
drivers/staging/gdm724x/gdm_mux.c +3 -15
index 445f836..c7c2e66 100644
@@ -26,8 +26,6 @@
 
 #include "gdm_mux.h"
 
-static struct workqueue_struct *mux_rx_wq;
-
 static u16 packet_type[TTY_MAX_COUNT] = {0xF011, 0xF010};
 
 #define USB_DEVICE_CDC_DATA(vid, pid) \
@@ -275,7 +273,7 @@ static void gdm_mux_rcv_complete(struct urb *urb)
 		r->len = r->urb->actual_length;
 		spin_lock_irqsave(&rx->to_host_lock, flags);
 		list_add_tail(&r->to_host_list, &rx->to_host_list);
-		queue_work(mux_rx_wq, &mux_dev->work_rx.work);
+		schedule_work(&mux_dev->work_rx.work);
 		spin_unlock_irqrestore(&rx->to_host_lock, flags);
 	}
 }
@@ -602,6 +600,8 @@ static int gdm_mux_suspend(struct usb_interface *intf, pm_message_t pm_msg)
 	mux_dev = tty_dev->priv_dev;
 	rx = &mux_dev->rx;
 
+	flush_work(&mux_dev->work_rx.work);
+
 	if (mux_dev->usb_state != PM_NORMAL) {
 		dev_err(intf->usb_dev, "usb suspend - invalid state\n");
 		return -1;
@@ -656,13 +656,6 @@ static struct usb_driver gdm_mux_driver = {
 
 static int __init gdm_usb_mux_init(void)
 {
-
-	mux_rx_wq = create_workqueue("mux_rx_wq");
-	if (!mux_rx_wq) {
-		pr_err("work queue create fail\n");
-		return -1;
-	}
-
 	register_lte_tty_driver();
 
 	return usb_register(&gdm_mux_driver);
@@ -672,11 +665,6 @@ static void __exit gdm_usb_mux_exit(void)
 {
 	unregister_lte_tty_driver();
 
-	if (mux_rx_wq) {
-		flush_workqueue(mux_rx_wq);
-		destroy_workqueue(mux_rx_wq);
-	}
-
 	usb_deregister(&gdm_mux_driver);
 }
 
Signature · 1 line
1.9.1
#1 lore raw

Hello, Amitoj.

Quoted 2 lines · Amitoj Kaur Chawla

Remove deprecated create_workqueue() by using system_wq since we do not require a dedicated workqueue here.

It'd be great if you can explain how the conversion is okay.

drivers/staging/gdm724x/gdm_mux.c static void gdm_mux_rcv_complete(struct urb *urb) · line 276

Quoted 7 lines

#define USB_DEVICE_CDC_DATA(vid, pid) \

drivers/staging/gdm724x/gdm_mux.c +1 -1
@@ -275,7 +273,7 @@ static void gdm_mux_rcv_complete(struct urb *urb)
 		r->len = r->urb->actual_length;
 		spin_lock_irqsave(&rx->to_host_lock, flags);
 		list_add_tail(&r->to_host_list, &rx->to_host_list);
-		queue_work(mux_rx_wq, &mux_dev->work_rx.work);
+		schedule_work(&mux_dev->work_rx.work);

1. because there's one work item per mux_dev and different mux_devs don't need to be ordered, increase of concurrency level by switching to system_wq shouldn't break anything.

drivers/staging/gdm724x/gdm_mux.c static int gdm_mux_suspend(struct usb_interface *intf, pm_message_t pm_msg) · line 604

Quoted 6 lines
drivers/staging/gdm724x/gdm_mux.c +2 -0
@@ -602,6 +600,8 @@ static int gdm_mux_suspend(struct usb_interface *intf, pm_message_t pm_msg)
 	mux_dev = tty_dev->priv_dev;
 	rx = &mux_dev->rx;
 
+	flush_work(&mux_dev->work_rx.work);
+

If work_rx is self-requeueing, cancel_work_sync() would be the right option here because flush_work() only guarantees that the current pending or executing instance is finished.

drivers/staging/gdm724x/gdm_mux.c static void __exit gdm_usb_mux_exit(void) · line 678

Quoted 8 lines
drivers/staging/gdm724x/gdm_mux.c +0 -4
@@ -672,11 +665,6 @@ static void __exit gdm_usb_mux_exit(void)
 {
 	unregister_lte_tty_driver();
 
-	if (mux_rx_wq) {
-		flush_workqueue(mux_rx_wq);
-		destroy_workqueue(mux_rx_wq);
-	}

2. and because all devices are suspended, which shutsdown the work item, before the driver can be unregistered, it's guaranteed that no work item is in flight by the time exit path runs.

JFYI, there's more info on the conversion in the following page.

http://kernelnewbies.org/Tejun_Heo

Thanks.

Signature · 1 line
tejun
#2 lore raw
Quoted 3 lines · Tejun Heo

It'd be great if you can explain how the conversion is okay.

Will do in v2. Thanks for elaborating on how I should write it.

Quoted 10 lines

drivers/staging/gdm724x/gdm_mux.c static int gdm_mux_suspend(struct usb_interface *intf, pm_message_t pm_msg) · line 604

Quoted 6 lines
drivers/staging/gdm724x/gdm_mux.c +2 -0
@@ -602,6 +600,8 @@ static int gdm_mux_suspend(struct usb_interface *intf, pm_message_t pm_msg)
      mux_dev = tty_dev->priv_dev;
      rx = &mux_dev->rx;
 
+     flush_work(&mux_dev->work_rx.work);
+

If work_rx is self-requeueing, cancel_work_sync() would be the right option here because flush_work() only guarantees that the current pending or executing instance is finished.

How do I determine whether work_rx is self-requeueing or not?

Amitoj

#3 lore raw

Hello,

Quoted 5 lines · Amitoj Kaur Chawla
Quoted 3 lines

If work_rx is self-requeueing, cancel_work_sync() would be the right option here because flush_work() only guarantees that the current pending or executing instance is finished.

How do I determine whether work_rx is self-requeueing or not?

By seeing whether the work function re-queues the work item it's running off of.

Thanks.

Signature · 1 line
tejun