History

tracing: Replace BUG_ON with lockdep_assert_held in uprobe_buffer functions

Replace BUG_ON(!mutex_is_locked(&event_mutex)) with lockdep_assert_held(&event_mutex) in uprobe_buffer_enable() and uprobe_buffer_disable(). BUG_ON() will crash the kernel. mutex_is_locked() only checks if any task holds lock,but not the caller task. lockdep_assert_held() also check current task for lock and no crash on true condition. Link: https://lore.kernel.org/all/20260521192846.8306-1-yashsuthar983@gmail.com/

Yash Suthar committed 5 months ago

Commit 585abc01 parent cf24cbb1 file · +2 −2Browse files

Showing the changes to kernel/trace (1 of 1 file). Show all

Unified · Split

kernel/trace/trace_uprobe.c+2−2
@@ -912,7 +912,7 @@ static int uprobe_buffer_enable(void) · 911 unmodified lines
912912 {
913913 int ret = 0;
914914
915− BUG_ON(!mutex_is_locked(&event_mutex));
915+ lockdep_assert_held(&event_mutex);
916916
917917 if (uprobe_buffer_refcnt++ == 0) {
918918 ret = uprobe_buffer_init();
@@ -927,7 +927,7 @@ static void uprobe_buffer_disable(void) · 8 unmodified lines
927927 {
928928 int cpu;
929929
930− BUG_ON(!mutex_is_locked(&event_mutex));
930+ lockdep_assert_held(&event_mutex);
931931
932932 if (--uprobe_buffer_refcnt == 0) {
933933 for_each_possible_cpu(cpu)