From patchwork Fri Apr 4 15:47:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 3939421 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6D7DA9F1EE for ; Fri, 4 Apr 2014 15:47:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7DAB120395 for ; Fri, 4 Apr 2014 15:47:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9F3C02038D for ; Fri, 4 Apr 2014 15:47:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753692AbaDDPrt (ORCPT ); Fri, 4 Apr 2014 11:47:49 -0400 Received: from mail-pb0-f52.google.com ([209.85.160.52]:42396 "EHLO mail-pb0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753616AbaDDPrs (ORCPT ); Fri, 4 Apr 2014 11:47:48 -0400 Received: by mail-pb0-f52.google.com with SMTP id rr13so3629497pbb.39 for ; Fri, 04 Apr 2014 08:47:48 -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=NqQpDAvUvINbeeDmKfhox2l1FDh2Hj9WzXeVrkiPjxE=; b=keGR1rjvpuB+oiFBRqJhkhw4UhRP6vLbS/ojcmHpGXQkom3y8aE4LVm0VNTX8u59rt YdnlOv/CgPVbCnI0Y2dF2Wy3TZQtza59x3rkpDzAfrlvzQov2oFP6Vzy8QRyzya08L+Q b5un+IBYoNmY+GakEs46fzx3xs4zjkN0HVmT+XkViDAk1iPUPut7G8su3lFuZIsSyY8/ c7/teNDLL682IzhOWw0MQHWwC2J8bx3NJm2/Zzc+vce9fsNwf1KwTjQTDUgGyq+0Rve3 X+r+ELLqjdae2qs74RAKVVGR3JlEVxwVtPx8Stl2zjbcOMnb6djlx7OE4TXuhTpaXjHj XjFw== 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=NqQpDAvUvINbeeDmKfhox2l1FDh2Hj9WzXeVrkiPjxE=; b=QoYjXRk4Thep4PolzV+VELR9GF8xHLCT60r3c2TFeqJ3FiXEr96AqYtLEQ+0wd6eiO I8vWGP59YrdMXcMfMEJwAS96Mfbfc3GxPPH6+mO4Ry/HqbDvkfHYvL1p4KZTYCeZNn9d UqlCamj/1enTbFdo3LXnitmFGADEai8CchpLq6ozSvXiFQGyir+yY3ih7DRsrbp0N5X1 KWGu/W2CMR3ltBDFbwlJQG/NNUJuFFVRx2QMqZdAJM0tDUwhGhpZEFxoQoESrtv1T6R9 0Po8a6+CO/QrpQsG4umFaFr5lGEuCh0rXRPhvcJuDzB/VkGK0vdwWTqJeFPHlOg1QYZW 7NTg== X-Gm-Message-State: ALoCoQlJUu2pNE5SJoQWof0XppPjVO2rLtXRog1afz2oT6C49lBsx3kLLQSD8c4YB0fa9uZELr0e+mZ1OSErV0oEbw6CEiD9c/HndU0oUolWPtOEQKydevMcxSe1ACgz8CShKcoky3O7O0BNLNXhluomEICaa7yDzQI0AhdXgMEU95AGFf4W8Jd+QPnB7/EF8QRC/Y7Rzj3C2Amuhlgbp6RhiRMHI2IagQ== X-Received: by 10.66.141.231 with SMTP id rr7mr15553732pab.41.1396626467981; Fri, 04 Apr 2014 08:47:47 -0700 (PDT) Received: from google.com ([172.26.55.227]) by mx.google.com with ESMTPSA id kt8sm42382656pab.7.2014.04.04.08.47.46 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 04 Apr 2014 08:47:47 -0700 (PDT) Date: Fri, 4 Apr 2014 09:47:44 -0600 From: Bjorn Helgaas To: Dave Airlie Cc: "linux-pci@vger.kernel.org" Subject: Re: Coverity CID 142811: pci_set_vga_state() operands don't affect result Message-ID: <20140404154744.GA8549@google.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 Thu, Apr 03, 2014 at 02:43:05PM -0600, Bjorn Helgaas wrote: > Coverity complains about this in drivers/pci/pci.c: > > CID 142811 (#1 of 1): Operands don't affect result (CONSTANT_EXPRESSION_RESULT) > result_independent_of_operands: flags & (2U /* 1 << 1 */) & > (command_bits & 4294967292U /* ~(1 | 2) */) is always 0 regardless of > the values of its operands. This occurs as the logical operand of if. > > 4128 WARN_ON((flags & PCI_VGA_STATE_CHANGE_DECODES) & > (command_bits & ~(PCI_COMMAND_IO|PCI_COMMAND_MEMORY))); > > This is a result of 3448a19da479 "vgaarb: use bridges to control VGA > routing where possible." > > I wonder if that middle "&" was intended to be "&&"? I propose the following patch for this. Unless there's objection, I'll queue this for v3.16. I took the liberty of interpreting your email responses as acks. PCI: Fix incorrect vgaarb conditional in WARN_ON() From: Bjorn Helgaas 3448a19da479 "vgaarb: use bridges to control VGA routing where possible" added the "flags & PCI_VGA_STATE_CHANGE_DECODES" condition to an existing WARN_ON(), but used bitwise AND (&) instead of logical AND (&&), so the condition is never true. Replace with logical AND. Found by Coverity (CID 142811). Signed-off-by: Bjorn Helgaas Acked-by: Yinghai Lu Acked-by: David Airlie --- drivers/pci/pci.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/pci.c b/drivers/pci/pci.c index 7325d43bf030..39012831867e 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4125,7 +4125,7 @@ int pci_set_vga_state(struct pci_dev *dev, bool decode, u16 cmd; int rc; - WARN_ON((flags & PCI_VGA_STATE_CHANGE_DECODES) & (command_bits & ~(PCI_COMMAND_IO|PCI_COMMAND_MEMORY))); + WARN_ON((flags & PCI_VGA_STATE_CHANGE_DECODES) && (command_bits & ~(PCI_COMMAND_IO|PCI_COMMAND_MEMORY))); /* ARCH specific VGA enables */ rc = pci_set_vga_state_arch(dev, decode, command_bits, flags);