[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6677e2c6-b621-4c7e-9dd6-631a02ce5996@kili.mountain>
Date: Thu, 23 Mar 2023 17:06:14 +0300
From: Dan Carpenter <error27@...il.com>
To: Oliver Neukum <oneukum@...e.com>
Cc: Sergei Shtylyov <sergei.shtylyov@...il.com>,
Mingxuan Xiang <mx_xiang@...t.edu.cn>,
Thinh Nguyen <Thinh.Nguyen@...opsys.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
hust-os-kernel-patches@...glegroups.com,
Dongliang Mu <dzm91@...t.edu.cn>, linux-usb@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] usb: dwc3: host: remove dead code in
dwc3_host_get_irq()
On Thu, Mar 23, 2023 at 02:48:56PM +0100, Oliver Neukum wrote:
> On 23.03.23 12:13, Dan Carpenter wrote:
>
> > > > > v1->v2: remove redundant goto
> > > > > drivers/usb/dwc3/host.c | 4 ----
> > > > > 1 file changed, 4 deletions(-)
> > > > >
> > > > > diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
> > > > > index f6f13e7f1ba1..ca1e8294e835 100644
> > > > > --- a/drivers/usb/dwc3/host.c
> > > > > +++ b/drivers/usb/dwc3/host.c
> > > > > @@ -54,12 +54,8 @@ static int dwc3_host_get_irq(struct dwc3 *dwc)
> > > > > irq = platform_get_irq(dwc3_pdev, 0);
> > > > > if (irq > 0) {
> > > > > dwc3_host_fill_xhci_irq_res(dwc, irq, NULL);
> > > > > - goto out;
> > > > > }
> > > >
> > > > Now drop {} please. :-)
> > >
> > > Well, no, please drop the whole patch.
> > > If platform_get_irq() returns -EPROBE_DEFER you now give that
> > > as a return value.
> > >
> > > This tiny bit of optimization is not worth changing semantics.
> >
> > The v2 patch doesn't change the semantics. Mine did though...
>
> Now I may be dense, but let's look at the current code:
>
> irq = platform_get_irq(dwc3_pdev, 0);
>
> assuming irq = -EPROBE_DEFER
>
> if (irq > 0) {
>
> not taken
> dwc3_host_fill_xhci_irq_res(dwc, irq, NULL);
> goto out;
> }
>
> if (!irq)
>
> irq != 0
You've reversed this if statement in your head. It says that if
platform_get_irq() returns zero, then return -EINVAL.
The problem that Mingxuan is trying to address is that checking for zero
is dead code and sometimes represents a bug when people check for zero
instead of negatives.
> irq = -EINVAL;
>
> out:
> return irq;
>
> returning -EINVAL
We do *want* it to return -EPROBE_DEFER as the current code does.
regards,
dan carpenter
Powered by blists - more mailing lists