All of lore.kernel.org
 help / color / mirror / Atom feed
From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: kishon@ti.com, lpieralisi@kernel.org, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org, mie@igel.co.jp, kw@linux.com
Subject: Re: [PATCH 2/5] misc: pci_endpoint_test: Fix the return value of IOCTL
Date: Sat, 20 Aug 2022 17:31:16 +0530	[thread overview]
Message-ID: <20220820120116.GC3151@thinkpad> (raw)
In-Reply-To: <Yv+rTZ1u7HXmS5Qk@kroah.com>

On Fri, Aug 19, 2022 at 05:25:01PM +0200, Greg KH wrote:
> On Fri, Aug 19, 2022 at 08:20:15PM +0530, Manivannan Sadhasivam wrote:
> > IOCTLs are supposed to return 0 for success and negative error codes for
> > failure. Currently, this driver is returning 0 for failure and 1 for
> > success, that's not correct. Hence, fix it!
> > 
> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > ---
> >  drivers/misc/pci_endpoint_test.c | 163 ++++++++++++++-----------------
> >  1 file changed, 76 insertions(+), 87 deletions(-)
> > 
> > diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
> > index db0458039d7d..bbf903c5a5bd 100644
> > --- a/drivers/misc/pci_endpoint_test.c
> > +++ b/drivers/misc/pci_endpoint_test.c
> > @@ -174,13 +174,12 @@ static void pci_endpoint_test_free_irq_vectors(struct pci_endpoint_test *test)
> >  	test->irq_type = IRQ_TYPE_UNDEFINED;
> >  }
> >  
> > -static bool pci_endpoint_test_alloc_irq_vectors(struct pci_endpoint_test *test,
> > +static int pci_endpoint_test_alloc_irq_vectors(struct pci_endpoint_test *test,
> >  						int type)
> >  {
> > -	int irq = -1;
> > +	int irq = -EINVAL;
> >  	struct pci_dev *pdev = test->pdev;
> >  	struct device *dev = &pdev->dev;
> > -	bool res = true;
> >  
> >  	switch (type) {
> >  	case IRQ_TYPE_LEGACY:
> > @@ -202,15 +201,16 @@ static bool pci_endpoint_test_alloc_irq_vectors(struct pci_endpoint_test *test,
> >  		dev_err(dev, "Invalid IRQ type selected\n");
> >  	}
> >  
> > +	test->irq_type = type;
> > +
> >  	if (irq < 0) {
> > -		irq = 0;
> > -		res = false;
> > +		test->num_irqs = 0;
> > +		return irq;
> 
> Why are you setting the type if there is an error?
> 

This was the original behaviour, so I kept it as it is. If it needs to be
changed, then it should be done in a separate patch I believe.

> 
> >  	}
> >  
> > -	test->irq_type = type;
> >  	test->num_irqs = irq;
> >  
> > -	return res;
> > +	return 0;
> >  }
> >  
> >  static void pci_endpoint_test_release_irq(struct pci_endpoint_test *test)
> > @@ -225,7 +225,7 @@ static void pci_endpoint_test_release_irq(struct pci_endpoint_test *test)
> >  	test->num_irqs = 0;
> >  }
> >  
> > -static bool pci_endpoint_test_request_irq(struct pci_endpoint_test *test)
> > +static int pci_endpoint_test_request_irq(struct pci_endpoint_test *test)
> >  {
> >  	int i;
> >  	int err;
> > @@ -240,7 +240,7 @@ static bool pci_endpoint_test_request_irq(struct pci_endpoint_test *test)
> >  			goto fail;
> >  	}
> >  
> > -	return true;
> > +	return 0;
> >  
> >  fail:
> >  	switch (irq_type) {
> > @@ -260,10 +260,10 @@ static bool pci_endpoint_test_request_irq(struct pci_endpoint_test *test)
> >  		break;
> >  	}
> >  
> > -	return false;
> > +	return err;
> >  }
> >  
> > -static bool pci_endpoint_test_bar(struct pci_endpoint_test *test,
> > +static int pci_endpoint_test_bar(struct pci_endpoint_test *test,
> >  				  enum pci_barno barno)
> >  {
> >  	int j;
> > @@ -272,7 +272,7 @@ static bool pci_endpoint_test_bar(struct pci_endpoint_test *test,
> >  	struct pci_dev *pdev = test->pdev;
> >  
> >  	if (!test->bar[barno])
> > -		return false;
> > +		return -ENOMEM;
> 
> How is this no memory?
>

No bar means a failure in pci_ioremap_bar() during probe. And that implies a
failure while mapping the device's BAR in host memory. So -ENOMEM seems to be
the apt error no.
 
> Shouldn't this not even get here if the allocation failed?
> 

No, the driver tries to map PCI_STD_NUM_BARS which is 6 and if some of them are
not available except BAR_0 then it just logs an error and continues. So it is
not fatal.

> >  
> >  	size = pci_resource_len(pdev, barno);
> >  
> > @@ -285,13 +285,13 @@ static bool pci_endpoint_test_bar(struct pci_endpoint_test *test,
> >  	for (j = 0; j < size; j += 4) {
> >  		val = pci_endpoint_test_bar_readl(test, barno, j);
> >  		if (val != 0xA0A0A0A0)
> > -			return false;
> > +			return -EINVAL;
> 
> Is this really an invalid value sent to the ioctl?
> 
> 
> >  	}
> >  
> > -	return true;
> > +	return 0;
> >  }
> >  
> > -static bool pci_endpoint_test_legacy_irq(struct pci_endpoint_test *test)
> > +static int pci_endpoint_test_legacy_irq(struct pci_endpoint_test *test)
> >  {
> >  	u32 val;
> >  
> > @@ -303,12 +303,12 @@ static bool pci_endpoint_test_legacy_irq(struct pci_endpoint_test *test)
> >  	val = wait_for_completion_timeout(&test->irq_raised,
> >  					  msecs_to_jiffies(1000));
> >  	if (!val)
> > -		return false;
> > +		return -ETIMEDOUT;
> >  
> > -	return true;
> > +	return 0;
> >  }
> >  
> > -static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test,
> > +static int pci_endpoint_test_msi_irq(struct pci_endpoint_test *test,
> >  				       u16 msi_num, bool msix)
> >  {
> >  	u32 val;
> > @@ -324,19 +324,18 @@ static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test,
> >  	val = wait_for_completion_timeout(&test->irq_raised,
> >  					  msecs_to_jiffies(1000));
> >  	if (!val)
> > -		return false;
> > +		return -ETIMEDOUT;
> >  
> > -	if (pci_irq_vector(pdev, msi_num - 1) == test->last_irq)
> > -		return true;
> > +	if (pci_irq_vector(pdev, msi_num - 1) != test->last_irq)
> > +		return -EINVAL;
> 
> Again, is this an invalid value passed to the ioctl?
> 
> Same for other places you are doing something and then returning this
> error value, are you sure that is correct?
> 
> -EINVAL should be "the values you sent me was incorrect", not "something
> bad happened based on what you gave me".
> 

Okay. Will revisit all of them.

Thanks,
Mani

-- 
மணிவண்ணன் சதாசிவம்

  reply	other threads:[~2022-08-20 12:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-19 14:50 [PATCH 0/5] pci_endpoint_test: Fix the return value of IOCTLs Manivannan Sadhasivam
2022-08-19 14:50 ` [PATCH 1/5] misc: pci_endpoint_test: Remove unnecessary WARN_ON Manivannan Sadhasivam
2022-08-19 15:27   ` Greg KH
2022-08-20 11:46     ` Manivannan Sadhasivam
2022-08-19 14:50 ` [PATCH 2/5] misc: pci_endpoint_test: Fix the return value of IOCTL Manivannan Sadhasivam
2022-08-19 15:20   ` Greg KH
2022-08-20 12:05     ` Manivannan Sadhasivam
2022-08-19 15:25   ` Greg KH
2022-08-20 12:01     ` Manivannan Sadhasivam [this message]
2022-08-19 14:50 ` [PATCH 3/5] tools: PCI: Fix parsing the return value of IOCTLs Manivannan Sadhasivam
2022-08-19 15:27   ` Greg KH
2022-08-20 11:47     ` Manivannan Sadhasivam
2022-08-22  4:25   ` Shunsuke Mie
2022-08-19 14:50 ` [PATCH 4/5] tools: PCI: Fix memory leak Manivannan Sadhasivam
2022-08-19 14:50 ` [PATCH 5/5] Documentation: PCI: endpoint: Use the correct return value of pcitest.sh Manivannan Sadhasivam

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=20220820120116.GC3151@thinkpad \
    --to=manivannan.sadhasivam@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kishon@ti.com \
    --cc=kw@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mie@igel.co.jp \
    /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.