From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23F9CC982D9 for ; Thu, 17 Sep 2026 16:38:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qyA8y1X/jw4Lf+OkE2z5XXcJcUYbjLIXey1Kmgo/ZSo=; b=xJOE6XUna6oYrG 8j+Q4L/1tcncKkZTkg9whCjJbbo/fZzpRWJFXDrgP8Ki+a7cdjFoi/ZFiam/eYH92hDTiv82J7/td NravmlwTU3WAnbFV3IukJXq59me1FcoPKKh3v5vutFDxE9JHwEhJ4ck3Bl9XgrD491XqNOC8ANfsJ 9ZjjZ3vhayscgPzDAESUUTeURU3ZOgWqDouvTvIhaqC6to2xptrvJROeuV7BGBhAljIqcE6pvqENi iS+Mh/wYY+ulJltiKDbecV3CoCpsNom9oCiJTyd4m6atGrIWr1a9l6pAns4ZZcs6xgqJ7XlvRyWzy eRAwrkMFWgzw+pgl24Hg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x7F8F-0000000Bwsm-3J13; Thu, 17 Sep 2026 16:38:43 +0000 Received: from mail.mainlining.org ([5.75.144.95]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x7F8B-0000000Bwnp-3psG for linux-snps-arc@lists.infradead.org; Thu, 17 Sep 2026 16:38:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; s=202507r; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1789663111; bh=ghYvDCJ6wWgl/DWKvRlZLjc r4JmsCO6Diem7VtlYvoo=; b=fyB1YvSKvGg1LWKCQZhUBc492tVVzKUf+KZBnI5LNuvCJ5g+ZU E6bkZfZWBE+ZQIYJNva6H1UqybZAs2u6MSsWz7m3aJKEZMUommjJq2vgXFTYVszJusLk7IevwrV 3uAVll3tWQSPCu8psXyYvDa346sjiFeMpOTxP5FVJ2OXn8ivF7Ar9zMblkFo0Sc1qIgzQTEoMnz eECEFt8PMgT7hUncGGx7FjraHbNbzdqgoitO2DlTK+xF0xBeNMnkBZrDOGfDZLxGj/YwQIn8g2u k6hg6hp3BRJs3diJxFQC1cKrT8U/XjrLCX9avh/i1pVEwYhevJmc5z5MoF9+JtxIuPA==; DKIM-Signature: v=1; a=ed25519-sha256; s=202507e; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1789663111; bh=ghYvDCJ6wWgl/DWKvRlZLjc r4JmsCO6Diem7VtlYvoo=; b=aqA1APFosR9li9xYj4aOMoBwNnHa27+/AJWqeXDYbSCs4I8uW1 aFOhtFdK/xx/jVETv72FWV94mClzvdy8f5Bg==; From: Bradley Morgan To: Andrew Morton , Vineet Gupta , Guo Ren , Yoshinori Sato , Rich Felker , Chris Zankel , Max Filippov Cc: Arnd Bergmann , "Paul E . McKenney" , David Laight , John Paul Adrian Glaubitz , linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Bradley Morgan Subject: [PATCH v3 4/5] sh: Emulate two-byte cmpxchg Date: Thu, 17 Sep 2026 16:38:29 +0000 Message-ID: <20260917163830.3748-5-brads@mainlining.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260917163830.3748-1-brads@mainlining.org> References: <20260917163830.3748-1-brads@mainlining.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260917_093840_116897_B85C6AA6 X-CRM114-Status: GOOD ( 10.69 ) X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+linux-snps-arc=archiver.kernel.org@lists.infradead.org SH has no byte or halfword atomic memory operations, so the __cmpxchg() switch routes case 1 through cmpxchg_emu_u8() and lets case 2 fall through to __cmpxchg_called_with_bad_pointer(), which is declared but never defined, so a two-byte cmpxchg() fails at link time. Route case 2 through the new cmpxchg_emu_u16(), which takes the old and new values as unsigned long, so the (unsigned long) casts move off the call and into _old_ and _new_ declarations that type check the old and new arguments against *ptr through (unsigned long)(0 ? *ptr : _o_), the idiom David Laight suggested, so cmpxchg(&p, 4, 5) no longer compiles silently. Acked-by: John Paul Adrian Glaubitz Signed-off-by: Bradley Morgan --- arch/sh/include/asm/cmpxchg.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/sh/include/asm/cmpxchg.h b/arch/sh/include/asm/cmpxchg.h index 1e5dc5ccf7bf..b87f59107b4e 100644 --- a/arch/sh/include/asm/cmpxchg.h +++ b/arch/sh/include/asm/cmpxchg.h @@ -59,6 +59,8 @@ static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old, switch (size) { case 1: return cmpxchg_emu_u8(ptr, old, new); + case 2: + return cmpxchg_emu_u16(ptr, old, new); case 4: return __cmpxchg_u32(ptr, old, new); } @@ -70,8 +72,10 @@ static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old, ({ \ __typeof__(*(ptr)) _o_ = (o); \ __typeof__(*(ptr)) _n_ = (n); \ - (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \ - (unsigned long)_n_, sizeof(*(ptr))); \ + unsigned long _old_ = (unsigned long)(0 ? *ptr : _o_); \ + unsigned long _new_ = (unsigned long)(0 ? *ptr : _n_); \ + (__typeof__(*(ptr))) __cmpxchg((ptr), _old_, \ + _new_, sizeof(*(ptr))); \ }) #include -- 2.47.3 _______________________________________________ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc