[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240122111306.4e0a29ab@gandalf.local.home>
Date: Mon, 22 Jan 2024 11:13:06 -0500
From: Steven Rostedt <rostedt@...dmis.org>
To: Ye Bin <yebin10@...wei.com>
Cc: <mhiramat@...nel.org>, <mathieu.desnoyers@...icios.com>,
<linux-trace-kernel@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 4/7] tracing/probes: support '%pD' type for print
struct file's name
On Mon, 22 Jan 2024 15:40:12 +0800
Ye Bin <yebin10@...wei.com> wrote:
> Similar to '%pD' for printk, use '%pD' for print struct file's name.
>
> Signed-off-by: Ye Bin <yebin10@...wei.com>
> ---
> kernel/trace/trace_probe.c | 41 ++++++++++++++++++++++++--------------
> 1 file changed, 26 insertions(+), 15 deletions(-)
>
> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> index 1599c0c3e6b7..f9819625de58 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
> @@ -12,6 +12,7 @@
> #define pr_fmt(fmt) "trace_probe: " fmt
>
> #include <linux/bpf.h>
> +#include <linux/fs.h>
> #include "trace_btf.h"
>
> #include "trace_probe.h"
> @@ -1572,28 +1573,38 @@ int traceprobe_expand_dentry_args(int argc, const char *argv[], char *buf,
>
> used = 0;
> for (i = 0; i < argc; i++) {
> - if (str_has_suffix(argv[i], ":%pd")) {
> - char *tmp = kstrdup(argv[i], GFP_KERNEL);
> - char *equal;
> + if (!str_has_suffix(argv[i], ":%pd") &&
> + !str_has_suffix(argv[i], ":%pD"))
> + continue;
And here too:
if (!str_has_suffix(argv[i], ":%pd", &idx) &&
!str_has_suffix(argv[i], ":%pD", &idx))
continue;
>
> - if (!tmp)
> - return -ENOMEM;
> + char *tmp = kstrdup(argv[i], GFP_KERNEL);
> + char *equal;
> +
> + if (!tmp)
> + return -ENOMEM;
>
> - equal = strchr(tmp, '=');
> - if (equal)
> - *equal = '\0';
> - tmp[strlen(argv[i]) - 4] = '\0';
> + equal = strchr(tmp, '=');
> + if (equal)
> + *equal = '\0';
> + tmp[strlen(argv[i]) - 4] = '\0';
tmp[idx] = '\0';
> + if (argv[i][strlen(argv[i]) - 1] == 'd')
To avoid another strlen() call.
if (tmp[idx + 3] == 'd')
-- Steve
> ret = snprintf(buf + used, bufsize - used,
> "%s%s+0x0(+0x%zx(%s)):string",
> equal ? tmp : "", equal ? "=" : "",
> offsetof(struct dentry, d_name.name),
> equal ? equal + 1 : tmp);
> - kfree(tmp);
> - if (ret >= bufsize - used)
> - return -ENOMEM;
> - argv[i] = buf + used;
> - used += ret + 1;
> - }
> + else
> + ret = snprintf(buf + used, bufsize - used,
> + "%s%s+0x0(+0x%zx(+0x%zx(%s))):string",
> + equal ? tmp : "", equal ? "=" : "",
> + offsetof(struct dentry, d_name.name),
> + offsetof(struct file, f_path.dentry),
> + equal ? equal + 1 : tmp);
> + kfree(tmp);
> + if (ret >= bufsize - used)
> + return -ENOMEM;
> + argv[i] = buf + used;
> + used += ret + 1;
> }
>
> return 0;
Powered by blists - more mailing lists