diff mbox series

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

Message ID 20190610150317.29546-4-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 sg helper to
operate sgl.

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

Comments

Ewan Milne June 10, 2019, 4:56 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 sg helper to
> operate sgl.
> 
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
>  drivers/scsi/ipr.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
> index d06bc1a817a1..028db6bd0280 100644
> --- a/drivers/scsi/ipr.c
> +++ b/drivers/scsi/ipr.c
> @@ -3952,6 +3952,7 @@ static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
>  	struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
>  	struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
>  	struct scatterlist *scatterlist = sglist->scatterlist;
> +	struct scatterlist *sg;
>  	int i;
>  
>  	ipr_cmd->dma_use_sg = sglist->num_dma_sg;
> @@ -3960,10 +3961,10 @@ static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
>  
>  	ioarcb->ioadl_len =
>  		cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
> -	for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
> +	for_each_sg(scatterlist, sg, ipr_cmd->dma_use_sg, i) {
>  		ioadl64[i].flags = cpu_to_be32(IPR_IOADL_FLAGS_WRITE);
> -		ioadl64[i].data_len = cpu_to_be32(sg_dma_len(&scatterlist[i]));
> -		ioadl64[i].address = cpu_to_be64(sg_dma_address(&scatterlist[i]));
> +		ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
> +		ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
>  	}
>  
>  	ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);

Reviewed-by: Ewan D. Milne <emilne@redhat.com>
James Bottomley June 10, 2019, 6:38 p.m. UTC | #2
On Mon, 2019-06-10 at 23:03 +0800, Ming Lei wrote:
> The current way isn't safe for chained sgl, so use sg helper to
> operate sgl.

ipr doesn't use chaining, so it can likewise assume a contiguous
scatterlist.  Since the hardware seems to have a 64 entry limit, it
looks like it never will use chaining.

James
diff mbox series

Patch

diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index d06bc1a817a1..028db6bd0280 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -3952,6 +3952,7 @@  static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
 	struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
 	struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
 	struct scatterlist *scatterlist = sglist->scatterlist;
+	struct scatterlist *sg;
 	int i;
 
 	ipr_cmd->dma_use_sg = sglist->num_dma_sg;
@@ -3960,10 +3961,10 @@  static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
 
 	ioarcb->ioadl_len =
 		cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
-	for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
+	for_each_sg(scatterlist, sg, ipr_cmd->dma_use_sg, i) {
 		ioadl64[i].flags = cpu_to_be32(IPR_IOADL_FLAGS_WRITE);
-		ioadl64[i].data_len = cpu_to_be32(sg_dma_len(&scatterlist[i]));
-		ioadl64[i].address = cpu_to_be64(sg_dma_address(&scatterlist[i]));
+		ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
+		ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
 	}
 
 	ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);