2022-07-23 06:52:05

by williamsukatube

[permalink] [raw]
Subject: [PATCH] scsi: lpfc: check the return value of alloc_workqueue()

From: William Dean <[email protected]>

The function alloc_workqueue() in lpfc_sli4_driver_resource_setup() can
fail, but there is no check of its return value. To fix this bug, its
return value should be checked with new error handling code.

Fixes: 3cee98db2610f ("scsi: lpfc: Fix crash on driver unload in wq free")
Reported-by: Hacash Robot <[email protected]>
Signed-off-by: William Dean <[email protected]>
---
drivers/scsi/lpfc/lpfc_init.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 750dd1e9f2cc..8e9594f4ed16 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -7958,6 +7958,8 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)

/* The lpfc_wq workqueue for deferred irq use */
phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
+ if (!phba->wq)
+ return -ENOMEM;

/*
* Initialize timers used by driver
--
2.25.1


2022-07-28 19:56:30

by James Smart

[permalink] [raw]
Subject: Re: [PATCH] scsi: lpfc: check the return value of alloc_workqueue()

On 7/22/2022 11:40 PM, [email protected] wrote:
> From: William Dean <[email protected]>
>
> The function alloc_workqueue() in lpfc_sli4_driver_resource_setup() can
> fail, but there is no check of its return value. To fix this bug, its
> return value should be checked with new error handling code.
>
> Fixes: 3cee98db2610f ("scsi: lpfc: Fix crash on driver unload in wq free")
> Reported-by: Hacash Robot <[email protected]>
> Signed-off-by: William Dean <[email protected]>
> ---
> drivers/scsi/lpfc/lpfc_init.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
> index 750dd1e9f2cc..8e9594f4ed16 100644
> --- a/drivers/scsi/lpfc/lpfc_init.c
> +++ b/drivers/scsi/lpfc/lpfc_init.c
> @@ -7958,6 +7958,8 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
>
> /* The lpfc_wq workqueue for deferred irq use */
> phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
> + if (!phba->wq)
> + return -ENOMEM;
>
> /*
> * Initialize timers used by driver

Reviewed-by: James Smart <[email protected]>

-- james