public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Michal Nazarewicz <mina86@mina86.com>
To: Kees Cook <keescook@chromium.org>, Thomas Gleixner <tglx@linutronix.de>
Cc: Kees Cook <keescook@chromium.org>,
	Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Raviteja Garimella <raviteja.garimella@broadcom.com>,
	"Gustavo A. R. Silva" <garsilva@embeddedor.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 27/31] usb/gadget/snps_udc_core: Move timer initialization earlier
Date: Sun, 03 Sep 2017 23:12:04 +0200	[thread overview]
Message-ID: <xa1ttw0jwkpn.fsf@mina86.com> (raw)
In-Reply-To: <1504222183-61202-28-git-send-email-keescook@chromium.org>

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»

  reply	other threads:[~2017-09-03 21:12 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 23:29 [PATCH 00/31] struct timer_list callback argument conversion, step 1 Kees Cook
2017-08-31 23:29 ` [PATCH 01/31] coccinelle: Improve setup_timer.cocci matching Kees Cook
2017-08-31 23:29 ` [PATCH 02/31] timer: Convert open-coded init_timer() to setup_timer() Kees Cook
2017-08-31 23:29 ` [PATCH 03/31] timer: Remove init_timer_pinned_deferrable() in favor of setup_pinned_deferrable_timer() Kees Cook
2017-08-31 23:29 ` [PATCH 04/31] timer: Remove init_timer_on_stack() in favor of setup_timer_on_stack() Kees Cook
2017-08-31 23:29 ` [PATCH 05/31] timer: Remove init_timer_pinned() in favor of setup_pinned_timer() Kees Cook
2017-08-31 23:29 ` [PATCH 06/31] timer: Remove init_timer_deferrable() in favor of setup_deferrable_timer() Kees Cook
2017-08-31 23:29 ` [PATCH 07/31] timer: Remove users of TIMER_DEFERRED_INITIALIZER Kees Cook
2017-08-31 23:29 ` [PATCH 08/31] timer: Remove users of TIMER_INITIALIZER Kees Cook
2017-08-31 23:29 ` [PATCH 09/31] timer: Remove unused static initializer macros Kees Cook
2017-08-31 23:29 ` [PATCH 10/31] timer: Remove users of expire and data arguments to DEFINE_TIMER Kees Cook
2017-08-31 23:29 ` [PATCH 11/31] timer: Remove expires and data arguments from DEFINE_TIMER Kees Cook
2017-09-01  7:26   ` Geert Uytterhoeven
2017-08-31 23:29 ` [PATCH 12/31] timer: Remove expires argument from __TIMER_INITIALIZER() Kees Cook
2017-08-31 23:29 ` [PATCH 13/31] timer: Remove meaningless .data/.function assignments Kees Cook
2017-09-01  5:09   ` Greg Kroah-Hartman
2017-09-01 17:59   ` Krzysztof Halasa
2017-09-01 20:07   ` Jens Axboe
2017-08-31 23:29 ` [PATCH 14/31] timer: Collapse cross-function single-assignment .data into setup_timer() Kees Cook
2017-08-31 23:29 ` [PATCH 15/31] timer: Additional init_timer() -> setup_timer() conversions Kees Cook
2017-08-31 23:29 ` [PATCH 16/31] usb/phy-isp1301-omap: Remove .data assignment Kees Cook
2017-08-31 23:29 ` [PATCH 17/31] media/i2c/tc358743: Initialize timer Kees Cook
2017-08-31 23:29 ` [PATCH 18/31] scsi/aic7xxx: Clean up timer usage Kees Cook
2017-08-31 23:29 ` [PATCH 19/31] timer: Remove open-coded casts for .data and .function Kees Cook
2017-09-01  0:28   ` Tyrel Datwyler
2017-09-01  0:29   ` Tyrel Datwyler
2017-08-31 23:29 ` [PATCH 20/31] net/core: Collapse redundant sk_timer callback data assignments Kees Cook
2017-08-31 23:29 ` [PATCH 21/31] s390/char/sclp: Use separate static data field with with static timer Kees Cook
2017-08-31 23:29 ` [PATCH 22/31] sparc/led: " Kees Cook
2017-08-31 23:29 ` [PATCH 23/31] mips/sgi-ip32: " Kees Cook
2017-09-01  7:04   ` Ralf Baechle
2017-09-01 22:56   ` Ralf Baechle
2017-08-31 23:29 ` [PATCH 24/31] mips/sgi-ip22: " Kees Cook
2017-09-01  6:59   ` Ralf Baechle
2017-09-01 16:57     ` Kees Cook
2017-09-01 22:56   ` Ralf Baechle
2017-08-31 23:29 ` [PATCH 25/31] net/atm/mpc: " Kees Cook
2017-08-31 23:29 ` [PATCH 26/31] staging/comedi/das16: Make timer initialization unconditional Kees Cook
2017-09-01  5:09   ` Greg Kroah-Hartman
2017-09-01  9:29   ` Ian Abbott
2017-09-01  9:38     ` Ian Abbott
2017-09-01 17:53       ` Kees Cook
2017-08-31 23:29 ` [PATCH 27/31] usb/gadget/snps_udc_core: Move timer initialization earlier Kees Cook
2017-09-03 21:12   ` Michal Nazarewicz [this message]
2017-09-06 23:23     ` Kees Cook
2017-08-31 23:29 ` [PATCH 28/31] infiniband/rdmavt: Remove redundant timer initialization Kees Cook
2017-08-31 23:29 ` [PATCH 29/31] scsi/bnx2i: Initialize timer Kees Cook
2017-08-31 23:29 ` [PATCH 30/31] appletalk: Remove unneeded synchronization Kees Cook
2017-08-31 23:29 ` [PATCH 31/31] timer: Switch to testing for .function instead of .data Kees Cook
2017-08-31 23:45   ` Dmitry Torokhov
2017-08-31 23:59     ` Kees Cook
2017-09-01  1:06       ` Dmitry Torokhov
2017-09-01 21:34   ` Jeff Kirsher
2017-09-02 13:47   ` Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xa1ttw0jwkpn.fsf@mina86.com \
    --to=mina86@mina86.com \
    --cc=balbi@kernel.org \
    --cc=garsilva@embeddedor.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=raviteja.garimella@broadcom.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox