From: Gabriele Monaco <gmonaco@redhat.com>
To: Nam Cao <namcao@linutronix.de>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-trace-kernel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] rv: Fix wrong type cast in monitors_show()
Date: Mon, 28 Jul 2025 10:59:01 +0200 [thread overview]
Message-ID: <786688d8a5ab0d5228d271861416d49cc3a8ebc3.camel@redhat.com> (raw)
In-Reply-To: <35e49e97696007919ceacf73796487a2e15a3d02.1753625621.git.namcao@linutronix.de>
On Sun, 2025-07-27 at 19:31 +0200, Nam Cao wrote:
> Argument 'p' of monitors_show() is not a pointer to struct
> rv_monitor, it is actually a pointer to the list_head inside struct
> rv_monitor. Therefore it is wrong to cast 'p' to struct rv_monitor *.
>
> This wrong type cast has been there since the beginning. But it still
> worked because the list_head was the first field in struct
> rv_monitor_def. This is no longer true since commit 24cbfe18d55a
> ("rv: Merge struct rv_monitor_def into struct rv_monitor") moved the
> list_head, and this wrong type cast became a functional problem.
>
> Properly use container_of() instead.
>
> Fixes: 24cbfe18d55a ("rv: Merge struct rv_monitor_def into struct
> rv_monitor")
> Signed-off-by: Nam Cao <namcao@linutronix.de>
> ---
> kernel/trace/rv/rv.c | 2 +-
>
> @@ -458,7 +458,7 @@ static int create_monitor_dir(struct rv_monitor
> *mon, struct rv_monitor *parent)
> */
> static int monitors_show(struct seq_file *m, void *p)
> {
> - struct rv_monitor *mon = p;
> + struct rv_monitor *mon = container_of(p, struct rv_monitor,
> list);
>
Good catch, thanks! The container_of is the way to go.
Do you have valid reasons not to move the list_head to the top? It's
not a big deal but it would save computing and summing the offset. It
doesn't seem name (the current first element) really needs to stay
there.
Thanks,
Gabriele
> if (mon->parent)
> seq_printf(m, "%s:%s\n", mon->parent->name, mon-
> >name);
next prev parent reply other threads:[~2025-07-28 8:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-27 17:31 [PATCH 0/2] rv: Fix wrong type cast Nam Cao
2025-07-27 17:31 ` [PATCH 1/2] rv: Fix wrong type cast in monitors_show() Nam Cao
2025-07-28 8:59 ` Gabriele Monaco [this message]
2025-07-28 9:36 ` Nam Cao
2025-07-28 11:07 ` Gabriele Monaco
2025-07-27 17:31 ` [PATCH 2/2] rv: Fix wrong type cast in reactors_show() and monitor_reactor_show() Nam Cao
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=786688d8a5ab0d5228d271861416d49cc3a8ebc3.camel@redhat.com \
--to=gmonaco@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=namcao@linutronix.de \
--cc=rostedt@goodmis.org \
/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