lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ccd1587a-0368-4bde-9c72-4f10393c58b0@kernel.org>
Date: Fri, 29 Nov 2024 19:51:30 +0900
From: Damien Le Moal <dlemoal@...nel.org>
To: Manivannan Sadhasivam <manivannan.sadhasivam@...aro.org>, kw@...ux.com,
 gregkh@...uxfoundation.org, arnd@...db.de, lpieralisi@...nel.org,
 shuah@...nel.org
Cc: kishon@...nel.org, aman1.gupta@...sung.com, p.rajanbabu@...sung.com,
 linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org,
 bhelgaas@...gle.com, linux-arm-msm@...r.kernel.org, robh@...nel.org,
 linux-kselftest@...r.kernel.org
Subject: Re: [PATCH v2 2/4] misc: pci_endpoint_test: Fix the return value of
 IOCTL

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@...uxfoundation.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@...aro.org>

Looks OK to me.

Reviewed-by: Damien Le Moal <dlemoal@...nel.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, &param);
>  		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, &param);
>  		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, &param);
>  		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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ