Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1725761

Re: [PATCH 27/31] usb/gadget/snps_udc_core: Move timer initialization earlier

From Michal Nazarewicz <mina86@mina86.com>
Newsgroups linux.kernel
Subject Re: [PATCH 27/31] usb/gadget/snps_udc_core: Move timer initialization earlier
Date 2017-09-03 23:20 +0200
Message-ID <ulKtb-50X-9@gated-at.bofh.it> (permalink)
References <ukHe1-3XZ-3@gated-at.bofh.it> <ukHnI-41L-25@gated-at.bofh.it>
Organization http://mina86.com/

Show all headers | View raw


On Thu, Aug 31 2017, Kees Cook wrote:
> With timer initialization made earlier at the start, there is no reason
> to make del_timer_sync() calls conditionally, there by removing the
> assignments and tests of the .data field.
>
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Raviteja Garimella <raviteja.garimella@broadcom.com>
> Cc: Michal Nazarewicz <mina86@mina86.com>
> Cc: "Gustavo A. R. Silva" <garsilva@embeddedor.com>
> Cc: linux-usb@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  drivers/usb/gadget/udc/snps_udc_core.c | 16 +++++-----------
>  1 file changed, 5 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/usb/gadget/udc/snps_udc_core.c b/drivers/usb/gadget/udc/snps_udc_core.c
> index 5460e5ba1c3c..1607e901e16b 100644
> --- a/drivers/usb/gadget/udc/snps_udc_core.c
> +++ b/drivers/usb/gadget/udc/snps_udc_core.c
> @@ -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,9 +3162,9 @@ int udc_probe(struct udc *dev)
>  	u32		reg;
>  	int		retval;
>  
> -	/* mark timer as not initialized */
> -	udc_timer.data = 0;
> -	udc_pollstall_timer.data = 0;
> +	/* timer init */
> +	setup_timer(&udc_timer, udc_timer_function, 0);
> +	setup_timer(&udc_pollstall_timer, udc_pollstall_timer_function, 0);
>  
>  	/* device struct setup */
>  	dev->gadget.ops = &udc_ops;
> @@ -3206,10 +3204,6 @@ int udc_probe(struct udc *dev)
>  	if (retval)
>  		goto finished;
>  
> -	/* timer init */
> -	setup_timer(&udc_timer, udc_timer_function, 1);
> -	setup_timer(&udc_pollstall_timer, udc_pollstall_timer_function, 1);
> -
>  	/* set SD */
>  	reg = readl(&dev->regs->ctl);
>  	reg |= AMD_BIT(UDC_DEVCTL_SD);


Stupid question, is the check in udc_remove even necessary?

udc_probe is called from udc_plat_probe:

	if (udc_probe(udc)) {
		ret = -ENODEV;
		goto exit_dma;
	}

If the call fails, udc_plat_probe cleans up after itself and noticeably
*does not* call udc_remove.  As far as I understand, if probe callback
fails, remove callback is *not* called.  Meanwhile, udc_remove is called
from the remove callback which is udc_plat_remove.  So, udc_remove can
be called only if udc_probe succeeds.

It seems to me that a better patch is:

--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -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,9 +3162,9 @@ 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;

-- 
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/31] struct timer_list callback argument conversion, step 1 Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 01/31] coccinelle: Improve setup_timer.cocci matching Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 16/31] usb/phy-isp1301-omap: Remove .data assignment Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 10/31] timer: Remove users of expire and data arguments to DEFINE_TIMER Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 04/31] timer: Remove init_timer_on_stack() in favor of setup_timer_on_stack() Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 15/31] timer: Additional init_timer() -> setup_timer() conversions Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 09/31] timer: Remove unused static initializer macros Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 08/31] timer: Remove users of TIMER_INITIALIZER Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 03/31] timer: Remove init_timer_pinned_deferrable() in favor of setup_pinned_deferrable_timer() Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 07/31] timer: Remove users of TIMER_DEFERRED_INITIALIZER Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 12/31] timer: Remove expires argument from __TIMER_INITIALIZER() Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 18/31] scsi/aic7xxx: Clean up timer usage Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 30/31] appletalk: Remove unneeded synchronization Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 06/31] timer: Remove init_timer_deferrable() in favor of setup_deferrable_timer() Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 11/31] timer: Remove expires and data arguments from DEFINE_TIMER Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
    Re: [PATCH 11/31] timer: Remove expires and data arguments from DEFINE_TIMER Geert Uytterhoeven <geert@linux-m68k.org> - 2017-09-01 09:30 +0200
  [PATCH 05/31] timer: Remove init_timer_pinned() in favor of setup_pinned_timer() Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 17/31] media/i2c/tc358743: Initialize timer Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
  [PATCH 24/31] mips/sgi-ip22: Use separate static data field with with static timer Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
    Re: [PATCH 24/31] mips/sgi-ip22: Use separate static data field with  with static timer Ralf Baechle <ralf@linux-mips.org> - 2017-09-01 09:10 +0200
      Re: [PATCH 24/31] mips/sgi-ip22: Use separate static data field with  with static timer Kees Cook <keescook@chromium.org> - 2017-09-01 19:00 +0200
    Re: [PATCH 24/31] mips/sgi-ip22: Use separate static data field with  with static timer Ralf Baechle <ralf@linux-mips.org> - 2017-09-02 01:00 +0200
  [PATCH 13/31] timer: Remove meaningless .data/.function assignments Kees Cook <keescook@chromium.org> - 2017-09-01 01:40 +0200
    Re: [PATCH 13/31] timer: Remove meaningless .data/.function  assignments Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-09-01 07:10 +0200
    Re: [PATCH 13/31] timer: Remove meaningless .data/.function assignments Krzysztof Halasa <khc@pm.waw.pl> - 2017-09-01 20:10 +0200
    Re: [PATCH 13/31] timer: Remove meaningless .data/.function  assignments Jens Axboe <axboe@kernel.dk> - 2017-09-01 22:10 +0200
  [PATCH 28/31] infiniband/rdmavt: Remove redundant timer initialization Kees Cook <keescook@chromium.org> - 2017-09-01 01:50 +0200
  [PATCH 22/31] sparc/led: Use separate static data field with with static timer Kees Cook <keescook@chromium.org> - 2017-09-01 01:50 +0200
  Re: [PATCH 31/31] timer: Switch to testing for .function instead of .data Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-09-01 01:50 +0200
    Re: [PATCH 31/31] timer: Switch to testing for .function instead of .data Kees Cook <keescook@chromium.org> - 2017-09-01 02:00 +0200
      Re: [PATCH 31/31] timer: Switch to testing for .function instead of .data Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-09-01 03:10 +0200
  [PATCH 23/31] mips/sgi-ip32: Use separate static data field with with static timer Kees Cook <keescook@chromium.org> - 2017-09-01 01:50 +0200
    Re: [PATCH 23/31] mips/sgi-ip32: Use separate static data field with  with static timer Ralf Baechle <ralf@linux-mips.org> - 2017-09-01 09:10 +0200
    Re: [PATCH 23/31] mips/sgi-ip32: Use separate static data field with  with static timer Ralf Baechle <ralf@linux-mips.org> - 2017-09-02 01:00 +0200
  [PATCH 20/31] net/core: Collapse redundant sk_timer callback data assignments Kees Cook <keescook@chromium.org> - 2017-09-01 01:50 +0200
  [PATCH 27/31] usb/gadget/snps_udc_core: Move timer initialization earlier Kees Cook <keescook@chromium.org> - 2017-09-01 01:50 +0200
    Re: [PATCH 27/31] usb/gadget/snps_udc_core: Move timer initialization earlier Michal Nazarewicz <mina86@mina86.com> - 2017-09-03 23:20 +0200
      Re: [PATCH 27/31] usb/gadget/snps_udc_core: Move timer initialization earlier Kees Cook <keescook@chromium.org> - 2017-09-07 01:30 +0200
  [PATCH 21/31] s390/char/sclp: Use separate static data field with with static timer Kees Cook <keescook@chromium.org> - 2017-09-01 01:50 +0200
  [PATCH 29/31] scsi/bnx2i: Initialize timer Kees Cook <keescook@chromium.org> - 2017-09-01 01:50 +0200
  [PATCH 19/31] timer: Remove open-coded casts for .data and .function Kees Cook <keescook@chromium.org> - 2017-09-01 01:50 +0200
    Re: [PATCH 19/31] timer: Remove open-coded casts for .data and  .function Tyrel Datwyler <tyreld@linux.vnet.ibm.com> - 2017-09-01 02:30 +0200
    Re: [PATCH 19/31] timer: Remove open-coded casts for .data and  .function Tyrel Datwyler <turtle.in.the.kernel@gmail.com> - 2017-09-01 02:30 +0200
  [PATCH 25/31] net/atm/mpc: Use separate static data field with with static timer Kees Cook <keescook@chromium.org> - 2017-09-01 01:50 +0200
  [PATCH 31/31] timer: Switch to testing for .function instead of .data Kees Cook <keescook@chromium.org> - 2017-09-01 01:50 +0200
    Re: [PATCH 31/31] timer: Switch to testing for .function instead of  .data Jeff Kirsher <jeffrey.t.kirsher@intel.com> - 2017-09-01 23:40 +0200
    Re: [PATCH 31/31] timer: Switch to testing for .function instead of .data "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2017-09-02 16:00 +0200

csiph-web