mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: James Smart <james.smart@broadcom.com>
To: Arnd Bergmann <arnd@arndb.de>,
	Dick Kennedy <dick.kennedy@broadcom.com>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Hannes Reinecke <hare@suse.com>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: lpfc: avoid uninitialized variable warning
Date: Fri, 22 Mar 2019 09:47:14 -0700	[thread overview]
Message-ID: <1a302ccb-2f9d-560d-8b07-eb5382684b76@broadcom.com> (raw)
In-Reply-To: <20190322142557.929966-1-arnd@arndb.de>

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


  reply	other threads:[~2019-03-22 16:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-22 14:25 Arnd Bergmann
2019-03-22 16:47 ` James Smart [this message]
2019-03-26  2:17 ` Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1a302ccb-2f9d-560d-8b07-eb5382684b76@broadcom.com \
    --to=james.smart@broadcom.com \
    --cc=arnd@arndb.de \
    --cc=dick.kennedy@broadcom.com \
    --cc=hare@suse.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®