scsi: qla4xxx: Don't call dma_free_coherent without dma_alloc_coherent
Subsystems (2)
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.
--- drivers/scsi/qla4xxx/ql4_os.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
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); exit_boot_info: ha->pri_ddb_idx = ddb_index[0 ]; ha->sec_ddb_idx = ddb_index[1 ];
Signature · 1 line
2.21.0
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_dmais initialized bydma_alloc_coherent, which is only called in the middle conditional statement. Use that same conditional to calldma_free_coherentso thatbuf_dmais always initialized when used.Fixes 2a991c215978 ("[SCSI] qla4xxx: Boot from SAN support for open-iscsi")Signed-off-by Nathan Chancellor <[email protected]>--- drivers/scsi/qla4xxx/ql4_os.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/scsi/qla4xxx/ql4_os.c +0
-0
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
PATCH v2 1/1 scsi: qla4xxx: Don't call dma_free_coherent when buf is NULL
In reply to Nathan ChancellorWhen 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.
---
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
@@ -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
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_coherentwhen buf is NULL, meaning that we never calleddma_alloc_coherentand initializedbuf_dma.Fixes 2a991c215978 ("[SCSI] qla4xxx: Boot from SAN support for open-iscsi")Signed-off-by Nathan Chancellor <[email protected]>---
v1 -> v2:
* Check that buf is not NULL, which matches how
dma_free_coherentis 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
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
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_coherentwhen buf is NULL, meaning that we never calleddma_alloc_coherentand initializedbuf_dma.Fixes 2a991c215978 ("[SCSI] qla4xxx: Boot from SAN support for open-iscsi")Signed-off-by Nathan Chancellor <[email protected]>drivers/scsi/qla4xxx/ql4_os.c +0
-0@@ -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
-1exit_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