Skip to content

Commit 02096a0

Browse files
arndbrichardweinberger
authored andcommitted
mtd: ubi: avoid expensive do_div() on 32-bit machines
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: b8a77b9 ("mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems") Fixes: 3ce4858 ("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>
1 parent 299af26 commit 02096a0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/mtd/ubi/nvmem.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
/* UBI NVMEM provider */
77
#include "ubi.h"
88
#include <linux/nvmem-provider.h>
9-
#include <asm/div64.h>
109

1110
/* List of all NVMEM devices */
1211
static LIST_HEAD(nvmem_devices);
@@ -27,14 +26,15 @@ static int ubi_nvmem_reg_read(void *priv, unsigned int from,
2726
struct ubi_nvmem *unv = priv;
2827
struct ubi_volume_desc *desc;
2928
uint32_t offs;
30-
uint64_t lnum = from;
29+
uint32_t lnum;
3130
int err = 0;
3231

3332
desc = ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY);
3433
if (IS_ERR(desc))
3534
return PTR_ERR(desc);
3635

37-
offs = do_div(lnum, unv->usable_leb_size);
36+
offs = from % unv->usable_leb_size;
37+
lnum = from / unv->usable_leb_size;
3838
while (bytes_left) {
3939
to_read = unv->usable_leb_size - offs;
4040

0 commit comments

Comments
 (0)