[Concept,01/10] x86: atomic: Add atomic_dec_and_test()

Message ID 20260418004014.1889749-2-sjg@u-boot.org
State New
Headers
Series efi-x86: boot Ubuntu live ISOs via U-Boot + BLS |

Commit Message

Simon Glass April 18, 2026, 12:39 a.m. UTC
  From: Simon Glass <sjg@chromium.org>

The Linux fs.h port for ext4l and isofs uses atomic_dec_and_test() on
buffer_head reference counts. The x86 asm/atomic.h provides atomic_dec()
but lacks the dec-and-test variant, so any file that includes linux/fs.h
on x86 fails to build once that code path is reached.

Add the standard "LOCK decl + sete" implementation, mirroring the Linux
kernel x86 atomic primitives, so the per-arch x86 atomic header is
complete enough to back linux/fs.h without needing the asm-generic
fallback.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/x86/include/asm/atomic.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
  

Patch

diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
index 14f811fc367..addbece6c3e 100644
--- a/arch/x86/include/asm/atomic.h
+++ b/arch/x86/include/asm/atomic.h
@@ -90,6 +90,23 @@  static inline void atomic_dec(atomic_t *v)
 		     : "+m" (v->counter));
 }
 
+/**
+ * atomic_dec_and_test - decrement and test
+ * @v: pointer of type atomic_t
+ *
+ * Atomically decrements @v by 1 and returns true if the result is 0,
+ * or false for all other cases.
+ */
+static inline int atomic_dec_and_test(atomic_t *v)
+{
+	unsigned char c;
+
+	asm volatile(LOCK_PREFIX "decl %0; sete %1"
+		     : "+m" (v->counter), "=qm" (c)
+		     : : "memory");
+	return c != 0;
+}
+
 /**
  * atomic_inc_short - increment of a short integer
  * @v: pointer to type int