Skip to contentSkip to conversation

usb/gadget/snps_udc_core: Convert timers to use timer_setup()

PATCH In review Kees Cook 2 participants 2 messages Oct 16, 2017 – Oct 17, 2017 USB

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 usb/gadget/snps_udc_core: Convert timers to use timer_setup()

In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly.

If the probe fails, udc_remove() will not be called, so there is no reason to make del_timer_sync() calls conditional. As a result, use of the .data field can be dropped, in support of making removing this field entirely from struct timer_list.

Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Raviteja Garimella <[email protected]>
Cc Michal Nazarewicz <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
---
 drivers/usb/gadget/udc/snps_udc_core.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)
drivers/usb/gadget/udc/snps_udc_core.c +6 -13
index 47df99dbaef4..2f5e788dd978 100644
@@ -1733,7 +1733,7 @@ static void udc_soft_reset(struct udc *dev)
 }
 
 /* RDE timer callback to set RDE bit */
-static void udc_timer_function(unsigned long v)
+static void udc_timer_function(struct timer_list *unused)
 {
 	u32 tmp;
 
@@ -1813,7 +1813,7 @@ static void udc_handle_halt_state(struct udc_ep *ep)
 }
 
 /* Stall timer callback to poll S bit and set it again after */
-static void udc_pollstall_timer_function(unsigned long v)
+static void udc_pollstall_timer_function(struct timer_list *unused)
 {
 	struct udc_ep *ep;
 	int halted = 0;
@@ -3067,14 +3067,12 @@ void udc_remove(struct udc *dev)
 	stop_timer++;
 	if (timer_pending(&udc_timer))
 		wait_for_completion(&on_exit);
-	if (udc_timer.data)
-		del_timer_sync(&udc_timer);
+	del_timer_sync(&udc_timer);
 	/* remove pollstall timer */
 	stop_pollstall_timer++;
 	if (timer_pending(&udc_pollstall_timer))
 		wait_for_completion(&on_pollstall_exit);
-	if (udc_pollstall_timer.data)
-		del_timer_sync(&udc_pollstall_timer);
+	del_timer_sync(&udc_pollstall_timer);
 	udc = NULL;
 }
 EXPORT_SYMBOL_GPL(udc_remove);
@@ -3164,10 +3162,6 @@ int udc_probe(struct udc *dev)
 	u32		reg;
 	int		retval;
 
-	/* mark timer as not initialized */
-	udc_timer.data = 0;
-	udc_pollstall_timer.data = 0;
-
 	/* device struct setup */
 	dev->gadget.ops = &udc_ops;
 
@@ -3207,9 +3201,8 @@ int udc_probe(struct udc *dev)
 		goto finished;
 
 	/* timer init */
-	setup_timer(&udc_timer, udc_timer_function, 1);
-	/* timer pollstall init */
-	setup_timer(&udc_pollstall_timer, udc_pollstall_timer_function, 1);
+	timer_setup(&udc_timer, udc_timer_function, 0);
+	timer_setup(&udc_pollstall_timer, udc_pollstall_timer_function, 0);
 
 	/* set SD */
 	reg = readl(&dev->regs->ctl);
Signature · 6 lines
2.7.4


-- 
Kees Cook
Pixel Security
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Kees Cook

In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly.

If the probe fails, udc_remove() will not be called, so there is no reason to make del_timer_sync() calls conditional. As a result, use of the .data field can be dropped, in support of making removing this field entirely from struct timer_list.

Quoted 4 lines
Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Raviteja Garimella <[email protected]>
Cc Michal Nazarewicz <[email protected]>
Quoted 71 lines
Cc "Gustavo A. R. Silva" <[email protected]>
---
 drivers/usb/gadget/udc/snps_udc_core.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)
drivers/usb/gadget/udc/snps_udc_core.c +6 -13
index 47df99dbaef4..2f5e788dd978 100644
@@ -1733,7 +1733,7 @@ static void udc_soft_reset(struct udc *dev)
 }
 
 /* RDE timer callback to set RDE bit */
-static void udc_timer_function(unsigned long v)
+static void udc_timer_function(struct timer_list *unused)
 {
 	u32 tmp;
 
@@ -1813,7 +1813,7 @@ static void udc_handle_halt_state(struct udc_ep *ep)
 }
 
 /* Stall timer callback to poll S bit and set it again after */
-static void udc_pollstall_timer_function(unsigned long v)
+static void udc_pollstall_timer_function(struct timer_list *unused)
 {
 	struct udc_ep *ep;
 	int halted = 0;
@@ -3067,14 +3067,12 @@ void udc_remove(struct udc *dev)
 	stop_timer++;
 	if (timer_pending(&udc_timer))
 		wait_for_completion(&on_exit);
-	if (udc_timer.data)
-		del_timer_sync(&udc_timer);
+	del_timer_sync(&udc_timer);
 	/* remove pollstall timer */
 	stop_pollstall_timer++;
 	if (timer_pending(&udc_pollstall_timer))
 		wait_for_completion(&on_pollstall_exit);
-	if (udc_pollstall_timer.data)
-		del_timer_sync(&udc_pollstall_timer);
+	del_timer_sync(&udc_pollstall_timer);
 	udc = NULL;
 }
 EXPORT_SYMBOL_GPL(udc_remove);
@@ -3164,10 +3162,6 @@ int udc_probe(struct udc *dev)
 	u32		reg;
 	int		retval;
 
-	/* mark timer as not initialized */
-	udc_timer.data = 0;
-	udc_pollstall_timer.data = 0;
-
 	/* device struct setup */
 	dev->gadget.ops = &udc_ops;
 
@@ -3207,9 +3201,8 @@ int udc_probe(struct udc *dev)
 		goto finished;
 
 	/* timer init */
-	setup_timer(&udc_timer, udc_timer_function, 1);
-	/* timer pollstall init */
-	setup_timer(&udc_pollstall_timer, udc_pollstall_timer_function, 1);
+	timer_setup(&udc_timer, udc_timer_function, 0);
+	timer_setup(&udc_pollstall_timer, udc_pollstall_timer_function, 0);
 
 	/* set SD */
 	reg = readl(&dev->regs->ctl);
Signature · 1 line
2.7.4
Signature · 3 lines
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»