From patchwork Thu Oct 20 12:57:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 78500 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp767698qge; Thu, 20 Oct 2016 05:58:58 -0700 (PDT) X-Received: by 10.31.114.71 with SMTP id n68mr601337vkc.129.1476968338901; Thu, 20 Oct 2016 05:58:58 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s65si22042360vkh.24.2016.10.20.05.58.58 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 20 Oct 2016 05:58:58 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54699 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxCvy-0003ET-CW for patch@linaro.org; Thu, 20 Oct 2016 08:58:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxCuL-0002Ss-Bz for qemu-devel@nongnu.org; Thu, 20 Oct 2016 08:57:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxCuK-0004JL-NQ for qemu-devel@nongnu.org; Thu, 20 Oct 2016 08:57:17 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:47379) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bxCuK-0004DT-DY for qemu-devel@nongnu.org; Thu, 20 Oct 2016 08:57:16 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1bxCuB-0006t0-IE; Thu, 20 Oct 2016 13:57:07 +0100 From: Peter Maydell To: qemu-devel@nongnu.org, qemu-trivial@nongnu.org Date: Thu, 20 Oct 2016 13:57:06 +0100 Message-Id: <1476968226-15918-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH] s390: avoid always-true comparison in s390_pci_generate_fid() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cornelia Huck , Christian Borntraeger , Alexander Graf , Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Coverity points out that the comparison "fid <= ZPCI_MAX_FID" in s390_pci_generate_fid() is always true (because fid is 32 bits and ZPCI_MAX_FID is 0xffffffff). This isn't a bug because the real loop termination condition is expressed later via an "if (...) break;" inside the loop, but it is a bit odd. Rephrase the loop to avoid the unnecessary duplicate-but-never-true conditional. Signed-off-by: Peter Maydell --- hw/s390x/s390-pci-bus.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) -- 2.7.4 Acked-by: Cornelia Huck diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c index b7f8bca..bbbe0b1 100644 --- a/hw/s390x/s390-pci-bus.c +++ b/hw/s390x/s390-pci-bus.c @@ -809,17 +809,11 @@ static uint32_t s390_pci_generate_fid(Error **errp) { uint32_t fid = 0; - while (fid <= ZPCI_MAX_FID) { + do { if (!s390_pci_find_dev_by_fid(fid)) { return fid; } - - if (fid == ZPCI_MAX_FID) { - break; - } - - fid++; - } + } while (fid++ != ZPCI_MAX_FID); error_setg(errp, "no free fid could be found"); return 0;