From patchwork Wed Jan 14 22:55:53 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1497 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=1768431427; bh=1nQrLHCWLEpkl+WACuROEC8/ssEny65izan6gNkURWI=; 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=Yv0ciR5KjdgugHqh1J/aN1LUBpch3xYoHZSkZNHbQQ2hjIrWg/538bKBVz5iiDaXd 73Nv4dRxCSGMy1mq/qYtoFQ5+UP3Wjr1oHMiliNKVK2QCYfAVFmm6lmgUPaGUvVjaZ OlgubnE+N+YsjdzSu+7ITx0CMuQpb7FJhkuKH+0/xH/NJFygyuPvZsOruvqQv8PrUy C2tWNxzZLw6nRS8uuDbyK+sVfUJmBVa+Ptl4ByuWfv9genAlVhbuiC51otbaT4PDex z7yeRYYNK6Y37LyIMkO0Bm4Av7qLxgo4n5YqzuFJYFqvxD9ZwoNdz4fZ371dNXuDIe BK7uHIlN1ca2g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 54600692F1 for ; Wed, 14 Jan 2026 15:57:07 -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 chhz0dEDglbE for ; Wed, 14 Jan 2026 15:57:07 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768431427; bh=1nQrLHCWLEpkl+WACuROEC8/ssEny65izan6gNkURWI=; 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=Yv0ciR5KjdgugHqh1J/aN1LUBpch3xYoHZSkZNHbQQ2hjIrWg/538bKBVz5iiDaXd 73Nv4dRxCSGMy1mq/qYtoFQ5+UP3Wjr1oHMiliNKVK2QCYfAVFmm6lmgUPaGUvVjaZ OlgubnE+N+YsjdzSu+7ITx0CMuQpb7FJhkuKH+0/xH/NJFygyuPvZsOruvqQv8PrUy C2tWNxzZLw6nRS8uuDbyK+sVfUJmBVa+Ptl4ByuWfv9genAlVhbuiC51otbaT4PDex z7yeRYYNK6Y37LyIMkO0Bm4Av7qLxgo4n5YqzuFJYFqvxD9ZwoNdz4fZ371dNXuDIe BK7uHIlN1ca2g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3CB1F6933C for ; Wed, 14 Jan 2026 15:57:07 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768431425; bh=YN74WQEhC2U5574+cufX89ZCa4d5vzTb+nYIVy6i9Hw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MohOUwAE2+deJakb2oxgwulnh63v6lmyL7BhYtEk+qTxcEVL9DVxdvaUHYVbV8v+O Ur/q1OPDh9srOqJRqgrCxsSRvy5+oDC4Eai4/jrULYLhPhCGqXar782lvDXlm/fjT7 PGWJy9+7yfNiUB9s7D3YGiFtFT8syJDACTOlj+R7gr/IzhGXfKEf+rD8E57J146wx5 HTZDGn9JbjEr2Ut8CG374UclM4jEVUmEiQo9RCuxd1bMZaGfFEjXr0WW2VY2349Wo/ CBBqEXAym5Q+R716g+Uh+xIzSwYDyZyj2JUMDHG9xKPHMCsgowLpGTpTO/woeYgKeU bO7Ot09TVxbow== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4E873692F1; Wed, 14 Jan 2026 15:57:05 -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 So5hH0lHml0r; Wed, 14 Jan 2026 15:57:05 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768431421; bh=ABL3oYtzAp3PjN2bcxpqPt5iF+n3JPL73MihKxgtJew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ub/jAdwS4nGrAX0dNGG0Oc7vvXAn8fpLUltslnfPbb98EKSpWKdNn7DaAd+xmB9xq Pe0ya7nsL6vHsY3nSDGtaglrrvZX7imed8NWMlj/NDKAv/aNfgv9B8oeiHzUuY2+aH jCrnXUKzKsoxu60HuxrNPl42C1rORseZW0rdfw29M6qCsa0k+EP/QiOs3w6Gel53bl tv69v9JigfY12LoBNhtVFlW7GsfXKH+0GK7qhwnnwTm4BjZDtZLi5YQHjOe7q6iohe rQJIcm6E6dhOAAQPq8ZN8ToBwHr4Uc2hifoprT5xUWxKbBHYH1tEmppxEUP7Zc1uaA yVb3J4l/lykYw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id E9704692EF; Wed, 14 Jan 2026 15:57:00 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 14 Jan 2026 15:55:53 -0700 Message-ID: <20260114225635.3407989-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114225635.3407989-1-sjg@u-boot.org> References: <20260114225635.3407989-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: GI25SFKKAOYBOHALHKJOF76V72LTK43F X-Message-ID-Hash: GI25SFKKAOYBOHALHKJOF76V72LTK43F 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 03/34] ext4l: Move atomic operations to asm-generic/atomic.h 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 atomic operations from ext4_uboot.h to asm-generic/atomic.h where they logically belong. This includes: - atomic_inc_return() - atomic_add_return() - atomic_dec_if_positive() - atomic_add_unless() Remove duplicate definitions from ext4_uboot.h that are now provided by asm-generic/atomic.h. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 30 ++++---------------- include/asm-generic/atomic.h | 53 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 24 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 68dca2f8d4e..f208889cbac 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -78,8 +78,7 @@ #include #include -/* Extra atomic operation not in asm-generic/atomic.h */ -#define atomic_dec_if_positive(v) (--(v)->counter) +/* atomic_dec_if_positive, atomic_add_unless, etc. are now in asm-generic/atomic.h */ /* SMP stubs - U-Boot is single-threaded */ #define raw_smp_processor_id() 0 @@ -433,8 +432,7 @@ int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode, /* spin_trylock is defined in linux/spinlock.h */ -/* Atomic extras */ -#define atomic_add_unless(v, a, u) ({ (void)(v); (void)(a); (void)(u); 1; }) +/* atomic_add_unless is now in asm-generic/atomic.h */ /* Block group lock - stub */ #define bgl_lock_ptr(lock, group) NULL @@ -2548,9 +2546,7 @@ static inline unsigned long ext4_find_next_bit_le(const void *addr, return size; } -/* Atomic64 operations */ -#define atomic64_inc(v) do { (void)(v); } while (0) -#define atomic64_add(i, v) do { (void)(i); (void)(v); } while (0) +/* atomic64 operations are now in asm-generic/atomic.h */ /* CPU cycle counter stub */ #define get_cycles() (0ULL) @@ -2592,17 +2588,7 @@ static inline unsigned long ext4_find_next_bit_le(const void *addr, /* array_index_nospec - bounds checking without speculation (no-op in U-Boot) */ #define array_index_nospec(index, size) (index) -/* atomic_inc_return - increment and return new value */ -static inline int atomic_inc_return(atomic_t *v) -{ - return ++(v->counter); -} - -/* atomic_add_return - add and return new value */ -static inline int atomic_add_return(int i, atomic_t *v) -{ - return (v->counter += i); -} +/* atomic_inc_return and atomic_add_return are now in asm-generic/atomic.h */ /* pde_data - proc dir entry data (not supported in U-Boot) */ #define pde_data(inode) ((void *)NULL) @@ -2640,10 +2626,7 @@ struct seq_operations { #define sb_issue_discard(sb, sector, nr_sects, gfp, flags) \ ({ (void)(sb); (void)(sector); (void)(nr_sects); (void)(gfp); (void)(flags); 0; }) -/* Atomic operations */ -#define atomic_sub(i, v) ((v)->counter -= (i)) -#define atomic64_sub(i, v) ((v)->counter -= (i)) -#define atomic_dec_and_test(v) (--((v)->counter) == 0) +/* atomic_sub, atomic64_sub, atomic_dec_and_test are in asm-generic/atomic.h */ /* RCU list operations - use regular list operations in U-Boot */ #define list_for_each_entry_rcu(pos, head, member, ...) \ @@ -2755,8 +2738,7 @@ struct folio_iter { /* blk_status_to_errno - convert block status to errno */ #define blk_status_to_errno(status) (-(status)) -/* atomic_inc - increment atomic */ -#define atomic_inc(v) ((v)->counter++) +/* atomic_inc is in asm-generic/atomic.h */ /* GFP_NOIO - allocation without I/O */ #define GFP_NOIO 0 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h index 94d0747194a..7825258922a 100644 --- a/include/asm-generic/atomic.h +++ b/include/asm-generic/atomic.h @@ -79,6 +79,59 @@ static inline int atomic_add_negative(int i, volatile atomic_t *v) return val < 0; } +static inline int atomic_inc_return(atomic_t *v) +{ + unsigned long flags = 0; + int val; + + local_irq_save(flags); + val = ++v->counter; + local_irq_restore(flags); + + return val; +} + +static inline int atomic_add_return(int i, atomic_t *v) +{ + unsigned long flags = 0; + int val; + + local_irq_save(flags); + val = (v->counter += i); + local_irq_restore(flags); + + return val; +} + +static inline int atomic_dec_if_positive(atomic_t *v) +{ + unsigned long flags = 0; + int val; + + local_irq_save(flags); + val = v->counter - 1; + if (val >= 0) + v->counter = val; + local_irq_restore(flags); + + return val; +} + +static inline int atomic_add_unless(atomic_t *v, int a, int u) +{ + unsigned long flags = 0; + int ret = 1; + + local_irq_save(flags); + if (v->counter != u) + v->counter += a; + else + ret = 0; + local_irq_restore(flags); + + return ret; +} + static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr) { unsigned long flags = 0;