diff mbox series

scsi: mvumi: fix build warning

Message ID 20190620062622.9979-1-ming.lei@redhat.com (mailing list archive)
State Accepted
Headers show
Series scsi: mvumi: fix build warning | expand

Commit Message

Ming Lei June 20, 2019, 6:26 a.m. UTC
The local variable 'sg' should be initialized in the failure path of
mvumi_make_sgl(), otherwise the following build warning is triggered:

	In file included from include/linux/pci-dma-compat.h:8,
	                 from include/linux/pci.h:2408,
	                 from drivers/scsi/mvumi.c:13:
	drivers/scsi/mvumi.c: In function 'mvumi_queue_command':
	include/linux/dma-mapping.h:608:34: warning: 'sg' may be used uninitialized in this function
	+[-Wmaybe-uninitialized]
	 #define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, 0)
	                                  ^~~~~~~~~~~~~~~~~~
	drivers/scsi/mvumi.c:192:22: note: 'sg' was declared here
	  struct scatterlist *sg;
                      ^~
Fixed it by removing the local variable reference in failure path.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Ewan D. Milne <emilne@redhat.com>
Fixes: 350d66a72adc ("scsi: mvumi: use sg helper to iterate over scatterlist")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/scsi/mvumi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Bart Van Assche June 20, 2019, 3:26 p.m. UTC | #1
On 6/19/19 11:26 PM, Ming Lei wrote:
> The local variable 'sg' should be initialized in the failure path of
> mvumi_make_sgl(), otherwise the following build warning is triggered:
> 
> 	In file included from include/linux/pci-dma-compat.h:8,
> 	                 from include/linux/pci.h:2408,
> 	                 from drivers/scsi/mvumi.c:13:
> 	drivers/scsi/mvumi.c: In function 'mvumi_queue_command':
> 	include/linux/dma-mapping.h:608:34: warning: 'sg' may be used uninitialized in this function
> 	+[-Wmaybe-uninitialized]
> 	 #define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, 0)
> 	                                  ^~~~~~~~~~~~~~~~~~
> 	drivers/scsi/mvumi.c:192:22: note: 'sg' was declared here
> 	  struct scatterlist *sg;
>                        ^~
> Fixed it by removing the local variable reference in failure path.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
James Bottomley June 20, 2019, 3:30 p.m. UTC | #2
On Thu, 2019-06-20 at 14:26 +0800, Ming Lei wrote:
> The local variable 'sg' should be initialized in the failure path of
> mvumi_make_sgl(), otherwise the following build warning is triggered:
> 
> 	In file included from include/linux/pci-dma-compat.h:8,
> 	                 from include/linux/pci.h:2408,
> 	                 from drivers/scsi/mvumi.c:13:
> 	drivers/scsi/mvumi.c: In function 'mvumi_queue_command':
> 	include/linux/dma-mapping.h:608:34: warning: 'sg' may be used
> uninitialized in this function
> 	+[-Wmaybe-uninitialized]
> 	 #define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n,
> r, 0)
> 	                                  ^~~~~~~~~~~~~~~~~~
> 	drivers/scsi/mvumi.c:192:22: note: 'sg' was declared here
> 	  struct scatterlist *sg;
>                       ^~
> Fixed it by removing the local variable reference in failure path.
> 
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Bart Van Assche <bvanassche@acm.org>
> Cc: Ewan D. Milne <emilne@redhat.com>
> Fixes: 350d66a72adc ("scsi: mvumi: use sg helper to iterate over
> scatterlist")
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
>  drivers/scsi/mvumi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
> index 0022cd31500a..53f3563aca22 100644
> --- a/drivers/scsi/mvumi.c
> +++ b/drivers/scsi/mvumi.c
> @@ -217,7 +217,7 @@ static int mvumi_make_sgl(struct mvumi_hba *mhba,
> struct scsi_cmnd *scmd,
>  		dev_err(&mhba->pdev->dev,
>  			"sg count[0x%x] is bigger than max
> sg[0x%x].\n",
>  			*sg_count, mhba->max_sge);
> -		dma_unmap_sg(&mhba->pdev->dev, sg, sgnum,
> +		dma_unmap_sg(&mhba->pdev->dev, scsi_sglist(scmd),
> sgnum,
>  			     scmd->sc_data_direction);
>  		return -1;
>  	}

I think this is a serious enough problem for mvumi that it needs
folding with comment into the original path.  I believe it will cause
an oops when this code path is hit otherwise, right?

James
Martin K. Petersen June 20, 2019, 8:02 p.m. UTC | #3
Ming,

> The local variable 'sg' should be initialized in the failure path of
> mvumi_make_sgl(), otherwise the following build warning is triggered:

Rolled this fix into the mvumi commit.

Thanks!
diff mbox series

Patch

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 0022cd31500a..53f3563aca22 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -217,7 +217,7 @@  static int mvumi_make_sgl(struct mvumi_hba *mhba, struct scsi_cmnd *scmd,
 		dev_err(&mhba->pdev->dev,
 			"sg count[0x%x] is bigger than max sg[0x%x].\n",
 			*sg_count, mhba->max_sge);
-		dma_unmap_sg(&mhba->pdev->dev, sg, sgnum,
+		dma_unmap_sg(&mhba->pdev->dev, scsi_sglist(scmd), sgnum,
 			     scmd->sc_data_direction);
 		return -1;
 	}