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]
Date: Sat, 15 Jun 2024 16:06:43 +0800
From: Zheng Yejian <zhengyejian1@...wei.com>
To: <kees@...nel.org>, <song@...nel.org>, <ndesaulniers@...gle.com>,
	<yonghong.song@...ux.dev>, <thunder.leizhen@...wei.com>, <ardb@...nel.org>
CC: <linux-kernel@...r.kernel.org>, <zhengyejian1@...wei.com>
Subject: [PATCH] kallsyms: Simply clean get_symbol_pos()

'symbol_end' is just for calculating 'symbolsize', so if 'symbolsize'
is NULL, there is no need to find 'symbol_end'. Besides, if 'offset'
is also NULL, there is even no need to assign to 'symbol_start'. So
just do cleanup.

Signed-off-by: Zheng Yejian <zhengyejian1@...wei.com>
---
 kernel/kallsyms.c | 43 +++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 22ea19a36e6e..fe6a248d629a 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -322,8 +322,8 @@ static unsigned long get_symbol_pos(unsigned long addr,
 				    unsigned long *symbolsize,
 				    unsigned long *offset)
 {
-	unsigned long symbol_start = 0, symbol_end = 0;
-	unsigned long i, low, high, mid;
+	unsigned long symbol_start;
+	unsigned long low, high, mid;
 
 	/* Do a binary search on the sorted kallsyms_addresses array. */
 	low = 0;
@@ -344,28 +344,35 @@ static unsigned long get_symbol_pos(unsigned long addr,
 	while (low && kallsyms_sym_address(low-1) == kallsyms_sym_address(low))
 		--low;
 
+	if (unlikely(!symbolsize && !offset))
+		return low;
+
 	symbol_start = kallsyms_sym_address(low);
 
-	/* Search for next non-aliased symbol. */
-	for (i = low + 1; i < kallsyms_num_syms; i++) {
-		if (kallsyms_sym_address(i) > symbol_start) {
-			symbol_end = kallsyms_sym_address(i);
-			break;
+	if (symbolsize) {
+		unsigned long symbol_end = 0;
+		unsigned long i;
+
+		/* Search for next non-aliased symbol. */
+		for (i = low + 1; i < kallsyms_num_syms; i++) {
+			if (kallsyms_sym_address(i) > symbol_start) {
+				symbol_end = kallsyms_sym_address(i);
+				break;
+			}
 		}
-	}
 
-	/* If we found no next symbol, we use the end of the section. */
-	if (!symbol_end) {
-		if (is_kernel_inittext(addr))
-			symbol_end = (unsigned long)_einittext;
-		else if (IS_ENABLED(CONFIG_KALLSYMS_ALL))
-			symbol_end = (unsigned long)_end;
-		else
-			symbol_end = (unsigned long)_etext;
-	}
+		/* If we found no next symbol, we use the end of the section. */
+		if (!symbol_end) {
+			if (is_kernel_inittext(addr))
+				symbol_end = (unsigned long)_einittext;
+			else if (IS_ENABLED(CONFIG_KALLSYMS_ALL))
+				symbol_end = (unsigned long)_end;
+			else
+				symbol_end = (unsigned long)_etext;
+		}
 
-	if (symbolsize)
 		*symbolsize = symbol_end - symbol_start;
+	}
 	if (offset)
 		*offset = addr - symbol_start;
 
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ