* [PATCH] scsi: myrs: check return value of dma_alloc_coherent() instead of using dma_mapping_error()
@ 2022-11-16 9:41 Peter Kosyh
2023-04-20 19:02 ` Alexey Khoroshilov
0 siblings, 1 reply; 2+ messages in thread
From: Peter Kosyh @ 2022-11-16 9:41 UTC (permalink / raw)
To: Hannes Reinecke
Cc: Peter Kosyh, James E.J. Bottomley, Martin K. Petersen,
linux-scsi, linux-kernel, lvc-project
dma_alloc_coherent() may leave third parameter uninitialized. So
it is not safe to use dma_mapping_error() without checking return
value of dma_alloc_coherent().
Check the return value of dma_alloc_coherent() to detect
an error.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by: Peter Kosyh <pkosyh@yandex.ru>
---
drivers/scsi/myrs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/myrs.c b/drivers/scsi/myrs.c
index 7eb8c39da366..1811c1a6385b 100644
--- a/drivers/scsi/myrs.c
+++ b/drivers/scsi/myrs.c
@@ -498,14 +498,14 @@ static bool myrs_enable_mmio_mbox(struct myrs_hba *cs,
/* Temporary dma mapping, used only in the scope of this function */
mbox = dma_alloc_coherent(&pdev->dev, sizeof(union myrs_cmd_mbox),
&mbox_addr, GFP_KERNEL);
- if (dma_mapping_error(&pdev->dev, mbox_addr))
+ if (!mbox)
return false;
/* These are the base addresses for the command memory mailbox array */
cs->cmd_mbox_size = MYRS_MAX_CMD_MBOX * sizeof(union myrs_cmd_mbox);
cmd_mbox = dma_alloc_coherent(&pdev->dev, cs->cmd_mbox_size,
&cs->cmd_mbox_addr, GFP_KERNEL);
- if (dma_mapping_error(&pdev->dev, cs->cmd_mbox_addr)) {
+ if (!cmd_mbox) {
dev_err(&pdev->dev, "Failed to map command mailbox\n");
goto out_free;
}
--
2.38.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] scsi: myrs: check return value of dma_alloc_coherent() instead of using dma_mapping_error()
2022-11-16 9:41 [PATCH] scsi: myrs: check return value of dma_alloc_coherent() instead of using dma_mapping_error() Peter Kosyh
@ 2023-04-20 19:02 ` Alexey Khoroshilov
0 siblings, 0 replies; 2+ messages in thread
From: Alexey Khoroshilov @ 2023-04-20 19:02 UTC (permalink / raw)
To: Peter Kosyh, Hannes Reinecke
Cc: lvc-project, Martin K. Petersen, James E.J. Bottomley,
linux-kernel, linux-scsi
On 16.11.2022 12:41, Peter Kosyh wrote:
> dma_alloc_coherent() may leave third parameter uninitialized. So
> it is not safe to use dma_mapping_error() without checking return
> value of dma_alloc_coherent().
>
> Check the return value of dma_alloc_coherent() to detect
> an error.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Signed-off-by: Peter Kosyh <pkosyh@yandex.ru>
> ---
> drivers/scsi/myrs.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/myrs.c b/drivers/scsi/myrs.c
> index 7eb8c39da366..1811c1a6385b 100644
> --- a/drivers/scsi/myrs.c
> +++ b/drivers/scsi/myrs.c
> @@ -498,14 +498,14 @@ static bool myrs_enable_mmio_mbox(struct myrs_hba *cs,
> /* Temporary dma mapping, used only in the scope of this function */
> mbox = dma_alloc_coherent(&pdev->dev, sizeof(union myrs_cmd_mbox),
> &mbox_addr, GFP_KERNEL);
> - if (dma_mapping_error(&pdev->dev, mbox_addr))
> + if (!mbox)
> return false;
>
> /* These are the base addresses for the command memory mailbox array */
> cs->cmd_mbox_size = MYRS_MAX_CMD_MBOX * sizeof(union myrs_cmd_mbox);
> cmd_mbox = dma_alloc_coherent(&pdev->dev, cs->cmd_mbox_size,
> &cs->cmd_mbox_addr, GFP_KERNEL);
> - if (dma_mapping_error(&pdev->dev, cs->cmd_mbox_addr)) {
> + if (!cmd_mbox) {
> dev_err(&pdev->dev, "Failed to map command mailbox\n");
> goto out_free;
> }
>
Reviewed-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Also you may want to add
Fixes: 77266186397c ("scsi: myrs: Add Mylex RAID controller (SCSI
interface)")
--
Alexey
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-04-20 19:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-16 9:41 [PATCH] scsi: myrs: check return value of dma_alloc_coherent() instead of using dma_mapping_error() Peter Kosyh
2023-04-20 19:02 ` Alexey Khoroshilov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®