On Thu, 11 Oct 2018, Christoph Hellwig wrote:
> diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
> index 90604bff8dd2..73fcbd65b9fe 100644
> --- a/drivers/scsi/esp_scsi.c
> +++ b/drivers/scsi/esp_scsi.c
> @@ -369,19 +369,25 @@ static void esp_map_dma(struct esp *esp, struct
> scsi_cmnd *cmd)
> {
> struct esp_cmd_priv *spriv = ESP_CMD_PRIV(cmd);
> struct scatterlist *sg = scsi_sglist(cmd);
> - int dir = cmd->sc_data_direction;
> - int total, i;
> + int total = 0, i;
>
> - if (dir == DMA_NONE)
> - return;
> -
Removing this DMA_NONE test caused an oops in my test. sg becomes a NULL
pointer.
> - spriv->u.num_sg = esp->ops->map_sg(esp, sg, scsi_sg_count(cmd), dir);
Does anyone happen to know whether the union 'u' serves any purpose?
--
> + if (esp->flags & ESP_FLAG_NO_DMA_MAP) {
> + /*
> + * For pseudo DMA and PIO we need the virtual address instead of
> + * a dma address, so perform an identity mapping.
> + */
> + spriv->u.num_sg = scsi_sg_count(cmd);
> + for (i = 0; i < spriv->u.num_sg; i++) {
> + sg[i].dma_address = (uintptr_t)sg_virt(&sg[i]);
> + total += sg_dma_len(&sg[i]);
> + }
> + } else {
> + spriv->u.num_sg = scsi_dma_map(cmd);
> + for (i = 0; i < spriv->u.num_sg; i++)
> + total += sg_dma_len(&sg[i]);
> + }
> spriv->cur_residue = sg_dma_len(sg);
> spriv->cur_sg = sg;
> -
> - total = 0;
> - for (i = 0; i < spriv->u.num_sg; i++)
> - total += sg_dma_len(&sg[i]);
> spriv->tot_residue = total;
> }
>