Merge tag 'v3.10.103' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / kernel / trace / trace_printk.c
index a9077c1b4ad3f402ecc7580b8c918e0b50db5318..9008103db583ed354a2e44136489a78ce92c2769 100644 (file)
@@ -38,6 +38,10 @@ struct trace_bprintk_fmt {
 static inline struct trace_bprintk_fmt *lookup_format(const char *fmt)
 {
        struct trace_bprintk_fmt *pos;
+
+       if (!fmt)
+               return ERR_PTR(-EINVAL);
+
        list_for_each_entry(pos, &trace_bprintk_fmt_list, list) {
                if (!strcmp(pos->fmt, fmt))
                        return pos;
@@ -59,7 +63,8 @@ void hold_module_trace_bprintk_format(const char **start, const char **end)
        for (iter = start; iter < end; iter++) {
                struct trace_bprintk_fmt *tb_fmt = lookup_format(*iter);
                if (tb_fmt) {
-                       *iter = tb_fmt->fmt;
+                       if (!IS_ERR(tb_fmt))
+                               *iter = tb_fmt->fmt;
                        continue;
                }
 
@@ -244,12 +249,31 @@ static const char **find_next(void *v, loff_t *pos)
 {
        const char **fmt = v;
        int start_index;
+       int last_index;
 
        start_index = __stop___trace_bprintk_fmt - __start___trace_bprintk_fmt;
 
        if (*pos < start_index)
                return __start___trace_bprintk_fmt + *pos;
 
+       /*
+        * The __tracepoint_str section is treated the same as the
+        * __trace_printk_fmt section. The difference is that the
+        * __trace_printk_fmt section should only be used by trace_printk()
+        * in a debugging environment, as if anything exists in that section
+        * the trace_prink() helper buffers are allocated, which would just
+        * waste space in a production environment.
+        *
+        * The __tracepoint_str sections on the other hand are used by
+        * tracepoints which need to map pointers to their strings to
+        * the ASCII text for userspace.
+        */
+       last_index = start_index;
+       start_index = __stop___tracepoint_str - __start___tracepoint_str;
+
+       if (*pos < last_index + start_index)
+               return __start___tracepoint_str + (*pos - last_index);
+
        return find_next_mod_format(start_index, v, fmt, pos);
 }
 
@@ -272,6 +296,9 @@ static int t_show(struct seq_file *m, void *v)
        const char *str = *fmt;
        int i;
 
+       if (!*fmt)
+               return 0;
+
        seq_printf(m, "0x%lx : \"", *(unsigned long *)fmt);
 
        /*