linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: lpfc: avoid uninitialized variable warning
@ 2019-03-22 14:25 Arnd Bergmann
  2019-03-22 16:47 ` James Smart
  2019-03-26  2:17 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-03-22 14:25 UTC (permalink / raw)
  To: James Smart, Dick Kennedy, James E.J. Bottomley, Martin K. Petersen
  Cc: Arnd Bergmann, Hannes Reinecke, linux-scsi, linux-kernel

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/scsi/lpfc/lpfc_nvme.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_nvme.c b/drivers/scsi/lpfc/lpfc_nvme.c
index 1aa00d2c3f74..9defff711884 100644
--- a/drivers/scsi/lpfc/lpfc_nvme.c
+++ b/drivers/scsi/lpfc/lpfc_nvme.c
@@ -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 "
-- 
2.20.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: lpfc: avoid uninitialized variable warning
  2019-03-22 14:25 [PATCH] scsi: lpfc: avoid uninitialized variable warning Arnd Bergmann
@ 2019-03-22 16:47 ` James Smart
  2019-03-26  2:17 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: James Smart @ 2019-03-22 16:47 UTC (permalink / raw)
  To: Arnd Bergmann, Dick Kennedy, James E.J. Bottomley, Martin K. Petersen
  Cc: Hannes Reinecke, linux-scsi, linux-kernel

On 3/22/2019 7:25 AM, Arnd Bergmann wrote:
> 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.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>   drivers/scsi/lpfc/lpfc_nvme.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/lpfc/lpfc_nvme.c b/drivers/scsi/lpfc/lpfc_nvme.c
> index 1aa00d2c3f74..9defff711884 100644
> --- a/drivers/scsi/lpfc/lpfc_nvme.c
> +++ b/drivers/scsi/lpfc/lpfc_nvme.c
> @@ -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 "

Looks good

Reviewed-By: James Smart <james.smart@broadcom.com>

-- james


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: lpfc: avoid uninitialized variable warning
  2019-03-22 14:25 [PATCH] scsi: lpfc: avoid uninitialized variable warning Arnd Bergmann
  2019-03-22 16:47 ` James Smart
@ 2019-03-26  2:17 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2019-03-26  2:17 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: James Smart, Dick Kennedy, James E.J. Bottomley,
	Martin K. Petersen, Hannes Reinecke, linux-scsi, linux-kernel


Arnd,

> 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.

Applied to 5.2/scsi-queue, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-26  2:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-22 14:25 [PATCH] scsi: lpfc: avoid uninitialized variable warning Arnd Bergmann
2019-03-22 16:47 ` James Smart
2019-03-26  2:17 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).