From: Niklas Cassel <cassel@kernel.org>
To: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Cc: kw@linux.com, gregkh@linuxfoundation.org, arnd@arndb.de,
lpieralisi@kernel.org, shuah@kernel.org, kishon@kernel.org,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
bhelgaas@google.com, linux-arm-msm@vger.kernel.org,
robh@kernel.org, linux-kselftest@vger.kernel.org,
Damien Le Moal <dlemoal@kernel.org>
Subject: Re: [PATCH v4 1/3] misc: pci_endpoint_test: Fix the return value of IOCTL
Date: Tue, 31 Dec 2024 17:57:47 +0100 [thread overview]
Message-ID: <Z3Qii43XSnxvc4pp@ryzen> (raw)
In-Reply-To: <20241231131341.39292-2-manivannan.sadhasivam@linaro.org>
On Tue, Dec 31, 2024 at 06:43:39PM +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!
>
> Reported-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Closes: https://lore.kernel.org/all/YvzNg5ROnxEApDgS@kroah.com
> Fixes: 2c156ac71c6b ("misc: Add host side PCI driver for PCI test function device")
> Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
> drivers/misc/pci_endpoint_test.c | 250 +++++++++++++++----------------
> tools/pci/pcitest.c | 51 +++----
> 2 files changed, 148 insertions(+), 153 deletions(-)
>
> diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
> index 5c99da952b7a..7d3f78b6f854 100644
> --- a/drivers/misc/pci_endpoint_test.c
> +++ b/drivers/misc/pci_endpoint_test.c
> @@ -169,43 +169,47 @@ 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;
> struct pci_dev *pdev = test->pdev;
> struct device *dev = &pdev->dev;
> - bool res = true;
>
> switch (type) {
> case IRQ_TYPE_INTX:
> irq = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_INTX);
> - if (irq < 0)
> + if (irq < 0) {
> dev_err(dev, "Failed to get Legacy interrupt\n");
> + return -ENOSPC;
> + }
> +
> break;
> case IRQ_TYPE_MSI:
> irq = pci_alloc_irq_vectors(pdev, 1, 32, PCI_IRQ_MSI);
> - if (irq < 0)
> + if (irq < 0) {
> dev_err(dev, "Failed to get MSI interrupts\n");
> + return -ENOSPC;
> + }
> +
> break;
> case IRQ_TYPE_MSIX:
> irq = pci_alloc_irq_vectors(pdev, 1, 2048, PCI_IRQ_MSIX);
> - if (irq < 0)
> + if (irq < 0) {
> dev_err(dev, "Failed to get MSI-X interrupts\n");
> + return -ENOSPC;
From the pci_alloc_irq_vectors() kdoc:
* Return: number of allocated vectors (which might be smaller than
* @max_vecs), -ENOSPC if less than @min_vecs interrupt vectors are
* available, other errnos otherwise.
So pci_alloc_irq_vectors() can return errors different than ENOSPC,
and in that case, you will overwrite that error.
> @@ -442,9 +444,12 @@ 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;
>
> - return pci_irq_vector(pdev, msi_num - 1) == test->last_irq;
> + if (!(pci_irq_vector(pdev, msi_num - 1) == test->last_irq))
if (pci_irq_vector(pdev, msi_num - 1) != test->last_irq) ?
Or perhaps even:
ret = pci_irq_vector();
if (ret < 0)
return ret;
if (ret != test->last_irq)
return -EIO;
Otherwise, this looks good to me:
Reviewed-by: Niklas Cassel <cassel@kernel.org>
next prev parent reply other threads:[~2024-12-31 16:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-31 13:13 [PATCH v4 0/3] Migrate PCI Endpoint Subsystem tests to Kselftest Manivannan Sadhasivam
2024-12-31 13:13 ` [PATCH v4 1/3] misc: pci_endpoint_test: Fix the return value of IOCTL Manivannan Sadhasivam
2024-12-31 16:57 ` Niklas Cassel [this message]
2024-12-31 18:51 ` Manivannan Sadhasivam
2024-12-31 13:13 ` [PATCH v4 2/3] selftests: Move PCI Endpoint tests from tools/pci to Kselftests Manivannan Sadhasivam
2024-12-31 17:17 ` Niklas Cassel
2024-12-31 18:53 ` Manivannan Sadhasivam
2024-12-31 13:13 ` [PATCH v4 3/3] selftests: pci_endpoint: Migrate to Kselftest framework Manivannan Sadhasivam
2024-12-31 17:42 ` Niklas Cassel
2024-12-31 19:18 ` Manivannan Sadhasivam
2024-12-31 19:33 ` Niklas Cassel
2025-01-02 7:04 ` Manivannan Sadhasivam
2025-01-02 14:23 ` Niklas Cassel
2025-01-16 4:47 ` Manivannan Sadhasivam
2025-01-16 10:30 ` Niklas Cassel
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=Z3Qii43XSnxvc4pp@ryzen \
--to=cassel@kernel.org \
--cc=arnd@arndb.de \
--cc=bhelgaas@google.com \
--cc=dlemoal@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=kishon@kernel.org \
--cc=kw@linux.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=robh@kernel.org \
--cc=shuah@kernel.org \
/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