diff mbox series

[5/5] scsi: mvumi: use sg helper to operate sgl

Message ID 20190610150317.29546-6-ming.lei@redhat.com (mailing list archive)
State Superseded
Headers show
Series scsi: use sg helper to operate sgl | expand

Commit Message

Ming Lei June 10, 2019, 3:03 p.m. UTC
The current way isn't safe for chained sgl, so use sgl helper to
operate sgl.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/scsi/mvumi.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Ewan Milne June 10, 2019, 4:59 p.m. UTC | #1
On Mon, 2019-06-10 at 23:03 +0800, Ming Lei wrote:
> The current way isn't safe for chained sgl, so use sgl helper to
> operate sgl.
> 
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
>  drivers/scsi/mvumi.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
> index 1fb6f6ca627e..3881aa6bf4c4 100644
> --- a/drivers/scsi/mvumi.c
> +++ b/drivers/scsi/mvumi.c
> @@ -195,8 +195,7 @@ static int mvumi_make_sgl(struct mvumi_hba *mhba, struct scsi_cmnd *scmd,
>  	unsigned int sgnum = scsi_sg_count(scmd);
>  	dma_addr_t busaddr;
>  
> -	sg = scsi_sglist(scmd);
> -	*sg_count = dma_map_sg(&mhba->pdev->dev, sg, sgnum,
> +	*sg_count = dma_map_sg(&mhba->pdev->dev, scsi_sglist(scmd), sgnum,
>  			       scmd->sc_data_direction);
>  	if (*sg_count > mhba->max_sge) {
>  		dev_err(&mhba->pdev->dev,
> @@ -206,12 +205,12 @@ static int mvumi_make_sgl(struct mvumi_hba *mhba, struct scsi_cmnd *scmd,
>  			     scmd->sc_data_direction);
>  		return -1;
>  	}
> -	for (i = 0; i < *sg_count; i++) {
> -		busaddr = sg_dma_address(&sg[i]);
> +	scsi_for_each_sg(scmd, sg, *sg_count, i) {
> +		busaddr = sg_dma_address(sg);
>  		m_sg->baseaddr_l = cpu_to_le32(lower_32_bits(busaddr));
>  		m_sg->baseaddr_h = cpu_to_le32(upper_32_bits(busaddr));
>  		m_sg->flags = 0;
> -		sgd_setsz(mhba, m_sg, cpu_to_le32(sg_dma_len(&sg[i])));
> +		sgd_setsz(mhba, m_sg, cpu_to_le32(sg_dma_len(sg)));
>  		if ((i + 1) == *sg_count)
>  			m_sg->flags |= 1U << mhba->eot_flag;
>  

Reviewed-by: Ewan D. Milne <emilne@redhat.com>
diff mbox series

Patch

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 1fb6f6ca627e..3881aa6bf4c4 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -195,8 +195,7 @@  static int mvumi_make_sgl(struct mvumi_hba *mhba, struct scsi_cmnd *scmd,
 	unsigned int sgnum = scsi_sg_count(scmd);
 	dma_addr_t busaddr;
 
-	sg = scsi_sglist(scmd);
-	*sg_count = dma_map_sg(&mhba->pdev->dev, sg, sgnum,
+	*sg_count = dma_map_sg(&mhba->pdev->dev, scsi_sglist(scmd), sgnum,
 			       scmd->sc_data_direction);
 	if (*sg_count > mhba->max_sge) {
 		dev_err(&mhba->pdev->dev,
@@ -206,12 +205,12 @@  static int mvumi_make_sgl(struct mvumi_hba *mhba, struct scsi_cmnd *scmd,
 			     scmd->sc_data_direction);
 		return -1;
 	}
-	for (i = 0; i < *sg_count; i++) {
-		busaddr = sg_dma_address(&sg[i]);
+	scsi_for_each_sg(scmd, sg, *sg_count, i) {
+		busaddr = sg_dma_address(sg);
 		m_sg->baseaddr_l = cpu_to_le32(lower_32_bits(busaddr));
 		m_sg->baseaddr_h = cpu_to_le32(upper_32_bits(busaddr));
 		m_sg->flags = 0;
-		sgd_setsz(mhba, m_sg, cpu_to_le32(sg_dma_len(&sg[i])));
+		sgd_setsz(mhba, m_sg, cpu_to_le32(sg_dma_len(sg)));
 		if ((i + 1) == *sg_count)
 			m_sg->flags |= 1U << mhba->eot_flag;