From: Damien Le Moal <dlemoal@kernel.org>
To: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
kw@linux.com, gregkh@linuxfoundation.org, arnd@arndb.de,
lpieralisi@kernel.org, shuah@kernel.org
Cc: kishon@kernel.org, aman1.gupta@samsung.com,
p.rajanbabu@samsung.com, 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
Subject: Re: [PATCH v2 2/4] misc: pci_endpoint_test: Fix the return value of IOCTL
Date: Fri, 29 Nov 2024 19:51:30 +0900 [thread overview]
Message-ID: <ccd1587a-0368-4bde-9c72-4f10393c58b0@kernel.org> (raw)
In-Reply-To: <20241129092415.29437-3-manivannan.sadhasivam@linaro.org>
On 11/29/24 18:24, 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")
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Looks OK to me.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
One nit below.
[...]
> static void pci_endpoint_test_remove(struct pci_dev *pdev)
> diff --git a/tools/pci/pcitest.c b/tools/pci/pcitest.c
> index 470258009ddc..545e04ad63a2 100644
> --- a/tools/pci/pcitest.c
> +++ b/tools/pci/pcitest.c
> @@ -16,7 +16,6 @@
>
> #include <linux/pcitest.h>
>
> -static char *result[] = { "NOT OKAY", "OKAY" };
> static char *irq[] = { "LEGACY", "MSI", "MSI-X" };
>
> struct pci_test {
> @@ -52,63 +51,65 @@ static int run_test(struct pci_test *test)
> ret = ioctl(fd, PCITEST_BAR, test->barnum);
> fprintf(stdout, "BAR%d:\t\t", test->barnum);
> if (ret < 0)
> - fprintf(stdout, "TEST FAILED\n");
> + fprintf(stdout, "NOT OKAY\n");
> else
> - fprintf(stdout, "%s\n", result[ret]);
> + fprintf(stdout, "OKAY\n");
Maybe replace all this "if (ret < 0) ... else ..." and all the ones below with
something a call to:
static void test_result(int ret)
{
fprintf(stdout, "%sOKAY\n", ret < 0 ? "NOT " : "");
}
or simply with the call:
fprintf(stdout, "%sOKAY\n", ret < 0 ? "NOT " : "");
to avoid all these repetition.
> }
>
> if (test->set_irqtype) {
> ret = ioctl(fd, PCITEST_SET_IRQTYPE, test->irqtype);
> fprintf(stdout, "SET IRQ TYPE TO %s:\t\t", irq[test->irqtype]);
> if (ret < 0)
> - fprintf(stdout, "FAILED\n");
> + fprintf(stdout, "NOT OKAY\n");
> else
> - fprintf(stdout, "%s\n", result[ret]);
> + fprintf(stdout, "OKAY\n");
> }
>
> if (test->get_irqtype) {
> ret = ioctl(fd, PCITEST_GET_IRQTYPE);
> fprintf(stdout, "GET IRQ TYPE:\t\t");
> - if (ret < 0)
> - fprintf(stdout, "FAILED\n");
> - else
> + if (ret < 0) {
> + fprintf(stdout, "NOT OKAY\n");
> + } else {
> fprintf(stdout, "%s\n", irq[ret]);
> + ret = 0;
> + }
> }
>
> if (test->clear_irq) {
> ret = ioctl(fd, PCITEST_CLEAR_IRQ);
> fprintf(stdout, "CLEAR IRQ:\t\t");
> if (ret < 0)
> - fprintf(stdout, "FAILED\n");
> + fprintf(stdout, "NOT OKAY\n");
> else
> - fprintf(stdout, "%s\n", result[ret]);
> + fprintf(stdout, "OKAY\n");
> }
>
> if (test->legacyirq) {
> ret = ioctl(fd, PCITEST_LEGACY_IRQ, 0);
> fprintf(stdout, "LEGACY IRQ:\t");
> if (ret < 0)
> - fprintf(stdout, "TEST FAILED\n");
> + fprintf(stdout, "NOT OKAY\n");
> else
> - fprintf(stdout, "%s\n", result[ret]);
> + fprintf(stdout, "OKAY\n");
> }
>
> if (test->msinum > 0 && test->msinum <= 32) {
> ret = ioctl(fd, PCITEST_MSI, test->msinum);
> fprintf(stdout, "MSI%d:\t\t", test->msinum);
> if (ret < 0)
> - fprintf(stdout, "TEST FAILED\n");
> + fprintf(stdout, "NOT OKAY\n");
> else
> - fprintf(stdout, "%s\n", result[ret]);
> + fprintf(stdout, "OKAY\n");
> }
>
> if (test->msixnum > 0 && test->msixnum <= 2048) {
> ret = ioctl(fd, PCITEST_MSIX, test->msixnum);
> fprintf(stdout, "MSI-X%d:\t\t", test->msixnum);
> if (ret < 0)
> - fprintf(stdout, "TEST FAILED\n");
> + fprintf(stdout, "NOT OKAY\n");
> else
> - fprintf(stdout, "%s\n", result[ret]);
> + fprintf(stdout, "OKAY\n");
> }
>
> if (test->write) {
> @@ -118,9 +119,9 @@ static int run_test(struct pci_test *test)
> ret = ioctl(fd, PCITEST_WRITE, ¶m);
> fprintf(stdout, "WRITE (%7ld bytes):\t\t", test->size);
> if (ret < 0)
> - fprintf(stdout, "TEST FAILED\n");
> + fprintf(stdout, "NOT OKAY\n");
> else
> - fprintf(stdout, "%s\n", result[ret]);
> + fprintf(stdout, "OKAY\n");
> }
>
> if (test->read) {
> @@ -130,9 +131,9 @@ static int run_test(struct pci_test *test)
> ret = ioctl(fd, PCITEST_READ, ¶m);
> fprintf(stdout, "READ (%7ld bytes):\t\t", test->size);
> if (ret < 0)
> - fprintf(stdout, "TEST FAILED\n");
> + fprintf(stdout, "NOT OKAY\n");
> else
> - fprintf(stdout, "%s\n", result[ret]);
> + fprintf(stdout, "OKAY\n");
> }
>
> if (test->copy) {
> @@ -142,14 +143,14 @@ static int run_test(struct pci_test *test)
> ret = ioctl(fd, PCITEST_COPY, ¶m);
> fprintf(stdout, "COPY (%7ld bytes):\t\t", test->size);
> if (ret < 0)
> - fprintf(stdout, "TEST FAILED\n");
> + fprintf(stdout, "NOT OKAY\n");
> else
> - fprintf(stdout, "%s\n", result[ret]);
> + fprintf(stdout, "OKAY\n");
> }
>
> fflush(stdout);
> close(fd);
> - return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */
> + return ret;
> }
>
> int main(int argc, char **argv)
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2024-11-29 10:51 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-29 9:24 [PATCH v2 0/4] Migrate PCI Endpoint Subsystem tests to Kselftest Manivannan Sadhasivam
2024-11-29 9:24 ` [PATCH v2 1/4] PCI: qcom-ep: Mark BAR0/BAR2 as 64bit BARs and BAR1/BAR3 as RESERVED Manivannan Sadhasivam
2024-11-29 14:38 ` Dmitry Baryshkov
2024-11-29 19:55 ` Bjorn Helgaas
2024-11-30 16:17 ` Greg KH
2024-12-02 12:58 ` Manivannan Sadhasivam
2024-12-02 17:40 ` Bjorn Helgaas
2024-11-29 9:24 ` [PATCH v2 2/4] misc: pci_endpoint_test: Fix the return value of IOCTL Manivannan Sadhasivam
2024-11-29 10:51 ` Damien Le Moal [this message]
2024-11-29 16:30 ` Manivannan Sadhasivam
2024-12-11 7:47 ` Manivannan Sadhasivam
2024-11-29 9:24 ` [PATCH v2 3/4] selftests: Move PCI Endpoint tests from tools/pci to Kselftests Manivannan Sadhasivam
2024-11-29 9:24 ` [PATCH v2 4/4] selftests: pci_endpoint: Migrate to Kselftest framework Manivannan Sadhasivam
2024-11-29 13:51 ` Niklas Cassel
2024-11-29 16:35 ` Manivannan Sadhasivam
2024-11-29 16:42 ` Niklas Cassel
2024-11-29 16:52 ` Manivannan Sadhasivam
2024-11-29 17:13 ` Niklas Cassel
2024-11-29 18:25 ` 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=ccd1587a-0368-4bde-9c72-4f10393c58b0@kernel.org \
--to=dlemoal@kernel.org \
--cc=aman1.gupta@samsung.com \
--cc=arnd@arndb.de \
--cc=bhelgaas@google.com \
--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=p.rajanbabu@samsung.com \
--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