Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8249466ybi; Thu, 6 Jun 2019 09:02:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/oaF9D4bdF/Yg63Qjq+kVUmWFDdaQtl2Gqt2txjXGS2hUSImxohHDUe8zwhGgIYu4ExvS X-Received: by 2002:a63:1b0e:: with SMTP id b14mr4063424pgb.365.1559836933038; Thu, 06 Jun 2019 09:02:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559836933; cv=none; d=google.com; s=arc-20160816; b=N0kYdq2qo1ILozKaAMoUxe+tw9MTWgrm6hDSHr1Cqz2jlhSjRGiF8/cWS3PuWDo+2u +Ex2gIpsIETlrFjybGvEPCtljKwXrgT2bI3K4OUXLm/IzokDdZLsiv18RQGUyP9EtFg2 H7RFCsvzAYUQczMQ9jOgLSKDwBlMwKgPa8O0+SaV5v0PQ/0iHoA4AGGXKdx6/GqT85Jc qgCmkTq3XgYBPxdqUS6gxvHI8fNx3SbMFO7R+KPcyYEdysWpLx1VucDT84gc9Q6M9TYr p1TjRd1pfZao15mD3+JgC30WM6QTl0e++VZ6Alyt5GqyQOzFh+fbILHRSBCJVKdqRPX1 EDFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ZYp/2XuxF4NBBIxpEf3TefxcM6zkxnjlEsipp8Zq6pU=; b=lpGZmLCGdOpuiYWZGp4xloMOEVP9sBXjUUb/LVryuTmfpE32x/0icbgrlWXYn775rn uuWVuYCjmLWOnQ5eDMN4R3jkJ+dkZctQfQZnHzhNXv3eakOKTiamBCavgvjkUGZHYVIu /XXZqieY4uU5vQvJlh+BoV79Egw+m9zO9UsolX7hkTjCrzUR7CJf7l4Yhk0vV4OSOMaM VjS0EREq/DgHB6WvGAxttOjQg5YKE/5HbQhpWRRgjAzKMcIKUHQ6op8mBKlacDMWTC5I 56JJunXLLnBtFj25LXfTXb0oEAK7X09suLOL78UJaJsE4dbAQyTHJmt/Guwi/zm5yjRt 6A4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RXu89w+r; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x7si2218157plv.130.2019.06.06.09.01.56; Thu, 06 Jun 2019 09:02:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RXu89w+r; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729473AbfFFQAs (ORCPT + 99 others); Thu, 6 Jun 2019 12:00:48 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:45529 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729145AbfFFQAr (ORCPT ); Thu, 6 Jun 2019 12:00:47 -0400 Received: by mail-ed1-f68.google.com with SMTP id f20so4041132edt.12; Thu, 06 Jun 2019 09:00:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ZYp/2XuxF4NBBIxpEf3TefxcM6zkxnjlEsipp8Zq6pU=; b=RXu89w+r5huBrCw1onIkFIQGk8BkHVfEL92HtWU3BuaaT4tlAzQZ93TKtQzwlWhne/ HIRqiE7r2VrTRig5TS2dxVMqD2jevzMQM5ZkrSr4qXVHRfk3TZ/QzghCPR+TX79jpCc+ 0cKjbqBfi41xtJc9yVYvzMHfV19rP21PFRfvj4YRIz7Vke/W8VC9szsgwVFQwkdCWlkY PVyi4E+B8w4jnl4msENwMOr57+a+Ha/56Hz+hkoVyisIDXZS8/R0Ht332pLwJHlx+A6W sfHMzEUJXoKU0Ej/nsieaxqCB3NXTNzVgMHkhqIzHOCFq9Zxz/rpB0Mmj57oMDa4byD6 ih6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ZYp/2XuxF4NBBIxpEf3TefxcM6zkxnjlEsipp8Zq6pU=; b=nm6jJF5m+woRL22or5B5IZBTnei2qkZ7kimcPrZWBFa2xlR2mwOvvMqBw4Vetd2upY D5iGgyoqEHMu+VK+ecZfZ57b+ahyj/9Y6Z511nMWwlTxpfFWzuhI9ukuogjyw1DxbiiJ DoW50kPdDcnLZl2ve7ETwAiRTCxWkWFycvrGk0D3+xo99rzRNBGEUeXL2zV83OHSSpGc bxGWLZkNJJK5BEklSNYOZLHAGpQkRIM4wByfV9B9RmlG0ArvYJil9xbrpTDpSdn0ueQK pzN0gadl7aiSiUt6M8HiIw2nmlEp5c6p/vAJJlNqyxM2yV9XIEykFmyPELKxgZNeLbqO wONQ== X-Gm-Message-State: APjAAAXGFLdKfiwyy56p1aaaDn2sDfaDjecKIdAM07JIHHit9TI5UNpo ryl+RVrXg9UlCBmMtUkDrN4= X-Received: by 2002:a50:e1c9:: with SMTP id m9mr33418888edl.71.1559836845424; Thu, 06 Jun 2019 09:00:45 -0700 (PDT) Received: from archlinux-epyc ([2a01:4f9:2b:2b15::2]) by smtp.gmail.com with ESMTPSA id y21sm392280ejm.60.2019.06.06.09.00.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 06 Jun 2019 09:00:44 -0700 (PDT) Date: Thu, 6 Jun 2019 09:00:42 -0700 From: Nathan Chancellor To: Pavel Machek Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, stable@vger.kernel.org, Arnd Bergmann , James Smart , "Martin K. Petersen" , Sasha Levin Subject: Re: [PATCH 4.19 237/276] scsi: lpfc: avoid uninitialized variable warning Message-ID: <20190606160042.GA54183@archlinux-epyc> References: <20190530030523.133519668@linuxfoundation.org> <20190530030539.944220603@linuxfoundation.org> <20190606125323.GC27432@amd> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190606125323.GC27432@amd> User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 06, 2019 at 02:53:23PM +0200, Pavel Machek wrote: > Hi! > > > [ Upstream commit faf5a744f4f8d76e7c03912b5cd381ac8045f6ec ] > > > > 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. > > Unfortunately, this missed "else" branch where the code was freeing > the memory with kfree(cstat)... so this introduces a memory leak. > > Best regards, > Pavel For the record, this is not a problem with the upstream commit (not saying you thought that or not, I just want to be clear). Looks like commit 4c47efc140fa ("scsi: lpfc: Move SCSI and NVME Stats to hardware queue structures") "resolved" this by not making it an issue in the first place. I think the simpler fix is this. Thanks for pointing it out! diff --git a/drivers/scsi/lpfc/lpfc_nvme.c b/drivers/scsi/lpfc/lpfc_nvme.c index 099f70798fdd..645ffb5332b4 100644 --- a/drivers/scsi/lpfc/lpfc_nvme.c +++ b/drivers/scsi/lpfc/lpfc_nvme.c @@ -2477,14 +2477,14 @@ lpfc_nvme_create_localport(struct lpfc_vport *vport) lpfc_nvme_template.max_sgl_segments = phba->cfg_nvme_seg_cnt + 1; lpfc_nvme_template.max_hw_queues = phba->cfg_nvme_io_channel; + if (!IS_ENABLED(CONFIG_NVME_FC)) + return ret; + cstat = kmalloc((sizeof(struct lpfc_nvme_ctrl_stat) * phba->cfg_nvme_io_channel), GFP_KERNEL); if (!cstat) return -ENOMEM; - 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. */