Re: [PATCH] rv: Fix wrong type cast in enabled_monitors_next()
From: Gabriele Monaco <gmonaco@redhat.com>
Date: 2025-08-06 12:45:28
Also in:
lkml
On Wed, 2025-08-06 at 14:09 +0200, Nam Cao wrote:
Argument 'p' of enabled_monitors_next() 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.Good catch, thanks! Reviewed-by: Gabriele Monaco <gmonaco@redhat.com>
quoted hunk ↗ jump to hunk
Fixes: 24cbfe18d55a ("rv: Merge struct rv_monitor_def into struct rv_monitor") Signed-off-by: Nam Cao <redacted> --- kernel/trace/rv/rv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)diff --git a/kernel/trace/rv/rv.c b/kernel/trace/rv/rv.c index bd7d56dbf6c2..6ce3495164d8 100644 --- a/kernel/trace/rv/rv.c +++ b/kernel/trace/rv/rv.c@@ -495,7 +495,7 @@ static void *available_monitors_next(structseq_file *m, void *p, loff_t *pos) */ static void *enabled_monitors_next(struct seq_file *m, void *p, loff_t *pos) { - struct rv_monitor *mon = p; + struct rv_monitor *mon = container_of(p, struct rv_monitor, list); (*pos)++;