Preparation to simplify the review of the next patch.

Add 2 "dummy" helpers used by FETCH_MTD_{symbol,deref} parse/fetch
code: calc_probe_offset(offset) which currently simply returns its
arg, and parse_probe_offset(name, offset) which calls kstrtol().

Signed-off-by: Oleg Nesterov <o...@redhat.com>
---
 kernel/trace/trace_probe.c |   27 +++++++++++++++++++++------
 1 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index dcf7780..723e6e9 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -263,12 +263,14 @@ static struct symbol_cache *alloc_symbol_cache(const char 
*sym, long offset)
        return sc;
 }
 
+static long calc_probe_offset(unsigned long offset);
+
 #define DEFINE_FETCH_symbol(type)                                      \
 static __kprobes void FETCH_FUNC_NAME(symbol, type)(struct pt_regs *regs,\
                                          void *data, void *dest)       \
 {                                                                      \
        struct symbol_cache *sc = data;                                 \
-       long off = sc->offset;                                          \
+       long off = calc_probe_offset(sc->offset);                       \
        if (sc->addr)                                                   \
                fetch_memory_##type(regs, (void *)sc->addr + off, dest);\
        else                                                            \
@@ -292,7 +294,7 @@ static __kprobes void FETCH_FUNC_NAME(deref, type)(struct 
pt_regs *regs,\
        unsigned long addr;                                             \
        call_fetch(&dprm->orig, regs, &addr);                           \
        if (addr) {                                                     \
-               addr += dprm->offset;                                   \
+               addr += calc_probe_offset(dprm->offset);                \
                fetch_memory_##type(regs, (void *)addr, dest);          \
        } else                                                          \
                *(type *)dest = 0;                                      \
@@ -487,6 +489,8 @@ static fetch_func_t get_fetch_size_function(const struct 
fetch_type *type,
        return NULL;
 }
 
+static int parse_probe_offset(const char *name, unsigned long *offset);
+
 /* Split symbol and offset. */
 int traceprobe_split_symbol_offset(char *symbol, unsigned long *offset)
 {
@@ -495,8 +499,7 @@ int traceprobe_split_symbol_offset(char *symbol, unsigned 
long *offset)
 
        tmp = strchr(symbol, '+');
        if (tmp) {
-               /* skip sign because kstrtoul doesn't accept '+' */
-               ret = kstrtoul(tmp + 1, 0, offset);
+               ret = parse_probe_offset(tmp, offset);
                if (ret)
                        return ret;
 
@@ -588,6 +591,19 @@ static int pseudo_reg_query_offset(const char *name)
        return -EINVAL;
 }
 
+static long calc_probe_offset(unsigned long offset)
+{
+       return offset;
+}
+
+static int parse_probe_offset(const char *name, unsigned long *offset)
+{
+       if (name[0] == '+')     /* kstrtol() rejects '+' */
+               name++;
+
+       return kstrtol(name, 0, offset);
+}
+
 /* Recursive argument parser */
 static int parse_probe_arg(char *arg, const struct fetch_type *t,
                     struct fetch_param *f, bool is_return, bool is_kprobe)
@@ -641,14 +657,13 @@ static int parse_probe_arg(char *arg, const struct 
fetch_type *t,
                break;
 
        case '+':       /* deref memory */
-               arg++;  /* Skip '+', because kstrtol() rejects it. */
        case '-':
                tmp = strchr(arg, '(');
                if (!tmp)
                        break;
 
                *tmp = '\0';
-               ret = kstrtol(arg, 0, &offset);
+               ret = parse_probe_offset(arg, &offset);
 
                if (ret)
                        break;
-- 
1.5.5.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to