[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220824123010.51763-3-manivannan.sadhasivam@linaro.org>
Date: Wed, 24 Aug 2022 18:00:07 +0530
From: Manivannan Sadhasivam <manivannan.sadhasivam@...aro.org>
To: kishon@...com, gregkh@...uxfoundation.org, lpieralisi@...nel.org
Cc: linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org,
mie@...l.co.jp, kw@...ux.com,
Manivannan Sadhasivam <manivannan.sadhasivam@...aro.org>,
stable@...r.kernel.org
Subject: [PATCH v2 2/5] tools: PCI: Fix parsing the return value of IOCTLs
"pci_endpoint_test" driver now returns 0 for success and negative error
code for failure. So adapt to the change by reporting FAILURE if the
return value is < 0, and SUCCESS otherwise.
Cc: stable@...r.kernel.org #5.10
Fixes: 3f2ed8134834 ("tools: PCI: Add a userspace tool to test PCI endpoint")
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@...aro.org>
---
tools/pci/pcitest.c | 41 +++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/tools/pci/pcitest.c b/tools/pci/pcitest.c
index 441b54234635..a4e5b17cc3b5 100644
--- a/tools/pci/pcitest.c
+++ b/tools/pci/pcitest.c
@@ -18,7 +18,6 @@
#define BILLION 1E9
-static char *result[] = { "NOT OKAY", "OKAY" };
static char *irq[] = { "LEGACY", "MSI", "MSI-X" };
struct pci_test {
@@ -54,9 +53,9 @@ 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, "FAILED\n");
else
- fprintf(stdout, "%s\n", result[ret]);
+ fprintf(stdout, "SUCCESS\n");
}
if (test->set_irqtype) {
@@ -65,16 +64,18 @@ static int run_test(struct pci_test *test)
if (ret < 0)
fprintf(stdout, "FAILED\n");
else
- fprintf(stdout, "%s\n", result[ret]);
+ fprintf(stdout, "SUCCESS\n");
}
if (test->get_irqtype) {
ret = ioctl(fd, PCITEST_GET_IRQTYPE);
fprintf(stdout, "GET IRQ TYPE:\t\t");
- if (ret < 0)
+ if (ret < 0) {
fprintf(stdout, "FAILED\n");
- else
+ } else {
fprintf(stdout, "%s\n", irq[ret]);
+ ret = 0;
+ }
}
if (test->clear_irq) {
@@ -83,34 +84,34 @@ static int run_test(struct pci_test *test)
if (ret < 0)
fprintf(stdout, "FAILED\n");
else
- fprintf(stdout, "%s\n", result[ret]);
+ fprintf(stdout, "SUCCESS\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, "FAILED\n");
else
- fprintf(stdout, "%s\n", result[ret]);
+ fprintf(stdout, "SUCCESS\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, "FAILED\n");
else
- fprintf(stdout, "%s\n", result[ret]);
+ fprintf(stdout, "SUCCESS\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, "FAILED\n");
else
- fprintf(stdout, "%s\n", result[ret]);
+ fprintf(stdout, "SUCCESS\n");
}
if (test->write) {
@@ -120,9 +121,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, "FAILED\n");
else
- fprintf(stdout, "%s\n", result[ret]);
+ fprintf(stdout, "SUCCESS\n");
}
if (test->read) {
@@ -132,9 +133,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, "FAILED\n");
else
- fprintf(stdout, "%s\n", result[ret]);
+ fprintf(stdout, "SUCCESS\n");
}
if (test->copy) {
@@ -144,14 +145,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, "FAILED\n");
else
- fprintf(stdout, "%s\n", result[ret]);
+ fprintf(stdout, "SUCCESS\n");
}
fflush(stdout);
close(fd);
- return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */
+ return ret;
}
int main(int argc, char **argv)
--
2.25.1
Powered by blists - more mailing lists