From patchwork Fri Jul 24 12:33:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 51442 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by patches.linaro.org (Postfix) with ESMTPS id 8FBFE22D94 for ; Fri, 24 Jul 2015 12:52:40 +0000 (UTC) Received: by lbvb1 with SMTP id b1sf7151349lbv.3 for ; Fri, 24 Jul 2015 05:52:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=13q6es25YUpRs69Qq3tipT48WZMZv8HCzBlrE6SssE8=; b=SZ36OGLXC2xom9CwEgtjyQSk+aA0ysi1o7I3oYacMpF7Zlj60ug/XCxJ87ix6n2NPH 5TgyRIs9JFSvEco8Ynwct2lcLR40/B39R23r3qd0yhSynE8MYgbEpkIijobOHLiyK3kT jBmjzDioZ9skqf1SVvIcMNSazcJaG/h+NpucIst2McB8QqF8Se67NiQD/PW6mopJWHS3 QDSfhwngadCiF/rNdgm+IyRjQekxtK7pBZEcmJZWFQXux3aeVN9ar9x1pR2GyucGtVRW 20Y9Gf0+x5jZl5KuT0/u+1+6LkQZbQ7LpBFFRIqJZIpf0tSpSV/EqrpEDH8RAyxBWO4a FklQ== X-Gm-Message-State: ALoCoQl97iEmLbONnBsVsCLQbfksdBk15DzHPKb0ZEkoo5b9/RKNbreX1vGWaPEkEPNRyLoATEaP X-Received: by 10.180.11.226 with SMTP id t2mr1638624wib.0.1437742359117; Fri, 24 Jul 2015 05:52:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.103 with SMTP id l7ls392410laf.35.gmail; Fri, 24 Jul 2015 05:52:38 -0700 (PDT) X-Received: by 10.112.159.162 with SMTP id xd2mr13196038lbb.67.1437742358957; Fri, 24 Jul 2015 05:52:38 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id az11si7466224lab.27.2015.07.24.05.52.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Jul 2015 05:52:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by lafd3 with SMTP id d3so3214790laf.1 for ; Fri, 24 Jul 2015 05:52:38 -0700 (PDT) X-Received: by 10.112.166.2 with SMTP id zc2mr13453113lbb.29.1437742358824; Fri, 24 Jul 2015 05:52:38 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.7.198 with SMTP id l6csp1161611lba; Fri, 24 Jul 2015 05:52:38 -0700 (PDT) X-Received: by 10.180.8.68 with SMTP id p4mr7133552wia.27.1437742357916; Fri, 24 Jul 2015 05:52:37 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id cw6si14627441wjc.208.2015.07.24.05.52.37 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 24 Jul 2015 05:52:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1ZIcA4-0005SW-QG; Fri, 24 Jul 2015 13:33:12 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Paolo Bonzini , Keith Busch , Kevin Wolf , "Michael S. Tsirkin" , qemu-block@nongnu.org Subject: [PATCH v2 1/6] hw/pci: Use pow2ceil() rather than hand-calculation Date: Fri, 24 Jul 2015 13:33:07 +0100 Message-Id: <1437741192-20955-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1437741192-20955-1-git-send-email-peter.maydell@linaro.org> References: <1437741192-20955-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , A couple of places in hw/pci use an inline calculation to round a size up to the next largest power of 2. We have a utility routine for this, so use it. (The behaviour of the old code is different if the size value is 0 -- it would leave it as 0 rather than rounding up to 1, but in both cases we know the size can't be 0. In the case where the size value had bit 31 set, the old code would invoke undefined behaviour; the new code will give a result of 0. Presumably that could never happen either.) Signed-off-by: Peter Maydell --- hw/pci/msix.c | 4 +--- hw/pci/pci.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/hw/pci/msix.c b/hw/pci/msix.c index 7716bf3..2fdada4 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -314,9 +314,7 @@ int msix_init_exclusive_bar(PCIDevice *dev, unsigned short nentries, bar_size = bar_pba_offset + bar_pba_size; } - if (bar_size & (bar_size - 1)) { - bar_size = 1 << qemu_fls(bar_size); - } + bar_size = pow2ceil(bar_size); name = g_strdup_printf("%s-msix", dev->name); memory_region_init(&dev->msix_exclusive_bar, OBJECT(dev), name, bar_size); diff --git a/hw/pci/pci.c b/hw/pci/pci.c index a017614..502da8d 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2065,9 +2065,7 @@ static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom, g_free(path); return; } - if (size & (size - 1)) { - size = 1 << qemu_fls(size); - } + size = pow2ceil(size); vmsd = qdev_get_vmsd(DEVICE(pdev));