]> www.infradead.org Git - users/willy/xarray.git/commitdiff
mtd: ubi: avoid expensive do_div() on 32-bit machines
authorArnd Bergmann <arnd@arndb.de>
Wed, 13 Mar 2024 08:46:52 +0000 (09:46 +0100)
committerRichard Weinberger <richard@nod.at>
Fri, 12 Jul 2024 17:46:21 +0000 (19:46 +0200)
The use of do_div() in ubi_nvmem_reg_read() makes calling it on
32-bit machines rather expensive. Since the 'from' variable is
known to be a 32-bit quantity, it is clearly never needed and
can be optimized into a regular division operation.

Fixes: b8a77b9a5f9c ("mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems")
Fixes: 3ce485803da1 ("mtd: ubi: provide NVMEM layer over UBI volumes")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
drivers/mtd/ubi/nvmem.c

index 8aeb9c428e51011cfc146c30339d96bfdda2ea50..a94a1a9aaec10e4add3154e2bbec572f200439ac 100644 (file)
@@ -6,7 +6,6 @@
 /* UBI NVMEM provider */
 #include "ubi.h"
 #include <linux/nvmem-provider.h>
-#include <asm/div64.h>
 
 /* List of all NVMEM devices */
 static LIST_HEAD(nvmem_devices);
@@ -27,14 +26,15 @@ static int ubi_nvmem_reg_read(void *priv, unsigned int from,
        struct ubi_nvmem *unv = priv;
        struct ubi_volume_desc *desc;
        uint32_t offs;
-       uint64_t lnum = from;
+       uint32_t lnum;
        int err = 0;
 
        desc = ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY);
        if (IS_ERR(desc))
                return PTR_ERR(desc);
 
-       offs = do_div(lnum, unv->usable_leb_size);
+       offs = from % unv->usable_leb_size;
+       lnum = from / unv->usable_leb_size;
        while (bytes_left) {
                to_read = unv->usable_leb_size - offs;