From patchwork Wed Jun 22 12:58:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 102116 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp2537984qgy; Wed, 22 Jun 2016 06:04:14 -0700 (PDT) X-Received: by 10.107.25.7 with SMTP id 7mr36758224ioz.104.1466600654087; Wed, 22 Jun 2016 06:04:14 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sp8si56762790pab.2.2016.06.22.06.04.13; Wed, 22 Jun 2016 06:04:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752747AbcFVNED (ORCPT + 30 others); Wed, 22 Jun 2016 09:04:03 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:61885 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751453AbcFVNDh (ORCPT ); Wed, 22 Jun 2016 09:03:37 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue001) with ESMTPA (Nemesis) id 0MIDR0-1bE31F3J7e-003tSO; Wed, 22 Jun 2016 14:56:55 +0200 From: Arnd Bergmann To: Davidlohr Bueso , Jens Axboe Cc: Arnd Bergmann , linux-efi@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] partition/efi: use ilog2 to compute block size Date: Wed, 22 Jun 2016 14:58:48 +0200 Message-Id: <20160622125905.1269359-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:5IWGVJgPkTV+8FDlC+eOQw27snrdMsn9qgFAe9l5mrFYVLVlj4Q o1SCnhUaoOcD/jTDZp7X4X8MRJY1rgRhuvEl8nUyDqZIUGn65eZJC+YXrhHyZ5fqQbBU0Rt uBaepFz9uYipFBCWR0vUouH7vXYrPWvlkkPou+3pFlQFGk5+0It2RYZxMvfeHg8xIulWDOl CNgYNmNfewemq3heUXhKQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:GvNAWwXcEiM=:qAXIBCoiOtnIixmIiNlBN+ GXaIdj6Ji7Y2Dy7ytnmvXjnsx0OmPXX6OLrSG/Pir+d3pT4jAyolCGcxh8bMn72zZbX79wbkK CUp2hJ66h5aWCAqKBsKiyr5PqSUwIyI5gadvtSqIJUePa7m61dlR8+Cy5QXNbTHF1vbhqArzq p+fyIHu37OzPJheOwnNfZuVs290wP4V3cGm1rH1y/3YhznyphposUsntU6z0s9z7csNDJue8F QqDWO0gbS7GWkmxwGf2Q4Yq0YOSkTMLSQcfKVOnrRiQCdFDs5Jyz9avXGuggV87Vx5WBdedmg ff6Esd9Kiee3iYiylXw3c/cjF5ezrscTLSq5+5rZh9rpbLmEDvhpL3a9SFHoiLQ9Hyux11Tkt xT3bXfxCHkqz3G1RgKAL13ACBIfWJTI+cDLkEswD/OriWnk3YQOeN+5p/cvMJJmKpObfzJvgq HZpbodSzG+V0YBbr6tpw5LmVPirH8GpU4GgzB7xq5xyoID6TzZ+Z+AKA0/9UnlBloqOq7Th7U fvgG9yt9kk12kqRpNvlJ4nvK6mzuG0Pzepon+Jv3DTenSThTHoJcj/Om8bGdaLly3FIJUBZRT eSJLnABLd5ut08bxZpgh2Y6P+oQ08T9GvNQI2Lq1fW/qvG6nQ8FbByrHfEjVHz/xp+TBBFdg4 CiXVEP6cE2XybXMu6iPyaSyCeD8J0SgCAB/ekEVg3WpY7ktsCzItUvqlBZuMK41ayyAQ= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enabling CONFIG_UBSAN_SANITIZE_ALL on ARM caused a link error: last_lba.part.0': :(.text+0xc3440): undefined reference to `____ilog2_NaN' :(.text+0xc3538): undefined reference to `__aeabi_uldivmod' :(.text+0xc38e8): undefined reference to `__aeabi_uldivmod' This is caused by gcc not behaving in the expected ways with __builtin_constant_p(), but it also points to somewhat inefficient code: As we know that the block size is a power-of-two value, we can turn the expensive 64-bit division into a simpler variable bit shift. Signed-off-by: Arnd Bergmann --- block/partitions/efi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.9.0 diff --git a/block/partitions/efi.c b/block/partitions/efi.c index bcd86e5cd546..7d83cf069574 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -147,10 +147,13 @@ efi_crc32(const void *buf, unsigned long len) */ static u64 last_lba(struct block_device *bdev) { + unsigned int blocksize; + if (!bdev || !bdev->bd_inode) return 0; - return div_u64(bdev->bd_inode->i_size, - bdev_logical_block_size(bdev)) - 1ULL; + + blocksize = bdev_logical_block_size(bdev); + return (bdev->bd_inode->i_size >> ilog2(blocksize)) - 1ULL; } static inline int pmbr_part_valid(gpt_mbr_record *part)