From patchwork Thu Jul 23 11:08:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 51390 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id A550120323 for ; Thu, 23 Jul 2015 11:09:09 +0000 (UTC) Received: by lbcjj5 with SMTP id jj5sf31967938lbc.1 for ; Thu, 23 Jul 2015 04:09:08 -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=dlN1fUp+dRuYztGdr0bg+FWp/E6eaFdWhOqLtggbdNYgwKS0ReHOELrkd1I2peYryu WT73r/Ik7K9RN4eUiKpnSDB5s8rRJxnqev/HtgThySvNiKiYC8LISrhMdXq0z8qePbP1 lYqZJj1kgtb/7JnVLnd4mkfei6qr7GT53Yi/FXZRURbzkNb4XxcrlsRWvmNcimAAkGFo fccpUCriVGLsvNetU5C7J6D+brX5Ap0PTKm8T5BH8dH3bzSJFsfUPQAnEUE/Zy+o6Cjw XIQ6OL7sCHwQZcnq5ebtoEeah8xhfF+fw5+LCqFttzFWrD18mIJ51YeG+IlZAafQx9tH jLww== X-Gm-Message-State: ALoCoQmGE1kr69d0FGAdN4lin0KuI+6fgjqKoudoIuku2+vkiMJnh2LxK1F5NT9v0TsWufGqCfKc X-Received: by 10.180.11.226 with SMTP id t2mr3988646wib.0.1437649748604; Thu, 23 Jul 2015 04:09:08 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.34 with SMTP id n2ls204034laj.15.gmail; Thu, 23 Jul 2015 04:09:08 -0700 (PDT) X-Received: by 10.152.180.134 with SMTP id do6mr7014592lac.95.1437649748447; Thu, 23 Jul 2015 04:09:08 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id eu8si3880251lbc.171.2015.07.23.04.09.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Jul 2015 04:09:08 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by lahe2 with SMTP id e2so92780516lah.1 for ; Thu, 23 Jul 2015 04:09:08 -0700 (PDT) X-Received: by 10.152.4.163 with SMTP id l3mr7366794lal.35.1437649748049; Thu, 23 Jul 2015 04:09:08 -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 l6csp486473lba; Thu, 23 Jul 2015 04:09:06 -0700 (PDT) X-Received: by 10.70.38.136 with SMTP id g8mr17066881pdk.156.1437649746173; Thu, 23 Jul 2015 04:09:06 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id hg5si11353908pac.34.2015.07.23.04.09.04 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 23 Jul 2015 04:09:05 -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 1ZIEN0-0003cU-Ge; Thu, 23 Jul 2015 12:08:58 +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 1/5] hw/pci: Use pow2ceil() rather than hand-calculation Date: Thu, 23 Jul 2015 12:08:54 +0100 Message-Id: <1437649738-13885-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1437649738-13885-1-git-send-email-peter.maydell@linaro.org> References: <1437649738-13885-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.48 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));