From patchwork Tue Apr 29 23:06:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 4089651 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 07F79BFF02 for ; Tue, 29 Apr 2014 23:06:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 083A920222 for ; Tue, 29 Apr 2014 23:06:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 23DCD2021F for ; Tue, 29 Apr 2014 23:06:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755877AbaD2XGQ (ORCPT ); Tue, 29 Apr 2014 19:06:16 -0400 Received: from mail-ie0-f176.google.com ([209.85.223.176]:64084 "EHLO mail-ie0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755874AbaD2XGP (ORCPT ); Tue, 29 Apr 2014 19:06:15 -0400 Received: by mail-ie0-f176.google.com with SMTP id rd18so1001240iec.7 for ; Tue, 29 Apr 2014 16:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=oM8iaBlmZxraI1Cjcz3e/QaHAnPsuxbJGf7v89OJN18=; b=pn2ysZRn5byAkM9wIB1WLPa3YorbC1dWyKoZXUn/DPcdblmafdzPO9SW8lbgPtXgjo QFZpna3GJTkD5zBsVcWnwuydaAOMk2gyVuMEk1wsooR5GIenT8Z2k2Ai7I5WceJrmCFi 8I+y2L2OB7fFLor15EUfgoW6+eZljQEKS6Ulnp2axJum8swc2T7jAOglOjg1k0lv7wWW xaovvjT5lWpVLQMKlHAfBotUWTMsOxHg+6rVMMis1nZok3Cm6T3Ij/8nPvPq5IXn/L0I Gpdo2hiHp/0sXKVqPbIlTzGuLr9PadP6PqIvypWKoXFZ37i4KWRCWEUKPEuCGzGhmYUb HgZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=oM8iaBlmZxraI1Cjcz3e/QaHAnPsuxbJGf7v89OJN18=; b=C5CEGQimeKe9aN8SuL9ioQQVchQkCFePx5hpWM8PjZtCH36sJPMAAk/WDm+5RgSRoi FLLYMnrxJqkbVyR74aydPrLwfY4rA2S/Tk8/X1PaugR0N7K4+XrFlz/p/MJLDvrlAtFw osaw1MYSyO/Sj2yu6z7dt54fjQQQwWr/wD1bvi5NPHwLA76T1TeDeW6XgnH+jqu+Hoiw zOLA5fCi6wkAsDnoDIs7tGcg7wGtvpW4saRGuN5gBhjIwkVZprWQbeuR0T1s0vVpN7I9 mbzhZc+bqT0OJiGUIQmi6Ge0iE5oaZA6e45fqw1dmT4cuHOHMnl1PeP/Y2bmkh3//Ain YUbw== X-Gm-Message-State: ALoCoQnNOfzmDFfTsO7b+gUksA+EpwAWfKM+SYz2j8FK+GshD+Dcm7tL4W5f17ESYiUsR1cax700kPruRGy4xo00C5SDuBbxNB5ra5u7tntJTGSaaAean9d5UPM155addg8z4K4e/CvZrG/MoAVY1ghcBpfZZpZ2FBlQVW0u1Yr0Z0HbT3T20jOSfDSSQtUQoz45WsUL7slEnoy/uCv6EMWNrMZ/FT0+mA== X-Received: by 10.50.13.100 with SMTP id g4mr34565240igc.9.1398812774894; Tue, 29 Apr 2014 16:06:14 -0700 (PDT) Received: from google.com ([172.16.51.53]) by mx.google.com with ESMTPSA id n5sm11497367igr.0.2014.04.29.16.06.14 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 29 Apr 2014 16:06:14 -0700 (PDT) Date: Tue, 29 Apr 2014 17:06:12 -0600 From: Bjorn Helgaas To: Yijing Wang Cc: Jon Mason , "linux-pci@vger.kernel.org" Subject: Re: Coverity CID 146454: pcie_bus_configure_settings() use of uninitialized variable Message-ID: <20140429230612.GA9795@google.com> References: <533E0F84.1050302@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <533E0F84.1050302@huawei.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Apr 04, 2014 at 09:48:52AM +0800, Yijing Wang wrote: > Hi Bjorn, > Jon seems to send a patch to fix this long ago. Link: http://patchwork.ozlabs.org/patch/191054/ > But this patch cannot be applied now. I think we can just set smpss = 0 in this function as the default value. Yep. It's ugly, but I don't have time to try to make it prettier. I'll apply the patch below. > On 2014/4/4 0:09, Bjorn Helgaas wrote: > > Coverity complains that "smpss" is used uninitialized in > > drivers/pci/probe.c in pcie_bus_configure_settings() when calling > > pcie_bus_configure_set(): > > > > 1642 pcie_bus_configure_set(bus->self, &smpss); > > 1643 pci_walk_bus(bus, pcie_bus_configure_set, &smpss); > > > > "smpss" may be uninitialized, and pcie_bus_configure_set() > > dereferences the pointer it receives. > > > > This is CID 146454. > > > > Bjorn PCI: Fix use of uninitialized MPS value From: Bjorn Helgaas If "pcie_bus_config == PCIE_BUS_PERFORMANCE", we don't initialize "smpss", so we pass a pointer to garbage into pcie_bus_configure_set(), where we compute "mps" based on the garbage. We then pass the garbage "mps" to pcie_write_mps(), which ignores it in the PCIE_BUS_PERFORMANCE case. Coverity isn't smart enough to deduce that we ignore the garbage (it's a lot to expect from a human, too), so initialize "smpss" to a safe value in all cases. Found by Coverity (CID 146454). Signed-off-by: Bjorn Helgaas --- drivers/pci/probe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index fe89a982a3da..490031fd2108 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1617,7 +1617,7 @@ static int pcie_bus_configure_set(struct pci_dev *dev, void *data) */ void pcie_bus_configure_settings(struct pci_bus *bus) { - u8 smpss; + u8 smpss = 0; if (!bus->self) return;