From patchwork Sat Jan 17 01:14:32 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1570 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768612545; bh=eUVAwP85tnxzQ6cao+6NscgLNX+kJFYtZd2aibthw08=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=wPrNnAmP8pUxceeM1DWXhNbHvotIAfP3e1cFdGUJPDSmdMK3jUNpIbckhi7Y1FrDk H7jvxuSBCmfuhLVJzMeKew6mi4N2YXUov9cki0+FQAw0kIcSkzb4hH5jC/5u4uxwUc VEKNX9+e8f8nUcu1GBC/c5wpuqI7hm8OMSkVyGPM5YBAscxeLoQmDC1shnVGGSCfui SmF9rpcCYR2NRNE1ahqZJzUIJvuDZQFhFzhy8ziuMRbR8p1LsQsGZkepabQPrZIltA ti5DCXGWqGHryV7GfC+miaUarsOwfCT0BwMvjaP6YSGyYsGhcunu/hn+5dvm4b5aAx Q1PdkztQsRSHw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 27A8E69405 for ; Fri, 16 Jan 2026 18:15:45 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id YYd_wIplXbXb for ; Fri, 16 Jan 2026 18:15:45 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768612545; bh=eUVAwP85tnxzQ6cao+6NscgLNX+kJFYtZd2aibthw08=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=wPrNnAmP8pUxceeM1DWXhNbHvotIAfP3e1cFdGUJPDSmdMK3jUNpIbckhi7Y1FrDk H7jvxuSBCmfuhLVJzMeKew6mi4N2YXUov9cki0+FQAw0kIcSkzb4hH5jC/5u4uxwUc VEKNX9+e8f8nUcu1GBC/c5wpuqI7hm8OMSkVyGPM5YBAscxeLoQmDC1shnVGGSCfui SmF9rpcCYR2NRNE1ahqZJzUIJvuDZQFhFzhy8ziuMRbR8p1LsQsGZkepabQPrZIltA ti5DCXGWqGHryV7GfC+miaUarsOwfCT0BwMvjaP6YSGyYsGhcunu/hn+5dvm4b5aAx Q1PdkztQsRSHw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 16A68693F4 for ; Fri, 16 Jan 2026 18:15:45 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768612543; bh=xVg7A4esvToeTT1ULqDdwTYiWk+DsOKgHclGDUxhg3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r/VpqvJpnzTHdJYdOZxUzkTtpJdVVmvgUf7ieb/VUrgjtRdFxZgGrivZIq3fqJ1Os FyHU3YdcNURMaB7d0qRi08hUfMgWzSCcXBe23z40zn86H0Lc4jRq2UWMs79+SUBmkj 3D9zmvceEX6OWqnSutMO+vTssUYnPz3EUgKpXAyb0eE9FCdYZjG7CdjaaQyXx8lpvy xvrrNoLhmB1oeqihSX8G5KBodQjkKq9PAn2FbVrTz4wF0P+lbxIMH7M1vDt+Jk5/cM gso1PF6oaCLxBlys4rLzr8w+CEA0AU88tYtWaXHEx/mjoRBtqYJ/9qClJhbNKmDBHg oEzOoZf15WLjw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 972426913F; Fri, 16 Jan 2026 18:15:43 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id GpmIwQaCVGPt; Fri, 16 Jan 2026 18:15:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768612539; bh=s9jK4qMFS5gpgJWRAwfnYJHFAVBQunfjrmjCuZ/2RqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ErKKfaS+KMNCfkWhhd+RYglMrdE+YaKteJJ4+IH3Y6NuBe3/T8jd27LuwiM7mIST7 coRMBeecWIWJYV5q4ziCeJSUh080RZHQ4EdZHQPkVm3gHvv5AhJ6J8yvqrW7Ek+23x lsiF+ggoZq6PykQO77SkMjLoMLYhoHYU4LhXJQXv38BJIyOFurargeMleslnCL0C8v +FPu86M+aNPOeU3LfBeyU54Jj5s4UW3mwyF28MXRGn4han0ojm4s/WpndHgXTK92o5 ucwiotXl5gAZJNvh9woTx3Mo5WqY67Dy4900ald0TFVFeFxEPkyXgeGnlm2HPwSoaP 0Cqw+nEkpMx7Q== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 4D438693E0; Fri, 16 Jan 2026 18:15:39 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 18:14:32 -0700 Message-ID: <20260117011448.3007171-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260117011448.3007171-1-sjg@u-boot.org> References: <20260117011448.3007171-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: H27SFMCPOKCWM5CA33JY33KNR7QNFEEN X-Message-ID-Hash: H27SFMCPOKCWM5CA33JY33KNR7QNFEEN X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 10/19] asm-generic: atomic: Add cmpxchg() macro List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Move the cmpxchg (compare and exchange) macro to the asm-generic atomic header where it belongs alongside other atomic operations. This is a single-threaded implementation for U-Boot that atomically compares *ptr with old and if equal, stores new. Returns the original value of *ptr. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 10 +--------- include/asm-generic/atomic.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 3ce94750fcf..f26006f9291 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -94,15 +94,7 @@ /* SMP stubs - U-Boot is single-threaded */ #define raw_smp_processor_id() 0 -/* cmpxchg - compare and exchange, single-threaded version */ -#define cmpxchg(ptr, old, new) ({ \ - typeof(*(ptr)) __cmpxchg_old = (old); \ - typeof(*(ptr)) __cmpxchg_new = (new); \ - typeof(*(ptr)) __cmpxchg_ret = *(ptr); \ - if (__cmpxchg_ret == __cmpxchg_old) \ - *(ptr) = __cmpxchg_new; \ - __cmpxchg_ret; \ -}) +/* cmpxchg is now in asm-generic/atomic.h */ /* Reference count type */ typedef struct { atomic_t refs; } refcount_t; diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h index 7825258922a..3fa749bf012 100644 --- a/include/asm-generic/atomic.h +++ b/include/asm-generic/atomic.h @@ -200,4 +200,22 @@ static inline void atomic64_dec(volatile atomic64_t *v) local_irq_restore(flags); } +/** + * cmpxchg - compare and exchange + * @ptr: pointer to the value + * @old: expected old value + * @new: new value to store if current equals old + * + * Single-threaded version for U-Boot. Atomically compares *ptr with old + * and if equal, stores new. Returns the original value of *ptr. + */ +#define cmpxchg(ptr, old, new) ({ \ + typeof(*(ptr)) __cmpxchg_old = (old); \ + typeof(*(ptr)) __cmpxchg_new = (new); \ + typeof(*(ptr)) __cmpxchg_ret = *(ptr); \ + if (__cmpxchg_ret == __cmpxchg_old) \ + *(ptr) = __cmpxchg_new; \ + __cmpxchg_ret; \ +}) + #endif