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: 9192739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5397560756 for ; Wed, 22 Jun 2016 13:04:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43B1B283FD for ; Wed, 22 Jun 2016 13:04:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3647C28408; Wed, 22 Jun 2016 13:04:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2AE1283FD for ; Wed, 22 Jun 2016 13:04:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752706AbcFVNEA (ORCPT ); Wed, 22 Jun 2016 09:04:00 -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-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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)