Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753091AbdICVML (ORCPT ); Sun, 3 Sep 2017 17:12:11 -0400 Received: from mail-wr0-f172.google.com ([209.85.128.172]:38658 "EHLO mail-wr0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752133AbdICVMJ (ORCPT ); Sun, 3 Sep 2017 17:12:09 -0400 X-Google-Smtp-Source: ADKCNb4Y4UYgdrRedER5EjhEkBx6Wf0Jt8fGB0Uc8sjlXVvW7jCwCfLVgAVc1xOf+PI3jIsgutNVMg== From: Michal Nazarewicz To: Kees Cook , Thomas Gleixner Cc: Kees Cook , Felipe Balbi , Greg Kroah-Hartman , Raviteja Garimella , "Gustavo A. R. Silva" , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 27/31] usb/gadget/snps_udc_core: Move timer initialization earlier In-Reply-To: <1504222183-61202-28-git-send-email-keescook@chromium.org> Organization: http://mina86.com/ References: <1504222183-61202-1-git-send-email-keescook@chromium.org> <1504222183-61202-28-git-send-email-keescook@chromium.org> Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACP0lEQVQ4T23Sv2vbQBQHcBk1xE6WyALX107VUEgmn6+ouUwpEQQ6uRjttkWP4CkBg2M0BQLBdPFZYPsyFYo7qEtKDQ7on+t7+nF2Ux8ahD587717OmNYrOvycHsZ+o2r051wHTHysAvGb8ygvgu4QWT0sCmkgZCIEnlV2X8BtyraazFGDuxhmKSQJMlwHQ7v5MHSNxmz78rfElwAa3ieVD9e+hBhjaPDDG6NgFo2f4wBMNIo5YmRtF0RyDgFjJjlMIWbnuM4x9MMfABGTlN4qgIQB4A1DEyA1BHWtfeWNUMwiVJKoqh97KrkOO+qzgluVYLvFCUKAX73nONeBr7BGMdM6Sg0kuep03VywLaIzRiVr+GAzKlpQIsAFnWAG2e6DT5WmWDiudZMIc6hYrMOmeMQK9WX0B+/RfjzL9DI7Y9/Iayn29Ci0r2i4f9gMimMSZLCDMalgQGU5hnUtqAN0OGvEmO1Wnl0C0wWSCEHnuHBqmygxdxA8oWXwbipoc1EoNR9DqOpBpOJrnr0criQab9ZT4LL+wI+K7GBQH30CrhUruilgP9DRTrhVWZCiAyILP+wiuLeCKGTD6r/nc8LOJcAwR6IBTUs+7CASw3QFZ0MdA2PI3zNziH4ZKVhXCRMBjeZ1DWMekKwDCASwExy+NQ86TaykaDAFHO4aP48y4fIcDM5yOG8GcTLbOyp8A8azjJI93JFd1EA6yN8sSxMQJWoABqniRZVykYgRXErzrdqExAoUrRb0xfRp8p2A/4XmfilTtkDZ4cAAAAASUVORK5CYII= X-Face: -TR8(rDTHy/(xl?SfWd1|3:TTgDIatE^t'vop%*gVg[kn$t{EpK(P"VQ=~T2#ysNmJKN$"yTRLB4YQs$4{[.]Fc1)*O]3+XO^oXM>Q#b^ix,O)Zbn)q[y06$`e3?C)`CwR9y5riE=fv^X@x$y?D:XO6L&x4f-}}I4=VRNwiA^t1-ZrVK^07.Pi/57c_du'& OpenPGP: id=AC1F5F5CD41888F8CC8458582060401250751FF4; url=http://mina86.com/mina86.pub X-Hashcash: 1:20:170903:linux-kernel@vger.kernel.org::nFWf6IJJKWSaBsy+:00000000000000000000000000000000006Eo X-Hashcash: 1:20:170903:raviteja.garimella@broadcom.com::1f4k1nmghuRKZPdv:0000000000000000000000000000000E2I X-Hashcash: 1:20:170903:gregkh@linuxfoundation.org::II7h9+9PoXIl5NNC:0000000000000000000000000000000000015jO X-Hashcash: 1:20:170903:balbi@kernel.org::eiMZBuHZo/yCqvp0:01GUb X-Hashcash: 1:20:170903:keescook@chromium.org::TMUIOUj0ysnmtY0F:00000000000000000000000000000000000000000qzG X-Hashcash: 1:20:170903:tglx@linutronix.de::k5WW52CTvvUSEdmy:00000000000000000000000000000000000000000000FVg X-Hashcash: 1:20:170903:keescook@chromium.org::JtpErhE87PY5heH2:00000000000000000000000000000000000000002QUs X-Hashcash: 1:20:170903:linux-usb@vger.kernel.org::t1hMouLpfD13+BPk:0000000000000000000000000000000000005/Kz X-Hashcash: 1:20:170903:garsilva@embeddedor.com::2P2dmu4YmeYxjwQL:00000000000000000000000000000000000000CMtf Date: Sun, 03 Sep 2017 23:12:04 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v83LCHGp020844 Content-Length: 3720 Lines: 114 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 > Cc: Greg Kroah-Hartman > Cc: Raviteja Garimella > Cc: Michal Nazarewicz > Cc: "Gustavo A. R. Silva" > Cc: linux-usb@vger.kernel.org > Signed-off-by: Kees Cook > --- > 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»