lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <bc04c6adae56428c9e247b0506da5f25@AcuMS.aculab.com>
Date:   Tue, 25 Aug 2020 14:52:47 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "'linux-sctp@...r.kernel.org'" <linux-sctp@...r.kernel.org>,
        Eric Biggers <ebiggers@...nel.org>,
        'Marcelo Ricardo Leitner' <marcelo.leitner@...il.com>,
        'Catalin Marinas' <catalin.marinas@....com>,
        "'kent.overstreet@...il.com'" <kent.overstreet@...il.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        "'Neil Horman'" <nhorman@...driver.com>
Subject: [PATCH 10/13] lib/generic-radix-tree: Simplify offset calculation:

Since these are equivalent:
    (idx / objs_per_page) * PAGE_SIZE + (idx % objs_per_page) * obj_size;
    idx * obj_size + (idx / objs_per_page) * (PAGE_SIZE % obj_size);
Use the latter since it is slightly faster.
It also deosn't need an extra check for obj_size being a power of 2.

Signed-off-by: David Laight <david.laight@...lab.com>
---
 include/linux/generic-radix-tree.h | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/include/linux/generic-radix-tree.h b/include/linux/generic-radix-tree.h
index 53149bc1b92a..5fe1c4c5588d 100644
--- a/include/linux/generic-radix-tree.h
+++ b/include/linux/generic-radix-tree.h
@@ -100,14 +100,9 @@ void __genradix_free(struct __genradix *);
 
 static inline size_t __idx_to_offset(size_t idx, size_t obj_size)
 {
-	if (!is_power_of_2(obj_size)) {
-		size_t objs_per_page = PAGE_SIZE / obj_size;
+	size_t objs_per_page = PAGE_SIZE / obj_size;
 
-		return (idx / objs_per_page) * PAGE_SIZE +
-			(idx % objs_per_page) * obj_size;
-	} else {
-		return idx * obj_size;
-	}
+	return idx * obj_size + (idx / objs_per_page) * (PAGE_SIZE % obj_size);
 }
 
 #define __genradix_cast(_radix)		(typeof((_radix)->type[0]) *)
-- 
2.25.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ