diff mbox series

scsi: 3ware: fix return 0 on the error path of probe

Message ID 20180727135157.13051-1-vasilyev@ispras.ru (mailing list archive)
State Accepted
Headers show
Series scsi: 3ware: fix return 0 on the error path of probe | expand

Commit Message

Anton Vasilyev July 27, 2018, 1:51 p.m. UTC
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@ispras.ru>
---
 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(-)

Comments

adam radford July 27, 2018, 6:42 p.m. UTC | #1
On Fri, Jul 27, 2018 at 6:52 AM Anton Vasilyev <vasilyev@ispras.ru> 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@ispras.ru>
> ---
>  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
Anton Vasilyev July 28, 2018, 3:18 p.m. UTC | #2
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@gmail.com>
написал:

On Fri, Jul 27, 2018 at 6:52 AM Anton Vasilyev <vasilyev@ispras.ru> 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@ispras.ru>
> ---
>  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
<div dir="auto"><div>Adam,</div><div dir="auto"><br></div><div dir="auto"><span style="font-family:sans-serif">3w-9xxx: twa_probe():</span></div><div dir="auto"><font face="sans-serif"><br></font>There is check of retval:</div><div dir="auto"><a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-9xxx.c#n2010" target="_blank" rel="noreferrer">https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-9xxx.c#n2010</a></div><div dir="auto"><br></div><div dir="auto">retval without assignement is 0 on fail of <span style="font-family:sans-serif">twa_initialize_device_</span><span style="font-family:sans-serif">extension():</span></div><div dir="auto"><span style="font-family:sans-serif"><a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-9xxx.c#n2040">https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-9xxx.c#n2040</a></span><br></div><div dir="auto"><font face="sans-serif"><br></font></div><div dir="auto"><font face="sans-serif">And this 0 is returned from probe on the error path.</font></div><div dir="auto"><font face="sans-serif"><br></font></div><div dir="auto"><font face="sans-serif">Same pattern is true for all other cases from patch.</font></div><div dir="auto"><font face="sans-serif"><br></font></div><div dir="auto"><font face="sans-serif">-Anton<br></font><div class="gmail_extra" dir="auto"><br><div class="gmail_quote">27 июл. 2018 г. 9:42 ПП пользователь &quot;adam radford&quot; &lt;<a href="mailto:aradford@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">aradford@gmail.com</a>&gt; написал:<br type="attribution"><blockquote class="m_-8378120472432222872m_7650373726616114635m_-7730006977630316119m_-622452158064295311m_-1586320276793739959quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_-8378120472432222872m_7650373726616114635m_-7730006977630316119m_-622452158064295311m_-1586320276793739959elided-text">On Fri, Jul 27, 2018 at 6:52 AM Anton Vasilyev &lt;<a href="mailto:vasilyev@ispras.ru" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">vasilyev@ispras.ru</a>&gt; wrote:<br>
&gt;<br>
&gt; tw_probe() returns 0 in case of fail of tw_initialize_device_extension(),<br>
&gt; pci_resource_start() or tw_reset_sequence() and releases resources.<br>
&gt; twl_probe() returns 0 in case of fail of twl_initialize_device_extension(),<br>
&gt; pci_iomap() and twl_reset_sequence().<br>
&gt; twa_probe() returns 0 in case of fail of tw_initialize_device_extension(),<br>
&gt; ioremap() and twa_reset_sequence().<br>
&gt;<br>
&gt;<br>
&gt; The patch adds retval initialization for these cases.<br>
&gt;<br>
&gt; Found by Linux Driver Verification project (<a href="http://linuxtesting.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">linuxtesting.org</a>).<br>
&gt;<br>
&gt; Signed-off-by: Anton Vasilyev &lt;<a href="mailto:vasilyev@ispras.ru" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">vasilyev@ispras.ru</a>&gt;<br>
&gt; ---<br>
&gt;  drivers/scsi/3w-9xxx.c | 6 +++++-<br>
&gt;  drivers/scsi/3w-sas.c  | 3 +++<br>
&gt;  drivers/scsi/3w-xxxx.c | 2 ++<br>
&gt;  3 files changed, 10 insertions(+), 1 deletion(-)<br>
&gt;<br>
&gt; diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c<br>
&gt; index 99ba4a770406..27521fc3ef5a 100644<br>
&gt; --- a/drivers/scsi/3w-9xxx.c<br>
&gt; +++ b/drivers/scsi/3w-9xxx.c<br>
&gt; @@ -2038,6 +2038,7 @@ static int twa_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)<br>
&gt;<br>
&gt;         if (twa_initialize_device_extension(tw_dev)) {<br>
&gt;                 TW_PRINTK(tw_dev-&gt;host, TW_DRIVER, 0x25, &quot;Failed to initialize device extension&quot;);<br>
&gt; +               retval = -ENOMEM;<br>
&gt;                 goto out_free_device_extension;<br>
&gt;         }<br>
&gt;<br>
&gt; @@ -2060,6 +2061,7 @@ static int twa_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)<br>
&gt;         tw_dev-&gt;base_addr = ioremap(mem_addr, mem_len);<br>
&gt;         if (!tw_dev-&gt;base_addr) {<br>
&gt;                 TW_PRINTK(tw_dev-&gt;host, TW_DRIVER, 0x35, &quot;Failed to ioremap&quot;);<br>
&gt; +               retval = -ENOMEM;<br>
&gt;                 goto out_release_mem_region;<br>
&gt;         }<br>
&gt;<br>
&gt; @@ -2067,8 +2069,10 @@ static int twa_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)<br>
&gt;         TW_DISABLE_INTERRUPTS(tw_dev);<br>
&gt;<br>
&gt;         /* Initialize the card */<br>
&gt; -       if (twa_reset_sequence(tw_dev, 0))<br>
&gt; +       if (twa_reset_sequence(tw_dev, 0)) {<br>
&gt; +               retval = -ENOMEM;<br>
&gt;                 goto out_iounmap;<br>
&gt; +       }<br>
&gt;<br>
&gt;         /* Set host specific parameters */<br>
&gt;         if ((pdev-&gt;device == PCI_DEVICE_ID_3WARE_9650SE) ||<br>
&gt; diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c<br>
&gt; index cf9f2a09b47d..40c1e6e64f58 100644<br>
&gt; --- a/drivers/scsi/3w-sas.c<br>
&gt; +++ b/drivers/scsi/3w-sas.c<br>
&gt; @@ -1594,6 +1594,7 @@ static int twl_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)<br>
&gt;<br>
&gt;         if (twl_initialize_device_extension(tw_dev)) {<br>
&gt;                 TW_PRINTK(tw_dev-&gt;host, TW_DRIVER, 0x1a, &quot;Failed to initialize device extension&quot;);<br>
&gt; +               retval = -ENOMEM;<br>
&gt;                 goto out_free_device_extension;<br>
&gt;         }<br>
&gt;<br>
&gt; @@ -1608,6 +1609,7 @@ static int twl_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)<br>
&gt;         tw_dev-&gt;base_addr = pci_iomap(pdev, 1, 0);<br>
&gt;         if (!tw_dev-&gt;base_addr) {<br>
&gt;                 TW_PRINTK(tw_dev-&gt;host, TW_DRIVER, 0x1c, &quot;Failed to ioremap&quot;);<br>
&gt; +               retval = -ENOMEM;<br>
&gt;                 goto out_release_mem_region;<br>
&gt;         }<br>
&gt;<br>
&gt; @@ -1617,6 +1619,7 @@ static int twl_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)<br>
&gt;         /* Initialize the card */<br>
&gt;         if (twl_reset_sequence(tw_dev, 0)) {<br>
&gt;                 TW_PRINTK(tw_dev-&gt;host, TW_DRIVER, 0x1d, &quot;Controller reset failed during probe&quot;);<br>
&gt; +               retval = -ENOMEM;<br>
&gt;                 goto out_iounmap;<br>
&gt;         }<br>
&gt;<br>
&gt; diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c<br>
&gt; index f6179e3d6953..961ea6f7def8 100644<br>
&gt; --- a/drivers/scsi/3w-xxxx.c<br>
&gt; +++ b/drivers/scsi/3w-xxxx.c<br>
&gt; @@ -2280,6 +2280,7 @@ static int tw_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)<br>
&gt;<br>
&gt;         if (tw_initialize_device_extension(tw_dev)) {<br>
&gt;                 printk(KERN_WARNING &quot;3w-xxxx: Failed to initialize device extension.&quot;);<br>
&gt; +               retval = -ENOMEM;<br>
&gt;                 goto out_free_device_extension;<br>
&gt;         }<br>
&gt;<br>
&gt; @@ -2294,6 +2295,7 @@ static int tw_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)<br>
&gt;         tw_dev-&gt;base_addr = pci_resource_start(pdev, 0);<br>
&gt;         if (!tw_dev-&gt;base_addr) {<br>
&gt;                 printk(KERN_WARNING &quot;3w-xxxx: Failed to get io address.&quot;);<br>
&gt; +               retval = -ENOMEM;<br>
&gt;                 goto out_release_mem_region;<br>
&gt;         }<br>
&gt;<br>
&gt; --<br>
&gt; 2.18.0<br>
&gt;<br>
<br></div>
Anton,<br>
<br>
3w-9xxx: twa_probe() initializes retval at the top of the function:<br>
<br>
<a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-9xxx.c#n2007" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-9xxx.c#n2007</a><br>
<br>
so does 3w-xxxx: tw_probe():<br>
<br>
<a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-xxxx.c#n2253" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-xxxx.c#n2253</a><br>
<br>
so does 3w-sas: twl_probe():<br>
<br>
<a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-sas.c#n1562" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/3w-sas.c#n1562</a><br>
<br>
so I think your patch isn&#39;t needed...<div class="m_-8378120472432222872m_7650373726616114635m_-7730006977630316119m_-622452158064295311m_-1586320276793739959signature-text"><br>
<br>
-Adam<br>
</div></blockquote></div><br></div><div class="gmail_extra" dir="auto"><br></div></div></div>
adam radford July 30, 2018, 6:31 p.m. UTC | #3
On Sat, Jul 28, 2018 at 8:18 AM Anton Vasilyev
<anton.vasilyev.87@gmail.com> wrote:
>
> 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@gmail.com> написал:
>
> On Fri, Jul 27, 2018 at 6:52 AM Anton Vasilyev <vasilyev@ispras.ru> 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@ispras.ru>
> > ---
> >  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
>
>
>

Acked-by: Adam Radford <aradford@gmail.com>
Martin K. Petersen July 31, 2018, 2:08 a.m. UTC | #4
Anton,

> 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().

Applied to 4.19/scsi-queue, thanks!
diff mbox series

Patch

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;
 	}