Skip to contentSkip to conversation

Staging: gdm724x: gdm_usb.c: Use module_usb_driver

PATCH In review Shraddha Barke 3 participants 6 messages Sep 29, 2015 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Staging: gdm724x: gdm_usb.c: Use module_usb_driver

Macro module_usb_driver is used for drivers whose init and exit paths does only register and unregister.Remove boilerplate code by using module_usb_driver.

Problem found using Coccinelle.

---
 drivers/staging/gdm724x/gdm_usb.c | 38 +-------------------------------------
 1 file changed, 1 insertion(+), 37 deletions(-)
drivers/staging/gdm724x/gdm_usb.c +1 -37
index ed1a12f..3977663 100644
@@ -998,43 +998,7 @@ static struct usb_driver gdm_usb_lte_driver = {
 	.reset_resume = gdm_usb_resume,
 };
 
-static int __init gdm_usb_lte_init(void)
-{
-	if (gdm_lte_event_init() < 0) {
-		pr_err("error creating event\n");
-		return -1;
-	}
-
-	usb_tx_wq = create_workqueue("usb_tx_wq");
-	if (usb_tx_wq == NULL)
-		return -1;
-
-	usb_rx_wq = create_workqueue("usb_rx_wq");
-	if (usb_rx_wq == NULL)
-		return -1;
-
-	return usb_register(&gdm_usb_lte_driver);
-}
-
-static void __exit gdm_usb_lte_exit(void)
-{
-	gdm_lte_event_exit();
-
-	usb_deregister(&gdm_usb_lte_driver);
-
-	if (usb_tx_wq) {
-		flush_workqueue(usb_tx_wq);
-		destroy_workqueue(usb_tx_wq);
-	}
-
-	if (usb_rx_wq) {
-		flush_workqueue(usb_rx_wq);
-		destroy_workqueue(usb_rx_wq);
-	}
-}
-
-module_init(gdm_usb_lte_init);
-module_exit(gdm_usb_lte_exit);
+module_usb_driver(gdm_usb_lte_driver);
 
 MODULE_VERSION(DRIVER_VERSION);
 MODULE_DESCRIPTION("GCT LTE USB Device Driver");
Signature · 1 line
2.1.4
#1 lore raw

PATCH 2/2 Staging: gdm724x: gdm_mux.c: Use module_usb_driver

Macro module_usb_driver is used for drivers whose init
and exit paths does only register and unregister. Remove boilerplate code by using module_usb_driver.

---
 drivers/staging/gdm724x/gdm_mux.c | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)
drivers/staging/gdm724x/gdm_mux.c +1 -28
index 1cf24e4..7cd9b87 100644
@@ -658,34 +658,7 @@ static struct usb_driver gdm_mux_driver = {
 	.reset_resume = gdm_mux_resume,
 };
 
-static int __init gdm_usb_mux_init(void)
-{
-
-	mux_rx_wq = create_workqueue("mux_rx_wq");
-	if (mux_rx_wq == NULL) {
-		pr_err("work queue create fail\n");
-		return -1;
-	}
-
-	register_lte_tty_driver();
-
-	return usb_register(&gdm_mux_driver);
-}
-
-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);
-}
-
-module_init(gdm_usb_mux_init);
-module_exit(gdm_usb_mux_exit);
+module_usb_driver(gdm_mux_driver);
 
 MODULE_DESCRIPTION("GCT LTE TTY Device Driver");
 MODULE_LICENSE("GPL");
Signature · 1 line
2.1.4
#2 lore raw
In reply to Shraddha Barke
Quoted 8 lines · Shraddha Barke

Macro module_usb_driver is used for drivers whose init and exit paths does only register and unregister.Remove boilerplate code by using module_usb_driver.

Problem found using Coccinelle.

---

But then how are you going to create the workqueues and gdm_lte_event_init()?
module_usb_driver() is used in places where the init function is only having usb_register() and exit function is only having usb_deregister(). If they are doing something special then you can not use module_usb_driver.

regards
sudip

#3 lore raw
Quoted 7 lines · Sudip Mukherjee
Quoted 6 lines · Shraddha Barke

Macro module_usb_driver is used for drivers whose init and exit paths does only register and unregister.Remove boilerplate code by using module_usb_driver.

Problem found using Coccinelle.

Quoted 8 lines
Quoted 2 lines

---

But then how are you going to create the workqueues and gdm_lte_event_init()?
module_usb_driver() is used in places where the init function is only having usb_register() and exit function is only having usb_deregister(). If they are doing something special then you can not use module_usb_driver.

Yes. I realised the mistake I made. Since the patch applied to the tree correctly I made the mistake of thinking the workqueues don't have significance. I have sent a patch which uses module_i2c_driver. Please provide feedback on that.

Thanks,

Shraddha

Quoted 4 lines

regards
sudip

#4 lore raw
In reply to Shraddha Barke
Quoted 5 lines · Shraddha Barke

Macro module_usb_driver is used for drivers whose init and exit paths does only register and unregister.Remove boilerplate code by using module_usb_driver.

Problem found using Coccinelle.

If you find a problem with Coccinelle, please put at least a simplified version of the semantic patch you used. As Sudip noted, this patch series is not at allcorrect, and knowing what semantic patch you used could help suggest where things went wrong.

julia

Quoted 64 lines
---
 drivers/staging/gdm724x/gdm_usb.c | 38 +-------------------------------------
 1 file changed, 1 insertion(+), 37 deletions(-)
drivers/staging/gdm724x/gdm_usb.c +1 -38
index ed1a12f..3977663 100644
@@ -998,43 +998,7 @@ static struct usb_driver gdm_usb_lte_driver = {
 	.reset_resume = gdm_usb_resume,
 };
 
-static int __init gdm_usb_lte_init(void)
-{
-	if (gdm_lte_event_init() < 0) {
-		pr_err("error creating event\n");
-		return -1;
-	}
-
-	usb_tx_wq = create_workqueue("usb_tx_wq");
-	if (usb_tx_wq == NULL)
-		return -1;
-
-	usb_rx_wq = create_workqueue("usb_rx_wq");
-	if (usb_rx_wq == NULL)
-		return -1;
-
-	return usb_register(&gdm_usb_lte_driver);
-}
-
-static void __exit gdm_usb_lte_exit(void)
-{
-	gdm_lte_event_exit();
-
-	usb_deregister(&gdm_usb_lte_driver);
-
-	if (usb_tx_wq) {
-		flush_workqueue(usb_tx_wq);
-		destroy_workqueue(usb_tx_wq);
-	}
-
-	if (usb_rx_wq) {
-		flush_workqueue(usb_rx_wq);
-		destroy_workqueue(usb_rx_wq);
-	}
-}
-
-module_init(gdm_usb_lte_init);
-module_exit(gdm_usb_lte_exit);
+module_usb_driver(gdm_usb_lte_driver);
 
 MODULE_VERSION(DRIVER_VERSION);
 MODULE_DESCRIPTION("GCT LTE USB Device Driver");
--

2.1.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1443502609-9918-1-git-send-email-shraddha.6596%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#5 lore raw
Quoted 8 lines · Julia Lawall
Quoted 4 lines · Shraddha Barke

Macro module_usb_driver is used for drivers whose init and exit paths does only register and unregister.Remove boilerplate code by using module_usb_driver.

Quoted 6 lines
Quoted 1 line

Problem found using Coccinelle.

If you find a problem with Coccinelle, please put at least a simplified version of the semantic patch you used. As Sudip noted, this patch series is not at allcorrect, and knowing what semantic patch you used could help suggest where things went wrong.

Yes. I've sent another patch which uses module_i2c_driver. Actually initially I used Coccinelle to search for all instances of module_init(f) and module_exit(f) which is why I got these results as well.

Quoted 68 lines

julia

Quoted 64 lines
---
 drivers/staging/gdm724x/gdm_usb.c | 38 +-------------------------------------
 1 file changed, 1 insertion(+), 37 deletions(-)
drivers/staging/gdm724x/gdm_usb.c +1 -38
index ed1a12f..3977663 100644
@@ -998,43 +998,7 @@ static struct usb_driver gdm_usb_lte_driver = {
 	.reset_resume = gdm_usb_resume,
 };
 
-static int __init gdm_usb_lte_init(void)
-{
-	if (gdm_lte_event_init() < 0) {
-		pr_err("error creating event\n");
-		return -1;
-	}
-
-	usb_tx_wq = create_workqueue("usb_tx_wq");
-	if (usb_tx_wq == NULL)
-		return -1;
-
-	usb_rx_wq = create_workqueue("usb_rx_wq");
-	if (usb_rx_wq == NULL)
-		return -1;
-
-	return usb_register(&gdm_usb_lte_driver);
-}
-
-static void __exit gdm_usb_lte_exit(void)
-{
-	gdm_lte_event_exit();
-
-	usb_deregister(&gdm_usb_lte_driver);
-
-	if (usb_tx_wq) {
-		flush_workqueue(usb_tx_wq);
-		destroy_workqueue(usb_tx_wq);
-	}
-
-	if (usb_rx_wq) {
-		flush_workqueue(usb_rx_wq);
-		destroy_workqueue(usb_rx_wq);
-	}
-}
-
-module_init(gdm_usb_lte_init);
-module_exit(gdm_usb_lte_exit);
+module_usb_driver(gdm_usb_lte_driver);
 
 MODULE_VERSION(DRIVER_VERSION);
 MODULE_DESCRIPTION("GCT LTE USB Device Driver");
--

2.1.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1443502609-9918-1-git-send-email-shraddha.6596%40gmail.com.
For more options, visit https://groups.google.com/d/optout.