* [PATCH] scsi: mpt3sas: fix error returns in BRM_status_show
@ 2020-07-01 13:14 Johannes Thumshirn
2020-07-02 1:06 ` Damien Le Moal
2020-07-03 4:02 ` Martin K. Petersen
0 siblings, 2 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2020-07-01 13:14 UTC (permalink / raw)
To: Martin K . Petersen
Cc: Sathya Prakash, Sreekanth Reddy, Suganath Prabu Subramani,
linux-scsi, Johannes Thumshirn
BRM_status_show() has several error branches, but none of them record the
error in the error return.]
Also while at it remove the manual mutex_unlock() of the pci_access_mutex
in case of an ongoing pci error recovery or host removal and jump to the
cleanup lable instead.
Note: we can safely jump to out as from here as io_unit_pg3 is initialized
to NULL and if it hasn't been allocated kfree() skips the NULL pointer.
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index 62e552838565..70d2d0987249 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -3149,20 +3149,20 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr,
}
/* pci_access_mutex lock acquired by sysfs show path */
mutex_lock(&ioc->pci_access_mutex);
- if (ioc->pci_error_recovery || ioc->remove_host) {
- mutex_unlock(&ioc->pci_access_mutex);
- return 0;
- }
+ if (ioc->pci_error_recovery || ioc->remove_host)
+ goto out;
/* allocate upto GPIOVal 36 entries */
sz = offsetof(Mpi2IOUnitPage3_t, GPIOVal) + (sizeof(u16) * 36);
io_unit_pg3 = kzalloc(sz, GFP_KERNEL);
if (!io_unit_pg3) {
+ rc = -ENOMEM;
ioc_err(ioc, "%s: failed allocating memory for iounit_pg3: (%d) bytes\n",
__func__, sz);
goto out;
}
+ rc = -EINVAL;
if (mpt3sas_config_get_iounit_pg3(ioc, &mpi_reply, io_unit_pg3, sz) !=
0) {
ioc_err(ioc, "%s: failed reading iounit_pg3\n",
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: mpt3sas: fix error returns in BRM_status_show
2020-07-01 13:14 [PATCH] scsi: mpt3sas: fix error returns in BRM_status_show Johannes Thumshirn
@ 2020-07-02 1:06 ` Damien Le Moal
2020-07-02 7:44 ` Sreekanth Reddy
2020-07-03 4:02 ` Martin K. Petersen
1 sibling, 1 reply; 4+ messages in thread
From: Damien Le Moal @ 2020-07-02 1:06 UTC (permalink / raw)
To: Johannes Thumshirn, Martin K . Petersen
Cc: Sathya Prakash, Sreekanth Reddy, Suganath Prabu Subramani, linux-scsi
On 2020/07/01 22:15, Johannes Thumshirn wrote:
> BRM_status_show() has several error branches, but none of them record the
> error in the error return.]
>
> Also while at it remove the manual mutex_unlock() of the pci_access_mutex
> in case of an ongoing pci error recovery or host removal and jump to the
> cleanup lable instead.
>
> Note: we can safely jump to out as from here as io_unit_pg3 is initialized
> to NULL and if it hasn't been allocated kfree() skips the NULL pointer.
>
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
> drivers/scsi/mpt3sas/mpt3sas_ctl.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> index 62e552838565..70d2d0987249 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> @@ -3149,20 +3149,20 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr,
> }
> /* pci_access_mutex lock acquired by sysfs show path */
> mutex_lock(&ioc->pci_access_mutex);
> - if (ioc->pci_error_recovery || ioc->remove_host) {
> - mutex_unlock(&ioc->pci_access_mutex);
> - return 0;
> - }
> + if (ioc->pci_error_recovery || ioc->remove_host)
> + goto out;
>
> /* allocate upto GPIOVal 36 entries */
> sz = offsetof(Mpi2IOUnitPage3_t, GPIOVal) + (sizeof(u16) * 36);
> io_unit_pg3 = kzalloc(sz, GFP_KERNEL);
> if (!io_unit_pg3) {
> + rc = -ENOMEM;
> ioc_err(ioc, "%s: failed allocating memory for iounit_pg3: (%d) bytes\n",
> __func__, sz);
> goto out;
> }
>
> + rc = -EINVAL;
> if (mpt3sas_config_get_iounit_pg3(ioc, &mpi_reply, io_unit_pg3, sz) !=
> 0) {
> ioc_err(ioc, "%s: failed reading iounit_pg3\n",
>
Looks good.
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: mpt3sas: fix error returns in BRM_status_show
2020-07-02 1:06 ` Damien Le Moal
@ 2020-07-02 7:44 ` Sreekanth Reddy
0 siblings, 0 replies; 4+ messages in thread
From: Sreekanth Reddy @ 2020-07-02 7:44 UTC (permalink / raw)
To: Damien Le Moal
Cc: Johannes Thumshirn, Martin K . Petersen, Sathya Prakash,
Suganath Prabu Subramani, linux-scsi
On Thu, Jul 2, 2020 at 6:36 AM Damien Le Moal <Damien.LeMoal@wdc.com> wrote:
>
> On 2020/07/01 22:15, Johannes Thumshirn wrote:
> > BRM_status_show() has several error branches, but none of them record the
> > error in the error return.]
> >
> > Also while at it remove the manual mutex_unlock() of the pci_access_mutex
> > in case of an ongoing pci error recovery or host removal and jump to the
> > cleanup lable instead.
> >
> > Note: we can safely jump to out as from here as io_unit_pg3 is initialized
> > to NULL and if it hasn't been allocated kfree() skips the NULL pointer.
> >
> > Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> > ---
> > drivers/scsi/mpt3sas/mpt3sas_ctl.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> > index 62e552838565..70d2d0987249 100644
> > --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> > +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> > @@ -3149,20 +3149,20 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr,
> > }
> > /* pci_access_mutex lock acquired by sysfs show path */
> > mutex_lock(&ioc->pci_access_mutex);
> > - if (ioc->pci_error_recovery || ioc->remove_host) {
> > - mutex_unlock(&ioc->pci_access_mutex);
> > - return 0;
> > - }
> > + if (ioc->pci_error_recovery || ioc->remove_host)
> > + goto out;
> >
> > /* allocate upto GPIOVal 36 entries */
> > sz = offsetof(Mpi2IOUnitPage3_t, GPIOVal) + (sizeof(u16) * 36);
> > io_unit_pg3 = kzalloc(sz, GFP_KERNEL);
> > if (!io_unit_pg3) {
> > + rc = -ENOMEM;
> > ioc_err(ioc, "%s: failed allocating memory for iounit_pg3: (%d) bytes\n",
> > __func__, sz);
> > goto out;
> > }
> >
> > + rc = -EINVAL;
> > if (mpt3sas_config_get_iounit_pg3(ioc, &mpi_reply, io_unit_pg3, sz) !=
> > 0) {
> > ioc_err(ioc, "%s: failed reading iounit_pg3\n",
> >
>
> Looks good.
>
> Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
Patch looks good.
Acked-by: sreekanth reddy <sreekanth.reddy@broadcom.com>
Thanks,
Sreekanth
>
> --
> Damien Le Moal
> Western Digital Research
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: mpt3sas: fix error returns in BRM_status_show
2020-07-01 13:14 [PATCH] scsi: mpt3sas: fix error returns in BRM_status_show Johannes Thumshirn
2020-07-02 1:06 ` Damien Le Moal
@ 2020-07-03 4:02 ` Martin K. Petersen
1 sibling, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2020-07-03 4:02 UTC (permalink / raw)
To: Johannes Thumshirn
Cc: Martin K . Petersen, Sreekanth Reddy, linux-scsi, Sathya Prakash,
Suganath Prabu Subramani
On Wed, 1 Jul 2020 22:14:54 +0900, Johannes Thumshirn wrote:
> BRM_status_show() has several error branches, but none of them record the
> error in the error return.]
>
> Also while at it remove the manual mutex_unlock() of the pci_access_mutex
> in case of an ongoing pci error recovery or host removal and jump to the
> cleanup lable instead.
>
> [...]
Applied to 5.8/scsi-fixes, thanks!
[1/1] scsi: mpt3sas: Fix error returns in BRM_status_show
https://git.kernel.org/mkp/scsi/c/c7e4dd5d84fc
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-07-03 4:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-01 13:14 [PATCH] scsi: mpt3sas: fix error returns in BRM_status_show Johannes Thumshirn
2020-07-02 1:06 ` Damien Le Moal
2020-07-02 7:44 ` Sreekanth Reddy
2020-07-03 4:02 ` Martin K. Petersen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).