[PATCH] drivers: scsi: 3w-xxxx: Add error handling for initialization failure in `tw_probe`

74 views
Skip to first unread message

Yuchen Yang

unread,
May 4, 2023, 4:21:28 AM5/4/23
to dz...@hust.edu.cn, hust-os-ker...@googlegroups.com, Yuchen Yang
Smatch complains that:
tw_probe() warn: missing error code 'retval'

This patch adds error checking to `tw_probe` function to handle
initialization failure. If `tw_reset_sequence` function returns a
non-zero value, the function will return an `-EINVAL` error code
to indicate the initialization failure.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Yuchen Yang <u2021...@hust.edu.cn>
---
The issue is found by static analyzer. The patched code has passed
Smatch checker, but remains untested on real device.
---
drivers/scsi/3w-xxxx.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index 36c34ced0cc1..641b8a2bbbd5 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -2305,8 +2305,10 @@ static int tw_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
TW_DISABLE_INTERRUPTS(tw_dev);

/* Initialize the card */
- if (tw_reset_sequence(tw_dev))
+ if (tw_reset_sequence(tw_dev)){
+ retval = -EINVAL;
goto out_release_mem_region;
+ }

/* Set host specific parameters */
host->max_id = TW_MAX_UNITS;
--
2.25.1

Dan Carpenter

unread,
May 4, 2023, 5:27:34 AM5/4/23
to Yuchen Yang, dz...@hust.edu.cn, hust-os-ker...@googlegroups.com
On Thu, May 04, 2023 at 04:20:51PM +0800, Yuchen Yang wrote:
> diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
> index 36c34ced0cc1..641b8a2bbbd5 100644
> --- a/drivers/scsi/3w-xxxx.c
> +++ b/drivers/scsi/3w-xxxx.c
> @@ -2305,8 +2305,10 @@ static int tw_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
> TW_DISABLE_INTERRUPTS(tw_dev);
>
> /* Initialize the card */
> - if (tw_reset_sequence(tw_dev))
> + if (tw_reset_sequence(tw_dev)){

scripts/checkpatch.pl complains.

ERROR: space required before the open brace '{'
#39: FILE: drivers/scsi/3w-xxxx.c:2308:
+ if (tw_reset_sequence(tw_dev)){

Hopefully, the bot will complain as well.

regards,
dan carpenter

Yuchen Yang

unread,
May 4, 2023, 8:03:45 AM5/4/23
to dz...@hust.edu.cn, hust-os-ker...@googlegroups.com, Yuchen Yang
Smatch complains that:
tw_probe() warn: missing error code 'retval'

This patch adds error checking to `tw_probe` function to handle
initialization failure. If `tw_reset_sequence` function returns a
non-zero value, the function will return an `-EINVAL` error code
to indicate the initialization failure.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Yuchen Yang <u2021...@hust.edu.cn>
---
v1 -> v2: Add a new space before the open brace '{'.
The issue is found by static analyzer. The patched code has passed
Smatch checker, but remains untested on real device.
---
drivers/scsi/3w-xxxx.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index 36c34ced0cc1..641b8a2bbbd5 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -2305,8 +2305,10 @@ static int tw_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
TW_DISABLE_INTERRUPTS(tw_dev);

/* Initialize the card */
- if (tw_reset_sequence(tw_dev))
+ if (tw_reset_sequence(tw_dev)) {

Dan Carpenter

unread,
May 4, 2023, 10:43:44 AM5/4/23
to Yuchen Yang, dz...@hust.edu.cn, hust-os-ker...@googlegroups.com
On Thu, May 04, 2023 at 08:03:15PM +0800, Yuchen Yang wrote:
> Smatch complains that:
> tw_probe() warn: missing error code 'retval'
>
> This patch adds error checking to `tw_probe` function to handle
> initialization failure. If `tw_reset_sequence` function returns a
> non-zero value, the function will return an `-EINVAL` error code
> to indicate the initialization failure.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Yuchen Yang <u2021...@hust.edu.cn>
> ---

Looks okay.

Reviewed-by: Dan Carpenter <dan.ca...@linaro.org>

regards,
dan carpenter

Yuchen Yang

unread,
May 5, 2023, 10:14:09 AM5/5/23
to Adam Radford, James E.J. Bottomley, Martin K. Petersen, hust-os-ker...@googlegroups.com, Yuchen Yang, Dan Carpenter, linux...@vger.kernel.org, linux-...@vger.kernel.org
Smatch complains that:
tw_probe() warn: missing error code 'retval'

This patch adds error checking to `tw_probe` function to handle
initialization failure. If `tw_reset_sequence` function returns a
non-zero value, the function will return an `-EINVAL` error code
to indicate the initialization failure.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Yuchen Yang <u2021...@hust.edu.cn>
Reviewed-by: Dan Carpenter <dan.ca...@linaro.org>
---

Martin K. Petersen

unread,
May 22, 2023, 5:41:01 PM5/22/23
to Yuchen Yang, Adam Radford, James E.J. Bottomley, Martin K. Petersen, hust-os-ker...@googlegroups.com, Dan Carpenter, linux...@vger.kernel.org, linux-...@vger.kernel.org

Yuchen,

> Smatch complains that:
> tw_probe() warn: missing error code 'retval'
>
> This patch adds error checking to `tw_probe` function to handle
> initialization failure. If `tw_reset_sequence` function returns a
> non-zero value, the function will return an `-EINVAL` error code
> to indicate the initialization failure.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Yuchen Yang <u2021...@hust.edu.cn>
> Reviewed-by: Dan Carpenter <dan.ca...@linaro.org>

Applied to 6.5/scsi-staging, thanks!

--
Martin K. Petersen Oracle Linux Engineering

Martin K. Petersen

unread,
May 31, 2023, 8:43:37 PM5/31/23
to Adam Radford, James E.J. Bottomley, Yuchen Yang, Martin K . Petersen, hust-os-ker...@googlegroups.com, Dan Carpenter, linux...@vger.kernel.org, linux-...@vger.kernel.org
On Fri, 05 May 2023 22:12:55 +0800, Yuchen Yang wrote:

> Smatch complains that:
> tw_probe() warn: missing error code 'retval'
>
> This patch adds error checking to `tw_probe` function to handle
> initialization failure. If `tw_reset_sequence` function returns a
> non-zero value, the function will return an `-EINVAL` error code
> to indicate the initialization failure.
>
> [...]

Applied to 6.5/scsi-queue, thanks!

[1/1] drivers: scsi: 3w-xxxx: Add error handling for initialization failure in `tw_probe`
https://git.kernel.org/mkp/scsi/c/2e2fe5ac695a
Reply all
Reply to author
Forward
0 new messages