2023-04-06 08:00:12

by Harshit Mogalapalli

[permalink] [raw]
Subject: [PATCH next] scsi: scsi_debug: Fix missing error code in scsi_debug_init()

Smatch reports: drivers/scsi/scsi_debug.c:6996
scsi_debug_init() warn: missing error code 'ret'

Although it is unlikely that KMEM_CACHE might fail, but if
it does then ret might be zero. So to fix this explicitly
mark ret as "-ENOMEM" and then goto driver_unreg.

Fixes: 1107c7b24ee3 ("scsi: scsi_debug: Dynamically allocate sdebug_queued_cmd")
Signed-off-by: Harshit Mogalapalli <[email protected]>
---
This is from static analysis, Only compile tested.
---
drivers/scsi/scsi_debug.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index cf3f58e8f733..f4fa1035a191 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -6992,8 +6992,10 @@ static int __init scsi_debug_init(void)
sdebug_add_host = 0;

queued_cmd_cache = KMEM_CACHE(sdebug_queued_cmd, SLAB_HWCACHE_ALIGN);
- if (!queued_cmd_cache)
+ if (!queued_cmd_cache) {
+ ret = -ENOMEM;
goto driver_unreg;
+ }

for (k = 0; k < hosts_to_add; k++) {
if (want_store && k == 0) {
--
2.38.1


2023-04-06 09:35:42

by John Garry

[permalink] [raw]
Subject: Re: [PATCH next] scsi: scsi_debug: Fix missing error code in scsi_debug_init()

On 06/04/2023 08:46, Harshit Mogalapalli wrote:
> Smatch reports: drivers/scsi/scsi_debug.c:6996
> scsi_debug_init() warn: missing error code 'ret'
>
> Although it is unlikely that KMEM_CACHE might fail, but if
> it does then ret might be zero. So to fix this explicitly
> mark ret as "-ENOMEM" and then goto driver_unreg.
>
> Fixes: 1107c7b24ee3 ("scsi: scsi_debug: Dynamically allocate sdebug_queued_cmd")
> Signed-off-by: Harshit Mogalapalli<[email protected]>
> ---

thanks
Reviewed-by: John Garry <[email protected]>

2023-04-12 01:16:46

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH next] scsi: scsi_debug: Fix missing error code in scsi_debug_init()


Harshit,

> Smatch reports: drivers/scsi/scsi_debug.c:6996
> scsi_debug_init() warn: missing error code 'ret'

Applied to 6.4/scsi-staging, thanks!

--
Martin K. Petersen Oracle Linux Engineering

2023-04-19 03:25:05

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH next] scsi: scsi_debug: Fix missing error code in scsi_debug_init()

On Thu, 06 Apr 2023 00:46:07 -0700, Harshit Mogalapalli wrote:

> Smatch reports: drivers/scsi/scsi_debug.c:6996
> scsi_debug_init() warn: missing error code 'ret'
>
> Although it is unlikely that KMEM_CACHE might fail, but if
> it does then ret might be zero. So to fix this explicitly
> mark ret as "-ENOMEM" and then goto driver_unreg.
>
> [...]

Applied to 6.4/scsi-queue, thanks!

[1/1] scsi: scsi_debug: Fix missing error code in scsi_debug_init()
https://git.kernel.org/mkp/scsi/c/b32283d75335

--
Martin K. Petersen Oracle Linux Engineering