From patchwork Fri Nov 20 21:30:50 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 61817 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nAKLVE33023783 for ; Fri, 20 Nov 2009 21:31:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755013AbZKTVar (ORCPT ); Fri, 20 Nov 2009 16:30:47 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755629AbZKTVaq (ORCPT ); Fri, 20 Nov 2009 16:30:46 -0500 Received: from palinux.external.hp.com ([192.25.206.14]:47264 "EHLO mail.parisc-linux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755110AbZKTVap (ORCPT ); Fri, 20 Nov 2009 16:30:45 -0500 Received: by mail.parisc-linux.org (Postfix, from userid 26919) id 007CD494003; Fri, 20 Nov 2009 14:30:50 -0700 (MST) Date: Fri, 20 Nov 2009 14:30:50 -0700 From: Matthew Wilcox To: linux-pci@vger.kernel.org Subject: [PCIUTILS PATCH] Improve large BAR display Message-ID: <20091120213050.GB8502@parisc-linux.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org diff --git a/lspci.c b/lspci.c index e453f1b..8685409 100644 --- a/lspci.c +++ b/lspci.c @@ -330,18 +330,16 @@ show_terse(struct device *d) static void show_size(pciaddr_t x) { + static const char suffix[][4] = { "", "KiB", "MiB", "GiB", "TiB" }; + unsigned i; if (!x) return; - printf(" [size="); - if (x < 1024) - printf("%d", (int) x); - else if (x < 1048576) - printf("%dK", (int)(x / 1024)); - else if (x < 0x80000000) - printf("%dM", (int)(x / 1048576)); - else - printf(PCIADDR_T_FMT, x); - putchar(']'); + for (i = 0; i < (sizeof(suffix) / sizeof(*suffix) - 1); i++) { + if (x < 1024) + break; + x /= 1024; + } + printf(" [size=%u%s]", (unsigned)x, suffix[i]); } static void