Skip to contentSkip to conversation

Fix missing mutex unlock in rv_register_monitor()

PATCH In review Zhen Ni 3 participants 4 messages Sep 3, 2025 – Sep 4, 2025

Subsystems (2)
lore
Share & tools
lore

Zhen Ni

author
#0 lore raw

PATCH 1/1 Fix missing mutex unlock in rv_register_monitor()

If create_monitor_dir() fails, the function returns directly without releasing rv_interface_lock. This leaves the mutex locked and causes subsequent monitor registration attempts to deadlock.

Fix it by making the error path jump to out_unlock, ensuring that the mutex is always released before returning.

Fixes 24cbfe18d55a ("rv: Merge struct rv_monitor_def into struct rv_monitor")
---
 kernel/trace/rv/rv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/rv/rv.c +1 -1
index 1482e91c39f4..e35565dd2dc5 100644
@@ -805,7 +805,7 @@ int rv_register_monitor(struct rv_monitor *monitor, struct rv_monitor *parent)
 
 	retval = create_monitor_dir(monitor, parent);
 	if (retval)
-		return retval;
+		goto out_unlock;
 
 	/* keep children close to the parent for easier visualisation */
 	if (parent)
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Zhen Ni

If create_monitor_dir() fails, the function returns directly without releasing rv_interface_lock. This leaves the mutex locked and causes subsequent monitor registration attempts to deadlock.

Fix it by making the error path jump to out_unlock, ensuring that the mutex is always released before returning.

Fixes 24cbfe18d55a ("rv: Merge struct rv_monitor_def into struct

rv_monitor")

Good catch, thank you!

I would also add a:

Fixes 24cbfe18d55a ("rv: Merge struct rv_monitor_def into struct rv_monitor")

(Adding Nam to the loop, as author of that patch)

Thanks,
Gabriele

Quoted 19 lines

---
 kernel/trace/rv/rv.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/rv/rv.c +0 -0
index 1482e91c39f4..e35565dd2dc5 100644
@@ -805,7 +805,7 @@ int rv_register_monitor(struct rv_monitor
 *monitor, struct rv_monitor *parent)


  retval = create_monitor_dir(monitor, parent); if (retval)

kernel/trace/rv/rv.c +1 -1
-		return retval;
+		goto out_unlock;


  /* keep children close to the parent for easier visualisation */
  if (parent)

Reviewed-by
#2 lore raw
Quoted 12 lines · Gabriele Monaco
Quoted 10 lines · Zhen Ni

If create_monitor_dir() fails, the function returns directly without releasing rv_interface_lock. This leaves the mutex locked and causes subsequent monitor registration attempts to deadlock.

Fix it by making the error path jump to out_unlock, ensuring that the mutex is always released before returning.

Fixes 24cbfe18d55a ("rv: Merge struct rv_monitor_def into struct

rv_monitor")

Quoted 7 lines

Good catch, thank you!

I would also add a:

Fixes 24cbfe18d55a ("rv: Merge struct rv_monitor_def into struct rv_monitor")

Am I hallucinating, or the fix tag is already there?

Quoted 1 line

(Adding Nam to the loop, as author of that patch)

Thanks for CC!

I have been debating whether we should convert rv to use lock guard. Problem like this one is a good advocate.

Nam

maintainer
#3 lore raw
Quoted 1 line · Nam Cao

Am I hallucinating, or the fix tag is already there?

I should stop doing 3 things at the same time, my bad :')

Quoted 9 lines
Quoted 2 lines

(Adding Nam to the loop, as author of that patch)

Thanks for CC!

I have been debating whether we should convert rv to use lock guard. Problem like this one is a good advocate.

I'm totally in favour, next cleanup series let's say.

Thanks,
Gabriele