diff mbox series

[1/5] scsi: vmw_pscsi: use sgl helper to operate sgl

Message ID 20190610150317.29546-2-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/vmw_pvscsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ewan Milne June 10, 2019, 4:54 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/vmw_pvscsi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
> index ecee4b3ff073..d71abd416eb4 100644
> --- a/drivers/scsi/vmw_pvscsi.c
> +++ b/drivers/scsi/vmw_pvscsi.c
> @@ -335,7 +335,7 @@ static void pvscsi_create_sg(struct pvscsi_ctx *ctx,
>  	BUG_ON(count > PVSCSI_MAX_NUM_SG_ENTRIES_PER_SEGMENT);
>  
>  	sge = &ctx->sgl->sge[0];
> -	for (i = 0; i < count; i++, sg++) {
> +	for (i = 0; i < count; i++, sg = sg_next(sg)) {
>  		sge[i].addr   = sg_dma_address(sg);
>  		sge[i].length = sg_dma_len(sg);
>  		sge[i].flags  = 0;

Reviewed-by: Ewan D. Milne <emilne@redhat.com>
James Bottomley June 10, 2019, 6:40 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 sgl helper to
> operate sgl.

This also isn't a chained driver.  However, this driver seems to
achieve this by magic number matching, which looks unsafe.  I'd really
prefer it if vmw_pvscsi.h had

#define PVSCSI_MAX_NUM_SG_ENTRIES_PER_SEGMENT SG_ALL

James
Ewan Milne June 10, 2019, 7:39 p.m. UTC | #3
On Mon, 2019-06-10 at 11:40 -0700, James Bottomley wrote:
> 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.
> 
> This also isn't a chained driver.  However, this driver seems to
> achieve this by magic number matching, which looks unsafe.  I'd really
> prefer it if vmw_pvscsi.h had
> 
> #define PVSCSI_MAX_NUM_SG_ENTRIES_PER_SEGMENT SG_ALL
> 
> James
> 

vmw_pvscsi appears to be definitely broken though, that's how Ming found these...

-Ewan
diff mbox series

Patch

diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index ecee4b3ff073..d71abd416eb4 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -335,7 +335,7 @@  static void pvscsi_create_sg(struct pvscsi_ctx *ctx,
 	BUG_ON(count > PVSCSI_MAX_NUM_SG_ENTRIES_PER_SEGMENT);
 
 	sge = &ctx->sgl->sge[0];
-	for (i = 0; i < count; i++, sg++) {
+	for (i = 0; i < count; i++, sg = sg_next(sg)) {
 		sge[i].addr   = sg_dma_address(sg);
 		sge[i].length = sg_dma_len(sg);
 		sge[i].flags  = 0;