Skip to contentSkip to conversation

scsi: qla4xxx: Don't call dma_free_coherent without dma_alloc_coherent

PATCH In review Nathan Chancellor 3 participants 5 messages Mar 7, 2019 – Mar 22, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: qla4xxx: Don't call dma_free_coherent without dma_alloc_coherent

When building with -Wsometimes-uninitialized, Clang warns:

drivers/scsi/qla4xxx/ql4_os.c:5915:7: warning: variable 'buf_dma' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

buf_dma is initialized by dma_alloc_coherent, which is only called in the middle conditional statement. Use that same conditional to call dma_free_coherent so that buf_dma is always initialized when used.

Fixes 2a991c215978 ("[SCSI] qla4xxx: Boot from SAN support for open-iscsi")
---
 drivers/scsi/qla4xxx/ql4_os.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/qla4xxx/ql4_os.c +2 -1
index 16a18d5d856f..88bb52456efd 100644
@@ -5982,7 +5982,8 @@ static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
 			  ddb_index[1]));
 
 exit_boot_info_free:
-	dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
+	if (is_qla80XX(ha))
+		dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
 exit_boot_info:
 	ha->pri_ddb_idx = ddb_index[0];
 	ha->sec_ddb_idx = ddb_index[1];
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/scsi/qla4xxx/ql4_os.c:5915:7: warning: variable 'buf_dma' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

buf_dma is initialized by dma_alloc_coherent, which is only called in the middle conditional statement. Use that same conditional to call dma_free_coherent so that buf_dma is always initialized when used.

Fixes 2a991c215978 ("[SCSI] qla4xxx: Boot from SAN support for open-iscsi")
---
 drivers/scsi/qla4xxx/ql4_os.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/qla4xxx/ql4_os.c +0 -0
index 16a18d5d856f..88bb52456efd 100644

drivers/scsi/qla4xxx/ql4_os.c static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[]) · line 5986

Quoted 6 lines
drivers/scsi/qla4xxx/ql4_os.c +2 -1
@@ -5982,7 +5982,8 @@ static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
                          ddb_index[1]));
 
 exit_boot_info_free:
-       dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
+       if (is_qla80XX(ha))
+               dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);

Very tricky code flow to follow in this function, but this patch makes sense upon closer inspection. Thanks for the patch Nathan

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw

PATCH v2 1/1 scsi: qla4xxx: Don't call dma_free_coherent when buf is NULL

In reply to Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/scsi/qla4xxx/ql4_os.c:5915:7: warning: variable 'buf_dma' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

Don't call dma_free_coherent when buf is NULL, meaning that we never called dma_alloc_coherent and initialized buf_dma.

Fixes 2a991c215978 ("[SCSI] qla4xxx: Boot from SAN support for open-iscsi")

---

v1 -> v2:

* Check that buf is not NULL, which matches how dma_free_coherent is called in the rest of the tree. This still fixes the warning.

 drivers/scsi/qla4xxx/ql4_os.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/qla4xxx/ql4_os.c +2 -1
index 16a18d5d856f..9f56dafc3cda 100644
@@ -5982,7 +5982,8 @@ static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
 			  ddb_index[1]));
 
 exit_boot_info_free:
-	dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
+	if (buf)
+		dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
 exit_boot_info:
 	ha->pri_ddb_idx = ddb_index[0];
 	ha->sec_ddb_idx = ddb_index[1];
Signature · 1 line
2.21.0
#3 lore raw

Re: [PATCH v2] scsi: qla4xxx: Don't call dma_free_coherent when buf is NULL

Quoted 28 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/scsi/qla4xxx/ql4_os.c:5915:7: warning: variable 'buf_dma' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

Don't call dma_free_coherent when buf is NULL, meaning that we never called dma_alloc_coherent and initialized buf_dma.

Fixes 2a991c215978 ("[SCSI] qla4xxx: Boot from SAN support for open-iscsi")

---

v1 -> v2:

* Check that buf is not NULL, which matches how dma_free_coherent is called in the rest of the tree. This still fixes the warning.

 drivers/scsi/qla4xxx/ql4_os.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/qla4xxx/ql4_os.c +0 -0
index 16a18d5d856f..9f56dafc3cda 100644

drivers/scsi/qla4xxx/ql4_os.c static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[]) · line 5986

Quoted 6 lines
drivers/scsi/qla4xxx/ql4_os.c +2 -1
@@ -5982,7 +5982,8 @@ static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
                          ddb_index[1]));
 
 exit_boot_info_free:
-       dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
+       if (buf)
+               dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);

Same thoughts as: https://lkml.org/lkml/2019/3/8/786
WDYT?

Signature · 2 lines
Thanks,
~Nick Desaulniers
#4 lore raw

Re: [PATCH v2] scsi: qla4xxx: Don't call dma_free_coherent when buf is NULL

Quoted 24 lines · Nick Desaulniers' via Clang Built Linux
Quoted 21 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/scsi/qla4xxx/ql4_os.c:5915:7: warning: variable 'buf_dma' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

Don't call dma_free_coherent when buf is NULL, meaning that we never called dma_alloc_coherent and initialized buf_dma.

Fixes 2a991c215978 ("[SCSI] qla4xxx: Boot from SAN support for open-iscsi")
drivers/scsi/qla4xxx/ql4_os.c +0 -0
index 16a18d5d856f..9f56dafc3cda 100644
@@ -5982,7 +5982,8 @@ static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
                          ddb_index[1]));
 
Quoted 7 lines

drivers/scsi/qla4xxx/ql4_os.c static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[]) · line 5986

Quoted 4 lines
drivers/scsi/qla4xxx/ql4_os.c +2 -1
 exit_boot_info_free:
-       dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
+       if (buf)
+               dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);

Same thoughts as: https://lkml.org/lkml/2019/3/8/786
WDYT?

Initializing the variable is definitely worse here, don't listen to clang's bad suggestions ;-)

This was my fix, I'll send that as a proper patch as well:

drivers/scsi/qla4xxx/ql4_os.c +0 -0
@@ -5928,7 +5928,7 @@ static int get_fw_boot_info(struct scsi_qla_host

*ha, uint16_t ddb_index[])

                val = rd_nvram_byte(ha, sec_addr);
                if (val & BIT_7)
                        ddb_index[1] = (val & 0x7f);
-
+               goto exit_boot_info;
        } else if (is_qla80XX(ha)) {
                buf = dma_alloc_coherent(&ha->pdev->dev, size,
                                         &buf_dma, GFP_KERNEL);


      Arnd