]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: sync: atomic: Implement Debug for Atomic<Debug>
authorBoqun Feng <boqun.feng@gmail.com>
Wed, 22 Oct 2025 03:53:23 +0000 (23:53 -0400)
committerBoqun Feng <boqun.feng@gmail.com>
Wed, 12 Nov 2025 16:56:41 +0000 (08:56 -0800)
If `Atomic<T>` is `Debug` then it's a `debugfs::Writer`, therefore make
it so since 1) debugfs needs to support `Atomic<T>` and 2) it's rather
trivial to implement `Debug` for `Atomic<Debug>`.

Tested-by: David Gow <davidgow@google.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://patch.msgid.link/20251022035324.70785-3-boqun.feng@gmail.com
rust/kernel/sync/atomic.rs

index 0bc6e7b04d673532c3f63c00e1979196818c35dc..3afc376be42d9ff5d54dd4d2125f98eb4dd1e098 100644 (file)
@@ -307,6 +307,15 @@ where
     }
 }
 
+impl<T: AtomicType + core::fmt::Debug> core::fmt::Debug for Atomic<T>
+where
+    T::Repr: AtomicBasicOps,
+{
+    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        core::fmt::Debug::fmt(&self.load(Relaxed), f)
+    }
+}
+
 impl<T: AtomicType> Atomic<T>
 where
     T::Repr: AtomicExchangeOps,