Re: [PATCH] scsi: 3ware: fix return 0 on the error path of probe

From: Anton Vasilyev
Date: Sat Jul 28 2018 - 11:18:26 EST


Adam,

3w-9xxx: twa_probe():

There is check of retval:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-9xxx.c#n2010

retval without assignement is 0 on fail ofÂtwa_initialize_device_extension():
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-9xxx.c#n2040

And this 0 is returned from probe on the error path.

Same pattern is true for all other cases from patch.

-Anton

27 ÐÑÐ. 2018 Ð. 9:42 ÐÐ ÐÐÐÑÐÐÐÐÑÐÐÑ "adam radford" <aradford@xxxxxxxxx> ÐÐÐÐÑÐÐ:
On Fri, Jul 27, 2018 at 6:52 AM Anton Vasilyev <vasilyev@xxxxxxxxx> wrote:
>
> tw_probe() returns 0 in case of fail of tw_initialize_device_extension(),
> pci_resource_start() or tw_reset_sequence() and releases resources.
> twl_probe() returns 0 in case of fail of twl_initialize_device_extension(),
> pci_iomap() and twl_reset_sequence().
> twa_probe() returns 0 in case of fail of tw_initialize_device_extension(),
> ioremap() and twa_reset_sequence().
>
>
> The patch adds retval initialization for these cases.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Anton Vasilyev <vasilyev@xxxxxxxxx>
> ---
>Â drivers/scsi/3w-9xxx.c | 6 +++++-
> drivers/scsi/3w-sas.c | 3 +++
>Â drivers/scsi/3w-xxxx.c | 2 ++
>Â 3 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
> index 99ba4a770406..27521fc3ef5a 100644
> --- a/drivers/scsi/3w-9xxx.c
> +++ b/drivers/scsi/3w-9xxx.c
> @@ -2038,6 +2038,7 @@ static int twa_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
>
>Â Â Â Â Âif (twa_initialize_device_extension(tw_dev)) {
>Â Â Â Â Â Â Â Â ÂTW_PRINTK(tw_dev->host, TW_DRIVER, 0x25, "Failed to initialize device extension");
> +Â Â Â Â Â Â Â Âretval = -ENOMEM;
>Â Â Â Â Â Â Â Â Âgoto out_free_device_extension;
>Â Â Â Â Â}
>
> @@ -2060,6 +2061,7 @@ static int twa_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
>Â Â Â Â Âtw_dev->base_addr = ioremap(mem_addr, mem_len);
>Â Â Â Â Âif (!tw_dev->base_addr) {
>Â Â Â Â Â Â Â Â ÂTW_PRINTK(tw_dev->host, TW_DRIVER, 0x35, "Failed to ioremap");
> +Â Â Â Â Â Â Â Âretval = -ENOMEM;
>Â Â Â Â Â Â Â Â Âgoto out_release_mem_region;
>Â Â Â Â Â}
>
> @@ -2067,8 +2069,10 @@ static int twa_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
>Â Â Â Â ÂTW_DISABLE_INTERRUPTS(tw_dev);
>
>Â Â Â Â Â/* Initialize the card */
> -Â Â Â Âif (twa_reset_sequence(tw_dev, 0))
> +Â Â Â Âif (twa_reset_sequence(tw_dev, 0)) {
> +Â Â Â Â Â Â Â Âretval = -ENOMEM;
>Â Â Â Â Â Â Â Â Âgoto out_iounmap;
> +Â Â Â Â}
>
>Â Â Â Â Â/* Set host specific parameters */
>Â Â Â Â Âif ((pdev->device == PCI_DEVICE_ID_3WARE_9650SE) ||
> diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
> index cf9f2a09b47d..40c1e6e64f58 100644
> --- a/drivers/scsi/3w-sas.c
> +++ b/drivers/scsi/3w-sas.c
> @@ -1594,6 +1594,7 @@ static int twl_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
>
>Â Â Â Â Âif (twl_initialize_device_extension(tw_dev)) {
>Â Â Â Â Â Â Â Â ÂTW_PRINTK(tw_dev->host, TW_DRIVER, 0x1a, "Failed to initialize device extension");
> +Â Â Â Â Â Â Â Âretval = -ENOMEM;
>Â Â Â Â Â Â Â Â Âgoto out_free_device_extension;
>Â Â Â Â Â}
>
> @@ -1608,6 +1609,7 @@ static int twl_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
>Â Â Â Â Âtw_dev->base_addr = pci_iomap(pdev, 1, 0);
>Â Â Â Â Âif (!tw_dev->base_addr) {
>Â Â Â Â Â Â Â Â ÂTW_PRINTK(tw_dev->host, TW_DRIVER, 0x1c, "Failed to ioremap");
> +Â Â Â Â Â Â Â Âretval = -ENOMEM;
>Â Â Â Â Â Â Â Â Âgoto out_release_mem_region;
>Â Â Â Â Â}
>
> @@ -1617,6 +1619,7 @@ static int twl_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
>Â Â Â Â Â/* Initialize the card */
>Â Â Â Â Âif (twl_reset_sequence(tw_dev, 0)) {
>Â Â Â Â Â Â Â Â ÂTW_PRINTK(tw_dev->host, TW_DRIVER, 0x1d, "Controller reset failed during probe");
> +Â Â Â Â Â Â Â Âretval = -ENOMEM;
>Â Â Â Â Â Â Â Â Âgoto out_iounmap;
>Â Â Â Â Â}
>
> diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
> index f6179e3d6953..961ea6f7def8 100644
> --- a/drivers/scsi/3w-xxxx.c
> +++ b/drivers/scsi/3w-xxxx.c
> @@ -2280,6 +2280,7 @@ static int tw_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
>
>Â Â Â Â Âif (tw_initialize_device_extension(tw_dev)) {
>Â Â Â Â Â Â Â Â Âprintk(KERN_WARNING "3w-xxxx: Failed to initialize device extension.");
> +Â Â Â Â Â Â Â Âretval = -ENOMEM;
>Â Â Â Â Â Â Â Â Âgoto out_free_device_extension;
>Â Â Â Â Â}
>
> @@ -2294,6 +2295,7 @@ static int tw_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
>Â Â Â Â Âtw_dev->base_addr = pci_resource_start(pdev, 0);
>Â Â Â Â Âif (!tw_dev->base_addr) {
>Â Â Â Â Â Â Â Â Âprintk(KERN_WARNING "3w-xxxx: Failed to get io address.");
> +Â Â Â Â Â Â Â Âretval = -ENOMEM;
>Â Â Â Â Â Â Â Â Âgoto out_release_mem_region;
>Â Â Â Â Â}
>
> --
> 2.18.0
>

Anton,

3w-9xxx: twa_probe() initializes retval at the top of the function:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-9xxx.c#n2007

so does 3w-xxxx: tw_probe():

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-xxxx.c#n2253

so does 3w-sas: twl_probe():

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-sas.c#n1562

so I think your patch isn't needed...


-Adam