Index: uspace/lib/c/generic/thread/fibril_synch.c
===================================================================
--- uspace/lib/c/generic/thread/fibril_synch.c	(revision 64c81329526384b209fb44070678037573c63325)
+++ uspace/lib/c/generic/thread/fibril_synch.c	(revision b8fd95183b5971cb8bae8b942ea28859f28c40fb)
@@ -1,3 +1,4 @@
 /*
+ * Copyright (c) 2025 Jiri Svoboda
  * Copyright (c) 2009 Jakub Jermar
  * All rights reserved.
@@ -112,9 +113,12 @@
 #define AWAITER_INIT { .fid = fibril_get_id() }
 
-static void print_deadlock(fibril_owner_info_t *oi)
+/** Print deadlock message nad blocking chain.
+ *
+ * @param oi Owner info for the resource being acquired
+ * @param f Fibril that is trying to acquire the resource
+ */
+static void print_deadlock(fibril_owner_info_t *oi, fibril_t *f)
 {
 	// FIXME: Print to stderr.
-
-	fibril_t *f = (fibril_t *) fibril_get_id();
 
 	if (deadlocked) {
@@ -143,12 +147,21 @@
 }
 
-static void check_fibril_for_deadlock(fibril_owner_info_t *oi, fibril_t *fib)
-{
+/** Check whether fibril trying to acquire a resource will cause deadlock.
+ *
+ * @param wanted_oi Owner info for the primitive that the fibril wants
+ * @param fib Fibril that wants to aquire the primitive
+ */
+static void check_fibril_for_deadlock(fibril_owner_info_t *wanted_oi,
+    fibril_t *fib)
+{
+	fibril_owner_info_t *oi;
+
 	futex_assert_is_locked(&fibril_synch_futex);
 
+	oi = wanted_oi;
 	while (oi && oi->owned_by) {
 		if (oi->owned_by == fib) {
 			futex_unlock(&fibril_synch_futex);
-			print_deadlock(oi);
+			print_deadlock(wanted_oi, fib);
 			abort();
 		}
@@ -157,4 +170,8 @@
 }
 
+/** Check whether trying to acquire a resource will cause deadlock.
+ *
+ * @param oi Owner info for the primitive that the current fibril wants
+ */
 static void check_for_deadlock(fibril_owner_info_t *oi)
 {
