linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] wd719x: add check for dma mapping errors
@ 2017-01-27 22:30 Alexey Khoroshilov
  2017-01-27 22:53 ` James Bottomley
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Khoroshilov @ 2017-01-27 22:30 UTC (permalink / raw)
  To: Ondrej Zary, James E.J. Bottomley, Martin K. Petersen
  Cc: Alexey Khoroshilov, linux-scsi, linux-kernel, ldv-project

wd719x_queuecommand() doesn't check if mapping dma memory succeed.
The patch adds the check and failure handling.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 drivers/scsi/wd719x.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/scsi/wd719x.c b/drivers/scsi/wd719x.c
index 2a9da2e0ea6b..41ddbdcf02e0 100644
--- a/drivers/scsi/wd719x.c
+++ b/drivers/scsi/wd719x.c
@@ -244,6 +244,12 @@ static int wd719x_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *cmd)
 	scb->sense_buf_length = SCSI_SENSE_BUFFERSIZE;
 	cmd->SCp.dma_handle = dma_map_single(&wd->pdev->dev, cmd->sense_buffer,
 			SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
+	if (dma_mapping_error(&wd->pdev->dev, cmd->SCp.dma_handle)) {
+		dev_err(&wd->pdev->dev, "unable to map dma\n");
+		wd719x_finish_cmd(cmd, DID_ERROR);
+		spin_unlock_irqrestore(wd->sh->host_lock, flags);
+		return 0;
+	}
 	scb->sense_buf = cpu_to_le32(cmd->SCp.dma_handle);
 
 	/* request autosense */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] wd719x: add check for dma mapping errors
  2017-01-27 22:30 [PATCH] wd719x: add check for dma mapping errors Alexey Khoroshilov
@ 2017-01-27 22:53 ` James Bottomley
  0 siblings, 0 replies; 2+ messages in thread
From: James Bottomley @ 2017-01-27 22:53 UTC (permalink / raw)
  To: Alexey Khoroshilov, Ondrej Zary, Martin K. Petersen
  Cc: linux-scsi, linux-kernel, ldv-project

On Sat, 2017-01-28 at 01:30 +0300, Alexey Khoroshilov wrote:
> wd719x_queuecommand() doesn't check if mapping dma memory succeed.
> The patch adds the check and failure handling.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> ---
>  drivers/scsi/wd719x.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/scsi/wd719x.c b/drivers/scsi/wd719x.c
> index 2a9da2e0ea6b..41ddbdcf02e0 100644
> --- a/drivers/scsi/wd719x.c
> +++ b/drivers/scsi/wd719x.c
> @@ -244,6 +244,12 @@ static int wd719x_queuecommand(struct Scsi_Host
> *sh, struct scsi_cmnd *cmd)
>  	scb->sense_buf_length = SCSI_SENSE_BUFFERSIZE;
>  	cmd->SCp.dma_handle = dma_map_single(&wd->pdev->dev, cmd
> ->sense_buffer,
>  			SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
> +	if (dma_mapping_error(&wd->pdev->dev, cmd->SCp.dma_handle))
> {
> +		dev_err(&wd->pdev->dev, "unable to map dma\n");
> +		wd719x_finish_cmd(cmd, DID_ERROR);
> +		spin_unlock_irqrestore(wd->sh->host_lock, flags);
> +		return 0;
> +	}

I'm not at all convinced of the wisdom of doing this for an ancient
driver: this thing is presumably x86 and ancient in which case it will
never fail anyway.

However, for the future, a mapping error is transient, meaning we want
the command retried, not errored, so from queuecommand you return
 SCSI_MLQUEUE_HOST_BUSY to induce a pause and retry.

James

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-01-27 22:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-27 22:30 [PATCH] wd719x: add check for dma mapping errors Alexey Khoroshilov
2017-01-27 22:53 ` James Bottomley

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).