diff mbox series

[3/5] tools: PCI: Fix parsing the return value of IOCTLs

Message ID 20220819145018.35732-4-manivannan.sadhasivam@linaro.org (mailing list archive)
State Superseded
Headers show
Series pci_endpoint_test: Fix the return value of IOCTLs | expand

Commit Message

Manivannan Sadhasivam Aug. 19, 2022, 2:50 p.m. UTC
"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.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 tools/pci/pcitest.c | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

Comments

Greg KH Aug. 19, 2022, 3:27 p.m. UTC | #1
On Fri, Aug 19, 2022 at 08:20:16PM +0530, Manivannan Sadhasivam wrote:
> "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.
> 
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

Fixes: tag and cc: stable?

thanks,

greg k-h
Manivannan Sadhasivam Aug. 20, 2022, 11:47 a.m. UTC | #2
On Fri, Aug 19, 2022 at 05:27:24PM +0200, Greg KH wrote:
> On Fri, Aug 19, 2022 at 08:20:16PM +0530, Manivannan Sadhasivam wrote:
> > "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.
> > 
> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> 
> Fixes: tag and cc: stable?
> 

Okay, then the same needs to be done for pci_endpoint_test and Documentation.

Thanks,
Mani

> thanks,
> 
> greg k-h
Shunsuke Mie Aug. 22, 2022, 4:25 a.m. UTC | #3
2022年8月19日(金) 23:50 Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>:
>
> "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.
>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.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, &param);
>                 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, &param);
>                 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, &param);
>                 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
>

Don't you use the errno of ioctl?

Thanks,
Shunsuke
diff mbox series

Patch

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, &param);
 		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, &param);
 		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, &param);
 		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)