mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Minfei Huang <mhuang@redhat.com>
To: akpm@linux-foundation.org, rob.jones@codethink.co.uk,
	amhyung@kernel.org, rusty@rustcorp.com.au
Cc: linux-kernel@vger.kernel.org, Minfei Huang <mnfhuang@gmail.com>
Subject: [PATCH 2/2] Define kallsyms_cmp_symbol_t as function type to simplify the code
Date: Tue, 14 Jul 2015 14:59:13 +0800	[thread overview]
Message-ID: <1436857153-18874-3-git-send-email-mhuang@redhat.com> (raw)
In-Reply-To: <1436857153-18874-1-git-send-email-mhuang@redhat.com>

From: Minfei Huang <mnfhuang@gmail.com>

It is not elegance, if we use function directly as the argument, like
following:

int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
                                  struct module *, unsigned long),
                                  void *data);

Here introduce a type defined function kallsyms_cmp_symbol_t. Now
we can use these type defined function directly, if we want to pass
the function as the argument.

int module_kallsyms_on_each_symbol(kallsyms_cmp_symbol_t fn,
					void *data);

Signed-off-by: Minfei Huang <mnfhuang@gmail.com>
---
 include/linux/kallsyms.h | 10 +++-------
 include/linux/module.h   | 13 ++++++-------
 kernel/kallsyms.c        |  4 +---
 kernel/module.c          |  4 +---
 4 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index 6883e19..e8ed37d 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -8,6 +8,7 @@
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/stddef.h>
+#include <linux/module.h>
 
 #define KSYM_NAME_LEN 128
 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
@@ -20,9 +21,7 @@ struct module;
 unsigned long kallsyms_lookup_name(const char *name);
 
 /* Call a function on each kallsyms symbol in the core kernel */
-int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
-				      unsigned long),
-			    void *data);
+int kallsyms_on_each_symbol(kallsyms_cmp_symbol_t fn, void *data);
 
 extern int kallsyms_lookup_size_offset(unsigned long addr,
 				  unsigned long *symbolsize,
@@ -52,10 +51,7 @@ static inline unsigned long kallsyms_lookup_name(const char *name)
 	return 0;
 }
 
-static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *,
-						    struct module *,
-						    unsigned long),
-					  void *data)
+static inline int kallsyms_on_each_symbol(kallsyms_cmp_symbol_t fn, void *data)
 {
 	return 0;
 }
diff --git a/include/linux/module.h b/include/linux/module.h
index 1e125b1..6a05a24 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -479,9 +479,10 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
 /* Look for this name: can be of form module:name. */
 unsigned long module_kallsyms_lookup_name(const char *name);
 
-int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
-					     struct module *, unsigned long),
-				   void *data);
+typedef int (*kallsyms_cmp_symbol_t)(void *, const char *,
+		struct module *, unsigned long);
+
+int module_kallsyms_on_each_symbol(kallsyms_cmp_symbol_t fn, void *data);
 
 extern void __module_put_and_exit(struct module *mod, long code)
 	__attribute__((noreturn));
@@ -637,10 +638,8 @@ static inline unsigned long module_kallsyms_lookup_name(const char *name)
 	return 0;
 }
 
-static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
-							   struct module *,
-							   unsigned long),
-						 void *data)
+static inline int module_kallsyms_on_each_symbol(
+		kallsyms_cmp_symbol_t fn, void *data)
 {
 	return 0;
 }
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 5c5987f..be5786b 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -193,9 +193,7 @@ unsigned long kallsyms_lookup_name(const char *name)
 }
 EXPORT_SYMBOL_GPL(kallsyms_lookup_name);
 
-int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
-				      unsigned long),
-			    void *data)
+int kallsyms_on_each_symbol(kallsyms_cmp_symbol_t fn, void *data)
 {
 	char namebuf[KSYM_NAME_LEN];
 	unsigned long i;
diff --git a/kernel/module.c b/kernel/module.c
index 1400c0b..67ed39b 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -3811,9 +3811,7 @@ unsigned long module_kallsyms_lookup_name(const char *name)
 	return ret;
 }
 
-int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
-					     struct module *, unsigned long),
-				   void *data)
+int module_kallsyms_on_each_symbol(kallsyms_cmp_symbol_t fn, void *data)
 {
 	struct module *mod;
 	unsigned int i;
-- 
2.2.2


  parent reply	other threads:[~2015-07-14  6:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-14  6:59 [PATCH 0/2] Using function type to cleanup the function parament Minfei Huang
2015-07-14  6:59 ` [PATCH 1/2] Define find_symbol_in_section_t as function type to simplify the code Minfei Huang
2015-07-14  7:04   ` Minfei Huang
2015-07-14 21:52   ` Rusty Russell
2015-07-15  2:11     ` Minfei Huang
2015-07-15 20:31     ` Andrew Morton
2015-07-16 11:29       ` Rusty Russell
2015-07-14  6:59 ` Minfei Huang [this message]
2015-07-14  7:05   ` [PATCH 2/2] Define kallsyms_cmp_symbol_t " Minfei Huang
2015-07-14  7:06 ` [PATCH 0/2] Using function type to cleanup the function parament Minfei Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436857153-18874-3-git-send-email-mhuang@redhat.com \
    --to=mhuang@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=amhyung@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mnfhuang@gmail.com \
    --cc=rob.jones@codethink.co.uk \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®