Skip to contentSkip to conversation

scsi: lpfc: avoid uninitialized variable warning

PATCH Applied Arnd Bergmann 3 participants 3 messages Mar 22, 2019 – Mar 26, 2019

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

PATCH 1/1 scsi: lpfc: avoid uninitialized variable warning

clang -Wuninitialized incorrectly sees a variable being used without initialization:

drivers/scsi/lpfc/lpfc_nvme.c:2102:37: error: variable 'localport' is uninitialized when used here

      [-Werror,-Wuninitialized]
                lport = (struct lpfc_nvme_lport *)localport->private;
                                                  ^~~~~~~~~
drivers/scsi/lpfc/lpfc_nvme.c:2059:38: note: initialize the variable 'localport' to silence this warning
        struct nvme_fc_local_port *localport;
                                            ^
                                             = NULL

1 error generated.

This is clearly in dead code, as the condition leading up to it is always false when CONFIG_NVME_FC is disabled, and the variable is always initialized when nvme_fc_register_localport() got called successfully.

Change the preprocessor conditional to the equivalent C construct, which makes the code more readable and gets rid of the warning.

---
 drivers/scsi/lpfc/lpfc_nvme.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/lpfc/lpfc_nvme.c +4 -4
index 1aa00d2c3f74..9defff711884 100644
@@ -2080,15 +2080,15 @@ lpfc_nvme_create_localport(struct lpfc_vport *vport)
 		lpfc_nvme_template.max_hw_queues =
 			phba->sli4_hba.num_present_cpu;
 
+	if (!IS_ENABLED(CONFIG_NVME_FC))
+		return ret;
+
 	/* localport is allocated from the stack, but the registration
 	 * call allocates heap memory as well as the private area.
 	 */
-#if (IS_ENABLED(CONFIG_NVME_FC))
+
 	ret = nvme_fc_register_localport(&nfcp_info, &lpfc_nvme_template,
 					 &vport->phba->pcidev->dev, &localport);
-#else
-	ret = -ENOMEM;
-#endif
 	if (!ret) {
 		lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_NVME_DISC,
 				 "6005 Successfully registered local "
Signature · 1 line
2.20.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 40 lines · Arnd Bergmann

clang -Wuninitialized incorrectly sees a variable being used without initialization:

drivers/scsi/lpfc/lpfc_nvme.c:2102:37: error: variable 'localport' is uninitialized when used here

       [-Werror,-Wuninitialized]
                 lport = (struct lpfc_nvme_lport *)localport->private;
                                                   ^~~~~~~~~
drivers/scsi/lpfc/lpfc_nvme.c:2059:38: note: initialize the variable 'localport' to silence this warning
         struct nvme_fc_local_port *localport;
                                             ^
                                              = NULL

1 error generated.

This is clearly in dead code, as the condition leading up to it is always false when CONFIG_NVME_FC is disabled, and the variable is always initialized when nvme_fc_register_localport() got called successfully.

Change the preprocessor conditional to the equivalent C construct, which makes the code more readable and gets rid of the warning.

---
  drivers/scsi/lpfc/lpfc_nvme.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/lpfc/lpfc_nvme.c +3 -0
index 1aa00d2c3f74..9defff711884 100644
@@ -2080,15 +2080,15 @@ lpfc_nvme_create_localport(struct lpfc_vport *vport)
  		lpfc_nvme_template.max_hw_queues =
  			phba->sli4_hba.num_present_cpu;
 
+	if (!IS_ENABLED(CONFIG_NVME_FC))
+		return ret;
+
  	/* localport is allocated from the stack, but the registration
  	 * call allocates heap memory as well as the private area.
  	 */

drivers/scsi/lpfc/lpfc_nvme.c lpfc_nvme_create_localport(struct lpfc_vport *vport) · line 2094

Quoted 10 lines
drivers/scsi/lpfc/lpfc_nvme.c +1 -4
-#if (IS_ENABLED(CONFIG_NVME_FC))
+
  	ret = nvme_fc_register_localport(&nfcp_info, &lpfc_nvme_template,
  					 &vport->phba->pcidev->dev, &localport);
-#else
-	ret = -ENOMEM;
-#endif
  	if (!ret) {
  		lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_NVME_DISC,
  				 "6005 Successfully registered local "

Looks good

-- james

#2 lore raw
In reply to Arnd Bergmann

Arnd,

Quoted 4 lines

clang -Wuninitialized incorrectly sees a variable being used without initialization:

drivers/scsi/lpfc/lpfc_nvme.c:2102:37: error: variable 'localport' is uninitialized when used here

Quoted 8 lines
      [-Werror,-Wuninitialized]
                lport = (struct lpfc_nvme_lport *)localport->private;
                                                  ^~~~~~~~~
drivers/scsi/lpfc/lpfc_nvme.c:2059:38: note: initialize the variable 'localport' to silence this warning
        struct nvme_fc_local_port *localport;
                                            ^
                                             = NULL

1 error generated.

Applied to 5.2/scsi-queue, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering