diff mbox series

[2/2] kallsyms: move sprint_module_info to kallsyms_tiny.c

Message ID 20220511080657.3996053-2-maninder1.s@samsung.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [1/2] kallsyms: add kallsyms_show_value definition in all cases | expand

Checks

Context Check Description
bpf/vmtest-bpf-PR fail merge-conflict
netdev/tree_selection success Not a local patch

Commit Message

Maninder Singh May 11, 2022, 8:06 a.m. UTC
As previous patch makes new file for generic kallsyms
(always compilable), move sprint_module_info module to
new file kallsyms_tiny.c

no functional change with this commit

Co-developed-by: Onkarnath <onkarnath.1@samsung.com>
Signed-off-by: Onkarnath <onkarnath.1@samsung.com>
Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
---
 include/linux/kallsyms.h | 11 +++++++++
 kernel/kallsyms_tiny.c   | 47 +++++++++++++++++++++++++++++++++++
 lib/vsprintf.c           | 53 ----------------------------------------
 3 files changed, 58 insertions(+), 53 deletions(-)
diff mbox series

Patch

diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index c5e63a217404..95a2f4ade996 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -27,6 +27,17 @@  struct module;
 /* How and when do we show kallsyms values? */
 extern bool kallsyms_show_value(const struct cred *cred);
 
+#if !defined(CONFIG_KALLSYMS) && defined(CONFIG_MODULES)
+extern int sprint_module_info(char *buf, unsigned long value,
+				int modbuildid, int backtrace, int symbol);
+#else
+static inline int sprint_module_info(char *buf, unsigned long value,
+				int modbuildid, int backtrace, int symbol)
+{
+	return 0;
+}
+#endif
+
 static inline int is_kernel_text(unsigned long addr)
 {
 	if (__is_kernel_text(addr))
diff --git a/kernel/kallsyms_tiny.c b/kernel/kallsyms_tiny.c
index 96ad06836126..8ed9fdd7d9f7 100644
--- a/kernel/kallsyms_tiny.c
+++ b/kernel/kallsyms_tiny.c
@@ -49,3 +49,50 @@  bool kallsyms_show_value(const struct cred *cred)
 		return false;
 	}
 }
+
+#if !defined(CONFIG_KALLSYMS) && defined(CONFIG_MODULES)
+int sprint_module_info(char *buf, unsigned long value,
+			     int modbuildid, int backtrace, int symbol)
+{
+	struct module *mod;
+	unsigned long offset;
+	void *base;
+	char *modname;
+	int len;
+	const unsigned char *buildid = NULL;
+	bool add_offset;
+
+	if (is_ksym_addr(value))
+		return 0;
+
+	if (backtrace || symbol)
+		add_offset = true;
+	else
+		add_offset = false;
+
+	preempt_disable();
+	mod = __module_address(value);
+	if (mod) {
+		modname = mod->name;
+#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
+		if (modbuildid)
+			buildid = mod->build_id;
+#endif
+		if (add_offset) {
+			base = mod->core_layout.base;
+			offset = value - (unsigned long)base;
+		}
+	}
+	preempt_enable();
+	if (!mod)
+		return 0;
+
+	/* address belongs to module */
+	if (add_offset)
+		len = sprintf(buf, "0x%p+0x%lx", base, offset);
+	else
+		len = sprintf(buf, "0x%lx", value);
+
+	return len + fill_name_build_id(buf, modname, modbuildid, buildid, len);
+}
+#endif
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 799fccca4a2d..983fdb02543c 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -999,59 +999,6 @@  char *bdev_name(char *buf, char *end, struct block_device *bdev,
 }
 #endif
 
-#if !defined(CONFIG_KALLSYMS) && defined(CONFIG_MODULES)
-static int sprint_module_info(char *buf, unsigned long value,
-			     int modbuildid, int backtrace, int symbol)
-{
-	struct module *mod;
-	unsigned long offset;
-	void *base;
-	char *modname;
-	int len;
-	const unsigned char *buildid = NULL;
-	bool add_offset;
-
-	if (is_ksym_addr(value))
-		return 0;
-
-	if (backtrace || symbol)
-		add_offset = true;
-	else
-		add_offset = false;
-
-	preempt_disable();
-	mod = __module_address(value);
-	if (mod) {
-		modname = mod->name;
-#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
-		if (modbuildid)
-			buildid = mod->build_id;
-#endif
-		if (add_offset) {
-			base = mod->core_layout.base;
-			offset = value - (unsigned long)base;
-		}
-	}
-	preempt_enable();
-	if (!mod)
-		return 0;
-
-	/* address belongs to module */
-	if (add_offset)
-		len = sprintf(buf, "0x%p+0x%lx", base, offset);
-	else
-		len = sprintf(buf, "0x%lx", value);
-
-	return len + fill_name_build_id(buf, modname, modbuildid, buildid, len);
-}
-#else
-static inline int sprint_module_info(char *buf, unsigned long value,
-			     int modbuildid, int backtrace, int symbol)
-{
-	return 0;
-}
-#endif
-
 static noinline_for_stack
 char *symbol_string(char *buf, char *end, void *ptr,
 		    struct printf_spec spec, const char *fmt)