All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Marc Gonzalez <marc.w.gonzalez@free.fr>
Cc: Aman Sharma <amanharitsh123@gmail.com>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Andrew Murray <amurray@thegoodpenguin.co.uk>,
	Linus Walleij <linus.walleij@linaro.org>,
	Ryder Lee <ryder.lee@mediatek.com>,
	Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>,
	Hou Zhiqiang <Zhiqiang.Hou@nxp.com>,
	Mans Rullgard <mans@mansr.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
	Marc Zyngier <maz@kernel.org>
Subject: Re: [PATCH 4/5] pci: handled return value of platform_get_irq correctly
Date: Thu, 12 Mar 2020 09:11:02 -0500	[thread overview]
Message-ID: <20200312141102.GA93224@google.com> (raw)
In-Reply-To: <6e413f63-06e3-9613-97dc-ff5968a4f759@free.fr>

[+cc another Marc]

On Thu, Mar 12, 2020 at 10:53:06AM +0100, Marc Gonzalez wrote:
> On 11/03/2020 20:19, Aman Sharma wrote:
> 
> > diff --git a/drivers/pci/controller/pcie-tango.c b/drivers/pci/controller/pcie-tango.c
> > index 21a208da3f59..18c2c4313eb5 100644
> > --- a/drivers/pci/controller/pcie-tango.c
> > +++ b/drivers/pci/controller/pcie-tango.c
> > @@ -273,9 +273,9 @@ static int tango_pcie_probe(struct platform_device *pdev)
> >  		writel_relaxed(0, pcie->base + SMP8759_ENABLE + offset);
> >  
> >  	virq = platform_get_irq(pdev, 1);
> > -	if (virq <= 0) {
> > +	if (virq < 0) {
> >  		dev_err(dev, "Failed to map IRQ\n");
> > -		return -ENXIO;
> > +		return virq;
> >  	}
> >  
> >  	irq_dom = irq_domain_create_linear(fwnode, MSI_MAX, &dom_ops, pcie);
> 
> Weee, here we go again :-)
> 
> https://patchwork.kernel.org/patch/11066455/
> https://patchwork.kernel.org/patch/10006651/
> 
> Last time around, my understanding was that, going forward,
> the best solution was:
> 
> 	virq = platform_get_irq(...)
> 	if (virq <= 0)
> 		return virq ? : -ENODEV;
> 
> i.e. map 0 to -ENODEV, pass other errors as-is, remove the dev_err
> 
> @Bjorn/Lorenzo did you have a change of heart?

Yes.  In 10006651 (Oct 20, 2017), I thought:

  irq = platform_get_irq(pdev, 0);
  if (irq <= 0)
    return -ENODEV;

was fine.  In 11066455 (Aug 7, 2019), I said I thought I was wrong and
that:

  platform_get_irq() is a generic interface and we have to be able to
  interpret return values consistently.  The overwhelming consensus
  among platform_get_irq() callers is to treat "irq < 0" as an error,
  and I think we should follow suit.
  ...
  I think the best pattern is:

    irq = platform_get_irq(pdev, i);
    if (irq < 0)
      return irq;

I still think what I said in 2019 is the right approach.  I do see
your comment in 10006651 about this pattern:

  if (virq <= 0)
    return virq ? : -ENODEV;

but IMHO it's too complicated for general use.  Admittedly, it's not
*very* complicated, but it's a relatively unusual C idiom and I
stumble over it every time I see it.  If 0 is a special case I think
it should be mapped to a negative error in arch-specific code, which I
think is what Linus T suggested in [1].

I think there's still a large consensus that "irq < 0" is the error
case.  In the tree today we have about 1400 callers of
platform_get_irq() and platform_get_irq_byname() [2].  Of those,
almost 900 check for "irq < 0" [3], while only about 150 check for
"irq <= 0" [4] and about 15 use some variant of a "irq ? : -ENODEV"
pattern.

The bottom line is that in drivers/pci, I'd like to see either a
single style or a compelling argument for why some checks should be
"irq < 0" and others should be "irq <= 0".

[1] https://yarchive.net/comp/linux/zero.html
[2] $ git grep "=.*platform_get_irq" | wc -l
    1422
[3] $ git grep -A4 "=.*platform_get_irq" | grep "<\s*0" | wc -l
    894
[4] $ git grep -A4 "=.*platform_get_irq" | grep "<=\s*0" | wc -l
    151
[5] $ git grep -A4 "=.*platform_get_irq" | grep "return.*?.*:.*;" | wc -l
    15

WARNING: multiple messages have this Message-ID (diff)
From: Bjorn Helgaas <helgaas@kernel.org>
To: Marc Gonzalez <marc.w.gonzalez@free.fr>
Cc: Ryder Lee <ryder.lee@mediatek.com>,
	Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>,
	linux-pci@vger.kernel.org,
	Linus Walleij <linus.walleij@linaro.org>,
	Aman Sharma <amanharitsh123@gmail.com>,
	linux-kernel@vger.kernel.org,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	linux-mediatek@lists.infradead.org,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Marc Zyngier <maz@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Mans Rullgard <mans@mansr.com>,
	Hou Zhiqiang <Zhiqiang.Hou@nxp.com>,
	linux-arm-kernel@lists.infradead.org,
	Andrew Murray <amurray@thegoodpenguin.co.uk>
Subject: Re: [PATCH 4/5] pci: handled return value of platform_get_irq correctly
Date: Thu, 12 Mar 2020 09:11:02 -0500	[thread overview]
Message-ID: <20200312141102.GA93224@google.com> (raw)
In-Reply-To: <6e413f63-06e3-9613-97dc-ff5968a4f759@free.fr>

[+cc another Marc]

On Thu, Mar 12, 2020 at 10:53:06AM +0100, Marc Gonzalez wrote:
> On 11/03/2020 20:19, Aman Sharma wrote:
> 
> > diff --git a/drivers/pci/controller/pcie-tango.c b/drivers/pci/controller/pcie-tango.c
> > index 21a208da3f59..18c2c4313eb5 100644
> > --- a/drivers/pci/controller/pcie-tango.c
> > +++ b/drivers/pci/controller/pcie-tango.c
> > @@ -273,9 +273,9 @@ static int tango_pcie_probe(struct platform_device *pdev)
> >  		writel_relaxed(0, pcie->base + SMP8759_ENABLE + offset);
> >  
> >  	virq = platform_get_irq(pdev, 1);
> > -	if (virq <= 0) {
> > +	if (virq < 0) {
> >  		dev_err(dev, "Failed to map IRQ\n");
> > -		return -ENXIO;
> > +		return virq;
> >  	}
> >  
> >  	irq_dom = irq_domain_create_linear(fwnode, MSI_MAX, &dom_ops, pcie);
> 
> Weee, here we go again :-)
> 
> https://patchwork.kernel.org/patch/11066455/
> https://patchwork.kernel.org/patch/10006651/
> 
> Last time around, my understanding was that, going forward,
> the best solution was:
> 
> 	virq = platform_get_irq(...)
> 	if (virq <= 0)
> 		return virq ? : -ENODEV;
> 
> i.e. map 0 to -ENODEV, pass other errors as-is, remove the dev_err
> 
> @Bjorn/Lorenzo did you have a change of heart?

Yes.  In 10006651 (Oct 20, 2017), I thought:

  irq = platform_get_irq(pdev, 0);
  if (irq <= 0)
    return -ENODEV;

was fine.  In 11066455 (Aug 7, 2019), I said I thought I was wrong and
that:

  platform_get_irq() is a generic interface and we have to be able to
  interpret return values consistently.  The overwhelming consensus
  among platform_get_irq() callers is to treat "irq < 0" as an error,
  and I think we should follow suit.
  ...
  I think the best pattern is:

    irq = platform_get_irq(pdev, i);
    if (irq < 0)
      return irq;

I still think what I said in 2019 is the right approach.  I do see
your comment in 10006651 about this pattern:

  if (virq <= 0)
    return virq ? : -ENODEV;

but IMHO it's too complicated for general use.  Admittedly, it's not
*very* complicated, but it's a relatively unusual C idiom and I
stumble over it every time I see it.  If 0 is a special case I think
it should be mapped to a negative error in arch-specific code, which I
think is what Linus T suggested in [1].

I think there's still a large consensus that "irq < 0" is the error
case.  In the tree today we have about 1400 callers of
platform_get_irq() and platform_get_irq_byname() [2].  Of those,
almost 900 check for "irq < 0" [3], while only about 150 check for
"irq <= 0" [4] and about 15 use some variant of a "irq ? : -ENODEV"
pattern.

The bottom line is that in drivers/pci, I'd like to see either a
single style or a compelling argument for why some checks should be
"irq < 0" and others should be "irq <= 0".

[1] https://yarchive.net/comp/linux/zero.html
[2] $ git grep "=.*platform_get_irq" | wc -l
    1422
[3] $ git grep -A4 "=.*platform_get_irq" | grep "<\s*0" | wc -l
    894
[4] $ git grep -A4 "=.*platform_get_irq" | grep "<=\s*0" | wc -l
    151
[5] $ git grep -A4 "=.*platform_get_irq" | grep "return.*?.*:.*;" | wc -l
    15

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

WARNING: multiple messages have this Message-ID (diff)
From: Bjorn Helgaas <helgaas@kernel.org>
To: Marc Gonzalez <marc.w.gonzalez@free.fr>
Cc: Ryder Lee <ryder.lee@mediatek.com>,
	Karthikeyan Mitran <m.karthikeyan@mobiveil.co.in>,
	linux-pci@vger.kernel.org,
	Linus Walleij <linus.walleij@linaro.org>,
	Aman Sharma <amanharitsh123@gmail.com>,
	linux-kernel@vger.kernel.org,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	linux-mediatek@lists.infradead.org,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Marc Zyngier <maz@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Mans Rullgard <mans@mansr.com>,
	Hou Zhiqiang <Zhiqiang.Hou@nxp.com>,
	linux-arm-kernel@lists.infradead.org,
	Andrew Murray <amurray@thegoodpenguin.co.uk>
Subject: Re: [PATCH 4/5] pci: handled return value of platform_get_irq correctly
Date: Thu, 12 Mar 2020 09:11:02 -0500	[thread overview]
Message-ID: <20200312141102.GA93224@google.com> (raw)
In-Reply-To: <6e413f63-06e3-9613-97dc-ff5968a4f759@free.fr>

[+cc another Marc]

On Thu, Mar 12, 2020 at 10:53:06AM +0100, Marc Gonzalez wrote:
> On 11/03/2020 20:19, Aman Sharma wrote:
> 
> > diff --git a/drivers/pci/controller/pcie-tango.c b/drivers/pci/controller/pcie-tango.c
> > index 21a208da3f59..18c2c4313eb5 100644
> > --- a/drivers/pci/controller/pcie-tango.c
> > +++ b/drivers/pci/controller/pcie-tango.c
> > @@ -273,9 +273,9 @@ static int tango_pcie_probe(struct platform_device *pdev)
> >  		writel_relaxed(0, pcie->base + SMP8759_ENABLE + offset);
> >  
> >  	virq = platform_get_irq(pdev, 1);
> > -	if (virq <= 0) {
> > +	if (virq < 0) {
> >  		dev_err(dev, "Failed to map IRQ\n");
> > -		return -ENXIO;
> > +		return virq;
> >  	}
> >  
> >  	irq_dom = irq_domain_create_linear(fwnode, MSI_MAX, &dom_ops, pcie);
> 
> Weee, here we go again :-)
> 
> https://patchwork.kernel.org/patch/11066455/
> https://patchwork.kernel.org/patch/10006651/
> 
> Last time around, my understanding was that, going forward,
> the best solution was:
> 
> 	virq = platform_get_irq(...)
> 	if (virq <= 0)
> 		return virq ? : -ENODEV;
> 
> i.e. map 0 to -ENODEV, pass other errors as-is, remove the dev_err
> 
> @Bjorn/Lorenzo did you have a change of heart?

Yes.  In 10006651 (Oct 20, 2017), I thought:

  irq = platform_get_irq(pdev, 0);
  if (irq <= 0)
    return -ENODEV;

was fine.  In 11066455 (Aug 7, 2019), I said I thought I was wrong and
that:

  platform_get_irq() is a generic interface and we have to be able to
  interpret return values consistently.  The overwhelming consensus
  among platform_get_irq() callers is to treat "irq < 0" as an error,
  and I think we should follow suit.
  ...
  I think the best pattern is:

    irq = platform_get_irq(pdev, i);
    if (irq < 0)
      return irq;

I still think what I said in 2019 is the right approach.  I do see
your comment in 10006651 about this pattern:

  if (virq <= 0)
    return virq ? : -ENODEV;

but IMHO it's too complicated for general use.  Admittedly, it's not
*very* complicated, but it's a relatively unusual C idiom and I
stumble over it every time I see it.  If 0 is a special case I think
it should be mapped to a negative error in arch-specific code, which I
think is what Linus T suggested in [1].

I think there's still a large consensus that "irq < 0" is the error
case.  In the tree today we have about 1400 callers of
platform_get_irq() and platform_get_irq_byname() [2].  Of those,
almost 900 check for "irq < 0" [3], while only about 150 check for
"irq <= 0" [4] and about 15 use some variant of a "irq ? : -ENODEV"
pattern.

The bottom line is that in drivers/pci, I'd like to see either a
single style or a compelling argument for why some checks should be
"irq < 0" and others should be "irq <= 0".

[1] https://yarchive.net/comp/linux/zero.html
[2] $ git grep "=.*platform_get_irq" | wc -l
    1422
[3] $ git grep -A4 "=.*platform_get_irq" | grep "<\s*0" | wc -l
    894
[4] $ git grep -A4 "=.*platform_get_irq" | grep "<=\s*0" | wc -l
    151
[5] $ git grep -A4 "=.*platform_get_irq" | grep "return.*?.*:.*;" | wc -l
    15

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-03-12 14:11 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-11 19:19 [PATCH 0/5] Handled return value of platform_get_irq correctly Aman Sharma
2020-03-11 19:19 ` Aman Sharma
2020-03-11 19:19 ` Aman Sharma
2020-03-11 19:19 ` [PATCH 1/5] pci: handled " Aman Sharma
2020-03-11 19:19   ` Aman Sharma
2020-03-11 19:19   ` Aman Sharma
2020-03-11 20:57   ` Bjorn Helgaas
2020-04-06 21:28     ` Bjorn Helgaas
2020-03-12 14:07   ` Linus Walleij
2020-03-12 14:07     ` Linus Walleij
2020-03-12 14:07     ` Linus Walleij
2020-03-12 19:02     ` Bjorn Helgaas
2020-03-12 19:02       ` Bjorn Helgaas
2020-03-12 19:02       ` Bjorn Helgaas
2020-03-12 22:45       ` Linus Walleij
2020-03-12 22:45         ` Linus Walleij
2020-03-12 22:45         ` Linus Walleij
2020-03-11 19:19 ` [PATCH 2/5] pci: added check for return value of platform_get_irq Aman Sharma
2020-03-11 19:19   ` Aman Sharma
2020-03-11 19:19   ` Aman Sharma
2020-03-11 19:19 ` [PATCH 3/5] pci: handled return value of platform_get_irq correctly Aman Sharma
2020-03-11 19:19   ` Aman Sharma
2020-03-11 19:19   ` Aman Sharma
2020-03-11 19:19 ` [PATCH 4/5] " Aman Sharma
2020-03-11 19:19   ` Aman Sharma
2020-03-11 19:19   ` Aman Sharma
2020-03-12  9:53   ` Marc Gonzalez
2020-03-12  9:53     ` Marc Gonzalez
2020-03-12  9:53     ` Marc Gonzalez
2020-03-12 14:11     ` Bjorn Helgaas [this message]
2020-03-12 14:11       ` Bjorn Helgaas
2020-03-12 14:11       ` Bjorn Helgaas
2020-03-12 15:53       ` Marc Gonzalez
2020-03-12 15:53         ` Marc Gonzalez
2020-03-12 15:53         ` Marc Gonzalez
2020-03-13 21:05       ` Thomas Gleixner
2020-03-13 21:05         ` Thomas Gleixner
2020-03-13 21:05         ` Thomas Gleixner
2020-03-13 21:56         ` Bjorn Helgaas
2020-03-13 21:56           ` Bjorn Helgaas
2020-03-13 21:56           ` Bjorn Helgaas
2020-03-17 22:03           ` Bjorn Helgaas
2020-03-17 22:03             ` Bjorn Helgaas
2020-03-17 22:03             ` Bjorn Helgaas
2020-03-18 13:42             ` Thomas Gleixner
2020-03-18 13:42               ` Thomas Gleixner
2020-03-18 13:42               ` Thomas Gleixner
2020-03-18 22:22               ` Bjorn Helgaas
2020-03-18 22:22                 ` Bjorn Helgaas
2020-03-18 22:22                 ` Bjorn Helgaas
2020-03-19  8:47                 ` Thomas Gleixner
2020-03-19  8:47                   ` Thomas Gleixner
2020-03-19  8:47                   ` Thomas Gleixner
2020-03-19 21:35                   ` Bjorn Helgaas
2020-03-19 21:35                     ` Bjorn Helgaas
2020-03-19 21:35                     ` Bjorn Helgaas
2020-03-11 19:19 ` [PATCH 5/5] pci: added check for return value of platform_get_irq Aman Sharma
2020-03-11 19:19   ` Aman Sharma
2020-03-11 19:19   ` Aman Sharma

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=20200312141102.GA93224@google.com \
    --to=helgaas@kernel.org \
    --cc=Zhiqiang.Hou@nxp.com \
    --cc=amanharitsh123@gmail.com \
    --cc=amurray@thegoodpenguin.co.uk \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=m.karthikeyan@mobiveil.co.in \
    --cc=mans@mansr.com \
    --cc=marc.w.gonzalez@free.fr \
    --cc=matthias.bgg@gmail.com \
    --cc=maz@kernel.org \
    --cc=ryder.lee@mediatek.com \
    --cc=thomas.petazzoni@bootlin.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.