{"id":2219439,"url":"http://patchwork.ozlabs.org/api/patches/2219439/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260403-cmpxchg-v2-1-23acd2727447@gmail.com/","project":{"id":2,"url":"http://patchwork.ozlabs.org/api/projects/2/?format=json","name":"Linux PPC development","link_name":"linuxppc-dev","list_id":"linuxppc-dev.lists.ozlabs.org","list_email":"linuxppc-dev@lists.ozlabs.org","web_url":"https://github.com/linuxppc/wiki/wiki","scm_url":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git","webscm_url":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/","list_archive_url":"https://lore.kernel.org/linuxppc-dev/","list_archive_url_format":"https://lore.kernel.org/linuxppc-dev/{}/","commit_url_format":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id={}"},"msgid":"<20260403-cmpxchg-v2-1-23acd2727447@gmail.com>","list_archive_url":"https://lore.kernel.org/linuxppc-dev/20260403-cmpxchg-v2-1-23acd2727447@gmail.com/","date":"2026-04-03T01:19:54","name":"[v2] cmpxchg: allow const-qualified old value in cmpxchg()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"7a6636db281bed803dcf3ae6c86affc93be617ed","submitter":{"id":15639,"url":"http://patchwork.ozlabs.org/api/people/15639/?format=json","name":"Hangbin Liu","email":"liuhangbin@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260403-cmpxchg-v2-1-23acd2727447@gmail.com/mbox/","series":[{"id":498574,"url":"http://patchwork.ozlabs.org/api/series/498574/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=498574","date":"2026-04-03T01:19:54","name":"[v2] cmpxchg: allow const-qualified old value in cmpxchg()","version":2,"mbox":"http://patchwork.ozlabs.org/series/498574/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2219439/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2219439/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linuxppc-dev+bounces-19257-incoming=patchwork.ozlabs.org@lists.ozlabs.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=T09NSeEN;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org\n (client-ip=2404:9400:21b9:f100::1; helo=lists.ozlabs.org;\n envelope-from=linuxppc-dev+bounces-19257-incoming=patchwork.ozlabs.org@lists.ozlabs.org;\n receiver=patchwork.ozlabs.org)","lists.ozlabs.org;\n arc=none smtp.remote-ip=\"2607:f8b0:4864:20::62e\"","lists.ozlabs.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","lists.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=T09NSeEN;\n\tdkim-atps=neutral","lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com\n (client-ip=2607:f8b0:4864:20::62e; helo=mail-pl1-x62e.google.com;\n envelope-from=liuhangbin@gmail.com; receiver=lists.ozlabs.org)"],"Received":["from lists.ozlabs.org (lists.ozlabs.org\n [IPv6:2404:9400:21b9:f100::1])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1 raw public key)\n server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fn1JZ2MGYz1yDH\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 03 Apr 2026 12:26:05 +1100 (AEDT)","from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4fn1JX6bCqz2yh4;\n\tFri, 03 Apr 2026 12:26:04 +1100 (AEDT)","from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com\n [IPv6:2607:f8b0:4864:20::62e])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 4fn1JW43Tcz2yVP\n\tfor <linuxppc-dev@lists.ozlabs.org>; Fri, 03 Apr 2026 12:26:03 +1100 (AEDT)","by mail-pl1-x62e.google.com with SMTP id\n d9443c01a7336-2b258576d8cso9421485ad.0\n        for <linuxppc-dev@lists.ozlabs.org>;\n Thu, 02 Apr 2026 18:26:03 -0700 (PDT)","from 1.0.0.127.in-addr.arpa ([209.132.188.88])\n        by smtp.gmail.com with ESMTPSA id\n d9443c01a7336-2b27472d688sm42536555ad.8.2026.04.02.18.25.45\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Thu, 02 Apr 2026 18:25:59 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1775179564;\n\tcv=none;\n b=lVrjT64JS/jcd9rHLY5nVH0WDyPPTzJFkU6IqJeU05HIBhw49kjHR9Z2HnwMjFvJSdV2JQAWu1X62z1LZfy6tNdV+w0ts5fiJKRcFxeTU0Il8zLEL2lypxIw6PDu2smIV57G67cwQCrchAuVEIrEEV2QHJHpVKnoONZDGTARDdbBQdKbxN9QocsqhKAutyNQW8YVbGhD1QjLAMiv++9n5lfIsTIcaDxtbb4Z1AsEb00nR5KIK2gSlRJO0iI0GZocdVrEHfAzYiYYwFjSkGrSPKETmFoTBBNSvHdKqqWrMqnqoUJO1DOTwJBdAb5+MRAM4D5qqDnDS7ab+c2PC5iGgw==","ARC-Message-Signature":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1775179564; c=relaxed/relaxed;\n\tbh=rY2ciLkg8RtFIf8Sumay9p4mc2pCLq551+da1KF5JtU=;\n\th=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc;\n b=nJi7JIrSYAkRXScxqQ4uiWBU5bV05bfO6mhl0pXw5uKr6Khqwqg72E8Occz4OpzLPG6wHwo/HuO8fFpHBeWX2KW5QehFVM1YqmWptRnLVfHchrxmv4E0aefeUADo0q/BEujAfJnRkCXJ3/O6YuEs9uRkrP0FvddbJjnpo+fgi6941bYUFFQ1ZL0c4rNcaDDc73j1pXQPgDPkEk6F8O81vQy1OgyAURISPv3+ZoHrDr0BosrytjCoANrpIgl2yyTR/Xtzsmi8A/JEzRc0aynuDr+aQBzgFHSSedPkTMQEzUCg1A3FdrIMbgXeXf3q0PvNYVVj2L/4xM3TKqYDh+lyHQ==","ARC-Authentication-Results":"i=1; lists.ozlabs.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com; dkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=T09NSeEN; dkim-atps=neutral;\n spf=pass (client-ip=2607:f8b0:4864:20::62e; helo=mail-pl1-x62e.google.com;\n envelope-from=liuhangbin@gmail.com;\n receiver=lists.ozlabs.org) smtp.mailfrom=gmail.com","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1775179561; x=1775784361;\n darn=lists.ozlabs.org;\n        h=cc:to:message-id:content-transfer-encoding:mime-version:subject\n         :date:from:from:to:cc:subject:date:message-id:reply-to;\n        bh=rY2ciLkg8RtFIf8Sumay9p4mc2pCLq551+da1KF5JtU=;\n        b=T09NSeENpJP4KYKbjBlxph5jSNALCaWJH7aIVffvqAIHBhcWEj/OLvtgi4ARpXq2Y5\n         pss5SdlkqrbNp3LhRROJY/gQ4IuaBepEhYDjox+53VJ41c1vnZo9nbssSdgM2sMRP0yp\n         iZAXsYOHzzfMNmbP/lKHy776yHeFqKwVUQ96pwNDJIhJ8IXu3kCG1ISi36vmcVSygt6M\n         AyCOr+D7NCM9CHQzQtUJ4kRZ8EGxjsSiF0al//ClRrSRC/7wmw9FdmQgmESR84lWHP00\n         88DfFw+w0bTDfQmb0U0zO6JSfSJ10vvAAPzGB62aK5ieIIRMqgRF2gAZcTOFogfpAaI1\n         fpWw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1775179561; x=1775784361;\n        h=cc:to:message-id:content-transfer-encoding:mime-version:subject\n         :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=rY2ciLkg8RtFIf8Sumay9p4mc2pCLq551+da1KF5JtU=;\n        b=RpUQI0XGVIEW6VK/Wtpc1I4U1Lk8qfwefJDAGlIPrPd4siDAWaVJIiUAAgOtZSUPF0\n         lxb0BkHoaPQJ/gGhy5bY4q+jcEo4bjDVPa7JGTWdSl3r3S3dFl5b5zLvF3g1MJaAEHQc\n         hJqI3kKhX3GcCzjmKDl1Z3yt/XbLneeQXOyBNaAPK854MAdgRMtXUxcT6CK8FTXaFZXB\n         TeD2IjICVRcjwrqBZKK24ppur0PF5wX719vCNooYSkcQq7m9s3T2BxQKPQkDCJQVHV7x\n         kRw+C5okdiyjSu1eyVCgtOu5EjaiaCkcrmJYpexzG0HuD5GBmUPl0YudlaEWr7yihdYb\n         72tA==","X-Forwarded-Encrypted":"i=1;\n AJvYcCU498V/rOJxrEFhX5hY8l2kJkjRAEhFkKapYxoDFLP0OS30SP3lBrsOV4X5l3q5Gl9nb8yHATKWMUYCG5s=@lists.ozlabs.org","X-Gm-Message-State":"AOJu0YwqWHatZ2L+Z0VPRZ1cbrauyOKRI/heveY5EoQFQOr9x3nDI1fM\n\tgnpXP9cIbf7xJFjhsh7Z41BLogkkI5mFTryXKoLrHWm/1a0HfiOOVeHb","X-Gm-Gg":"AeBDievqiUBP8Qk2q287PGxS+lkTApdbtQYeK8SelFSF/TrhDBwrmDMBY8qZk/bYBQi\n\tyhvHoHTfoxtSOl8GOgHLe3Y+iKFjrPXfv2fd2FwIkrZVuy2WbuX+2nvWoU7W67xLXQRKbprJD8P\n\tpuIMUUqdoK1kVwPzMvAyLCxG6ON6kpW7LP7S91oxsmkgPNzf2rAdOClkXjbOL5R8quaX9AoWth4\n\tk+6G98LOtJFQPT6UJiL+V2nhJrrXyo3gIFPELu/PVW8gv4OPTUuHrhi0NKi8HopEO9hPFh3i0gU\n\tun91iieEP5HkTGNsaZ2Xn2f8alhb+I7H2bYGAqN1QInkrrv/Q9qr5K9giI1xLaVMf6LpkHm+7My\n\tOQXyJ8QNHwkH31xfOrau6+cSU4/CyIpfTL2/1ssi8/KDpbViVGxi5HKKo24UN6gI4Gh4u12GXSS\n\tZBURKSyNXYpBSippYTvRXSRAGLQtu4sm9nNevOhJrL2SqXrC/M","X-Received":"by 2002:a17:902:ea0b:b0:2b2:5da8:14be with SMTP id\n d9443c01a7336-2b28190a213mr12256705ad.41.1775179561300;\n        Thu, 02 Apr 2026 18:26:01 -0700 (PDT)","From":"Hangbin Liu <liuhangbin@gmail.com>","Date":"Fri, 03 Apr 2026 09:19:54 +0800","Subject":"[PATCH v2] cmpxchg: allow const-qualified old value in cmpxchg()","X-Mailing-List":"linuxppc-dev@lists.ozlabs.org","List-Id":"<linuxppc-dev.lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev+help@lists.ozlabs.org>","List-Owner":"<mailto:linuxppc-dev+owner@lists.ozlabs.org>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Archive":"<https://lore.kernel.org/linuxppc-dev/>,\n  <https://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Subscribe":"<mailto:linuxppc-dev+subscribe@lists.ozlabs.org>,\n  <mailto:linuxppc-dev+subscribe-digest@lists.ozlabs.org>,\n  <mailto:linuxppc-dev+subscribe-nomail@lists.ozlabs.org>","List-Unsubscribe":"<mailto:linuxppc-dev+unsubscribe@lists.ozlabs.org>","Precedence":"list","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","Message-Id":"<20260403-cmpxchg-v2-1-23acd2727447@gmail.com>","X-B4-Tracking":"v=1; b=H4sIAAAAAAAC/2XMSwrDIBSF4a2EO65Fb00KHXUfJQPxeaHGoEFSg\n nuvzbTD/3D4Dig2ky3wGA7ItlKhtPTAywA6qMVbRqY3IMeJS45Mx3XXwTN05sbvTkolBfT3mq2\n j/ZRec+9AZUv5c8JV/NZ/owommBwnYVHz0aB++qjofdUpwtxa+wIngfApngAAAA==","X-Change-ID":"20260402-cmpxchg-2fd307f44a41","To":"Richard Henderson <richard.henderson@linaro.org>,\n Matt Turner <mattst88@gmail.com>, Magnus Lindholm <linmag7@gmail.com>,\n Vineet Gupta <vgupta@kernel.org>, Brian Cain <bcain@kernel.org>,\n \"James E.J. Bottomley\" <James.Bottomley@HansenPartnership.com>,\n Helge Deller <deller@gmx.de>, Madhavan Srinivasan <maddy@linux.ibm.com>,\n Michael Ellerman <mpe@ellerman.id.au>, Nicholas Piggin <npiggin@gmail.com>,\n \"Christophe Leroy (CS GROUP)\" <chleroy@kernel.org>,\n Paul Walmsley <pjw@kernel.org>, Palmer Dabbelt <palmer@dabbelt.com>,\n Albert Ou <aou@eecs.berkeley.edu>, Alexandre Ghiti <alex@ghiti.fr>,\n Yoshinori Sato <ysato@users.sourceforge.jp>, Rich Felker <dalias@libc.org>,\n John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,\n \"David S. Miller\" <davem@davemloft.net>,\n Andreas Larsson <andreas@gaisler.com>, Thomas Gleixner <tglx@kernel.org>,\n Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,\n Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org,\n \"H. Peter Anvin\" <hpa@zytor.com>, Chris Zankel <chris@zankel.net>,\n Max Filippov <jcmvbkbc@gmail.com>,\n David Laight <david.laight.linux@gmail.com>","Cc":"linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org,\n linux-snps-arc@lists.infradead.org, linux-hexagon@vger.kernel.org,\n linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,\n linux-riscv@lists.infradead.org, linux-sh@vger.kernel.org,\n sparclinux@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,\n Hangbin Liu <liuhangbin@gmail.com>","X-Mailer":"b4 0.14.3","X-Spam-Status":"No, score=-0.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID,\n\tDKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,\n\tSPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.1 OzLabs 8","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on lists.ozlabs.org"},"content":"The old value passed to cmpxchg() is semantically read-only: it is\nonly loaded into a register as a comparand and is never written back.\nHowever, the macro currently assigns it implicitly to a local variable\nof type __typeof__(*(ptr)), which triggers -Werror=discarded-qualifiers\nwhen old is a const-qualified pointer and ptr points to a non-const type.\n\nFix this by using __auto_type with the conditional expression trick:\n\n  __auto_type _o_ = 1 ? (o) : *(ptr);\n\nThe __auto_type deduces the type from the expression, so _o_ naturally\ntakes the const-qualified type when o is const-qualified, avoiding the\ndiscarded-qualifiers warning. The conditional expression forces the\ncompiler to verify that o and *(ptr) have compatible types, preserving\nthe type-safety check that a bare __auto_type _o_ = (o) would lose.\nSince the condition is the constant 1, the compiler optimizes away the\n*(ptr) branch entirely with no runtime cost.\n\nFor macros where ptr is already captured in a local variable (arc's\n_p_, hexagon's __ptr, riscv's __ptr), the captured variable is used\nin the conditional expression to avoid re-evaluating ptr.\n\nThe new value is intentionally left without this treatment: new will\nbe stored into *ptr, so silently accepting a const-qualified new would\nallow callers to store a pointer-to-const into a non-const location\nwithout any compiler warning.\n\nSuggested-by: Jakub Kicinski <kuba@kernel.org>\nSigned-off-by: Hangbin Liu <liuhangbin@gmail.com>\n---\nChanges in v2:\n- Use __auto_type as the previous way will loose ptr type checking (David Laight)\n- Link to v1: https://lore.kernel.org/r/20260402-cmpxchg-v1-1-4561e2c05d2c@gmail.com\n---\n arch/alpha/include/asm/cmpxchg.h     | 4 ++--\n arch/arc/include/asm/cmpxchg.h       | 4 ++--\n arch/hexagon/include/asm/cmpxchg.h   | 2 +-\n arch/parisc/include/asm/cmpxchg.h    | 2 +-\n arch/powerpc/include/asm/cmpxchg.h   | 8 ++++----\n arch/riscv/include/asm/cmpxchg.h     | 4 ++--\n arch/sh/include/asm/cmpxchg.h        | 2 +-\n arch/sparc/include/asm/cmpxchg_32.h  | 2 +-\n arch/sparc/include/asm/cmpxchg_64.h  | 2 +-\n arch/x86/include/asm/cmpxchg.h       | 2 +-\n arch/xtensa/include/asm/cmpxchg.h    | 2 +-\n tools/arch/x86/include/asm/cmpxchg.h | 2 +-\n 12 files changed, 18 insertions(+), 18 deletions(-)\n\n\n---\nbase-commit: f8f5627a8aeab15183eef8930bf75ba88a51622f\nchange-id: 20260402-cmpxchg-2fd307f44a41\n\nBest regards,","diff":"diff --git a/arch/alpha/include/asm/cmpxchg.h b/arch/alpha/include/asm/cmpxchg.h\nindex ae1b96479d0c..e6cb60ca35bf 100644\n--- a/arch/alpha/include/asm/cmpxchg.h\n+++ b/arch/alpha/include/asm/cmpxchg.h\n@@ -234,7 +234,7 @@ ____cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,\n \n #define arch_cmpxchg_local(ptr, o, n)\t\t\t\t\t\\\n ({\t\t\t\t\t\t\t\t\t\\\n-\t__typeof__(*(ptr)) _o_ = (o);\t\t\t\t\t\\\n+\t__auto_type _o_ = 1 ? (o) : *(ptr);\t\t\t\t\\\n \t__typeof__(*(ptr)) _n_ = (n);\t\t\t\t\t\\\n \t(__typeof__(*(ptr))) ____cmpxchg((ptr), (unsigned long)_o_,\t\\\n \t\t\t\t\t  (unsigned long)_n_,\t\t\\\n@@ -265,7 +265,7 @@ ____cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,\n #define arch_cmpxchg(ptr, o, n)\t\t\t\t\t\t\\\n ({\t\t\t\t\t\t\t\t\t\\\n \t__typeof__(*(ptr)) __ret;\t\t\t\t\t\\\n-\t__typeof__(*(ptr)) _o_ = (o);\t\t\t\t\t\\\n+\t__auto_type _o_ = 1 ? (o) : *(ptr);\t\t\t\t\\\n \t__typeof__(*(ptr)) _n_ = (n);\t\t\t\t\t\\\n \tsmp_mb();\t\t\t\t\t\t\t\\\n \t__ret = (__typeof__(*(ptr))) ____cmpxchg((ptr),\t\t\t\\\ndiff --git a/arch/arc/include/asm/cmpxchg.h b/arch/arc/include/asm/cmpxchg.h\nindex 76f43db0890f..e18609174133 100644\n--- a/arch/arc/include/asm/cmpxchg.h\n+++ b/arch/arc/include/asm/cmpxchg.h\n@@ -42,7 +42,7 @@\n #define arch_cmpxchg_relaxed(ptr, old, new)\t\t\t\t\\\n ({\t\t\t\t\t\t\t\t\t\\\n \t__typeof__(ptr) _p_ = (ptr);\t\t\t\t\t\\\n-\t__typeof__(*(ptr)) _o_ = (old);\t\t\t\t\t\\\n+\t__auto_type _o_ = 1 ? (old) : *(_p_);\t\t\t\t\\\n \t__typeof__(*(ptr)) _n_ = (new);\t\t\t\t\t\\\n \t__typeof__(*(ptr)) _prev_;\t\t\t\t\t\\\n \t\t\t\t\t\t\t\t\t\\\n@@ -64,7 +64,7 @@\n #define arch_cmpxchg(ptr, old, new)\t\t\t\t        \\\n ({\t\t\t\t\t\t\t\t\t\\\n \tvolatile __typeof__(ptr) _p_ = (ptr);\t\t\t\t\\\n-\t__typeof__(*(ptr)) _o_ = (old);\t\t\t\t\t\\\n+\t__auto_type _o_ = 1 ? (old) : *(_p_);\t\t\t\t\\\n \t__typeof__(*(ptr)) _n_ = (new);\t\t\t\t\t\\\n \t__typeof__(*(ptr)) _prev_;\t\t\t\t\t\\\n \tunsigned long __flags;\t\t\t\t\t\t\\\ndiff --git a/arch/hexagon/include/asm/cmpxchg.h b/arch/hexagon/include/asm/cmpxchg.h\nindex 9c58fb81f7fd..88986fe04072 100644\n--- a/arch/hexagon/include/asm/cmpxchg.h\n+++ b/arch/hexagon/include/asm/cmpxchg.h\n@@ -54,7 +54,7 @@ __arch_xchg(unsigned long x, volatile void *ptr, int size)\n #define arch_cmpxchg(ptr, old, new)\t\t\t\t\\\n ({\t\t\t\t\t\t\t\t\\\n \t__typeof__(ptr) __ptr = (ptr);\t\t\t\t\\\n-\t__typeof__(*(ptr)) __old = (old);\t\t\t\\\n+\t__auto_type __old = 1 ? (old) : *(__ptr);\t\t\\\n \t__typeof__(*(ptr)) __new = (new);\t\t\t\\\n \t__typeof__(*(ptr)) __oldval = (__typeof__(*(ptr))) 0;\t\\\n \t\t\t\t\t\t\t\t\\\ndiff --git a/arch/parisc/include/asm/cmpxchg.h b/arch/parisc/include/asm/cmpxchg.h\nindex bf0a0f1189eb..30748e31aa17 100644\n--- a/arch/parisc/include/asm/cmpxchg.h\n+++ b/arch/parisc/include/asm/cmpxchg.h\n@@ -78,7 +78,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)\n \n #define arch_cmpxchg(ptr, o, n)\t\t\t\t\t\t \\\n ({\t\t\t\t\t\t\t\t\t \\\n-\t__typeof__(*(ptr)) _o_ = (o);\t\t\t\t\t \\\n+\t__auto_type _o_ = 1 ? (o) : *(ptr);\t\t\t\t \\\n \t__typeof__(*(ptr)) _n_ = (n);\t\t\t\t\t \\\n \t(__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,\t \\\n \t\t\t\t    (unsigned long)_n_, sizeof(*(ptr))); \\\ndiff --git a/arch/powerpc/include/asm/cmpxchg.h b/arch/powerpc/include/asm/cmpxchg.h\nindex dbb50c06f0bf..eaf88b7d0443 100644\n--- a/arch/powerpc/include/asm/cmpxchg.h\n+++ b/arch/powerpc/include/asm/cmpxchg.h\n@@ -698,7 +698,7 @@ __cmpxchg_acquire(void *ptr, unsigned long old, unsigned long new,\n }\n #define arch_cmpxchg(ptr, o, n)\t\t\t\t\t\t \\\n   ({\t\t\t\t\t\t\t\t\t \\\n-     __typeof__(*(ptr)) _o_ = (o);\t\t\t\t\t \\\n+     __auto_type _o_ = 1 ? (o) : *(ptr);\t\t\t\t \\\n      __typeof__(*(ptr)) _n_ = (n);\t\t\t\t\t \\\n      (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,\t\t \\\n \t\t\t\t    (unsigned long)_n_, sizeof(*(ptr))); \\\n@@ -707,7 +707,7 @@ __cmpxchg_acquire(void *ptr, unsigned long old, unsigned long new,\n \n #define arch_cmpxchg_local(ptr, o, n)\t\t\t\t\t \\\n   ({\t\t\t\t\t\t\t\t\t \\\n-     __typeof__(*(ptr)) _o_ = (o);\t\t\t\t\t \\\n+     __auto_type _o_ = 1 ? (o) : *(ptr);\t\t\t\t \\\n      __typeof__(*(ptr)) _n_ = (n);\t\t\t\t\t \\\n      (__typeof__(*(ptr))) __cmpxchg_local((ptr), (unsigned long)_o_,\t \\\n \t\t\t\t    (unsigned long)_n_, sizeof(*(ptr))); \\\n@@ -715,7 +715,7 @@ __cmpxchg_acquire(void *ptr, unsigned long old, unsigned long new,\n \n #define arch_cmpxchg_relaxed(ptr, o, n)\t\t\t\t\t\\\n ({\t\t\t\t\t\t\t\t\t\\\n-\t__typeof__(*(ptr)) _o_ = (o);\t\t\t\t\t\\\n+\t__auto_type _o_ = 1 ? (o) : *(ptr);\t\t\t\t\\\n \t__typeof__(*(ptr)) _n_ = (n);\t\t\t\t\t\\\n \t(__typeof__(*(ptr))) __cmpxchg_relaxed((ptr),\t\t\t\\\n \t\t\t(unsigned long)_o_, (unsigned long)_n_,\t\t\\\n@@ -724,7 +724,7 @@ __cmpxchg_acquire(void *ptr, unsigned long old, unsigned long new,\n \n #define arch_cmpxchg_acquire(ptr, o, n)\t\t\t\t\t\\\n ({\t\t\t\t\t\t\t\t\t\\\n-\t__typeof__(*(ptr)) _o_ = (o);\t\t\t\t\t\\\n+\t__auto_type _o_ = 1 ? (o) : *(ptr);\t\t\t\t\\\n \t__typeof__(*(ptr)) _n_ = (n);\t\t\t\t\t\\\n \t(__typeof__(*(ptr))) __cmpxchg_acquire((ptr),\t\t\t\\\n \t\t\t(unsigned long)_o_, (unsigned long)_n_,\t\t\\\ndiff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h\nindex 8712cf9c69dc..30ade671298f 100644\n--- a/arch/riscv/include/asm/cmpxchg.h\n+++ b/arch/riscv/include/asm/cmpxchg.h\n@@ -215,7 +215,7 @@\n \t\t      cas_prepend, cas_append)\t\t\t\t\\\n ({\t\t\t\t\t\t\t\t\t\\\n \t__typeof__(ptr) __ptr = (ptr);\t\t\t\t\t\\\n-\t__typeof__(*(__ptr)) __old = (old);\t\t\t\t\\\n+\t__auto_type __old = 1 ? (old) : *(__ptr);\t\t\t\\\n \t__typeof__(*(__ptr)) __new = (new);\t\t\t\t\\\n \t__typeof__(*(__ptr)) __ret;\t\t\t\t\t\\\n \t\t\t\t\t\t\t\t\t\\\n@@ -331,7 +331,7 @@ union __u128_halves {\n \n #define __arch_cmpxchg128(p, o, n, cas_sfx)\t\t\t\t\t\\\n ({\t\t\t\t\t\t\t\t\t\t\\\n-\t__typeof__(*(p)) __o = (o);                                             \\\n+\t__auto_type __o = 1 ? (o) : *(p);\t\t\t\t\t\\\n \tunion __u128_halves __hn = { .full = (n) };\t\t\t\t\\\n \tunion __u128_halves __ho = { .full = (__o) };\t\t\t\t\\\n \tregister unsigned long t1 asm (\"t1\") = __hn.low;\t\t\t\\\ndiff --git a/arch/sh/include/asm/cmpxchg.h b/arch/sh/include/asm/cmpxchg.h\nindex 1e5dc5ccf7bf..6c1bfb367f11 100644\n--- a/arch/sh/include/asm/cmpxchg.h\n+++ b/arch/sh/include/asm/cmpxchg.h\n@@ -68,7 +68,7 @@ static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,\n \n #define arch_cmpxchg(ptr,o,n)\t\t\t\t\t\t \\\n   ({\t\t\t\t\t\t\t\t\t \\\n-     __typeof__(*(ptr)) _o_ = (o);\t\t\t\t\t \\\n+     __auto_type _o_ = 1 ? (o) : *(ptr);\t\t\t\t \\\n      __typeof__(*(ptr)) _n_ = (n);\t\t\t\t\t \\\n      (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,\t\t \\\n \t\t\t\t    (unsigned long)_n_, sizeof(*(ptr))); \\\ndiff --git a/arch/sparc/include/asm/cmpxchg_32.h b/arch/sparc/include/asm/cmpxchg_32.h\nindex 8c1a3ca34eeb..df40a16dd021 100644\n--- a/arch/sparc/include/asm/cmpxchg_32.h\n+++ b/arch/sparc/include/asm/cmpxchg_32.h\n@@ -55,7 +55,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)\n \n #define arch_cmpxchg(ptr, o, n)\t\t\t\t\t\t\\\n ({\t\t\t\t\t\t\t\t\t\\\n-\t__typeof__(*(ptr)) _o_ = (o);\t\t\t\t\t\\\n+\t__auto_type _o_ = 1 ? (o) : *(ptr);\t\t\t\t\\\n \t__typeof__(*(ptr)) _n_ = (n);\t\t\t\t\t\\\n \t(__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,\t\\\n \t\t\t(unsigned long)_n_, sizeof(*(ptr)));\t\t\\\ndiff --git a/arch/sparc/include/asm/cmpxchg_64.h b/arch/sparc/include/asm/cmpxchg_64.h\nindex 3de25262c411..4b540405fcc7 100644\n--- a/arch/sparc/include/asm/cmpxchg_64.h\n+++ b/arch/sparc/include/asm/cmpxchg_64.h\n@@ -170,7 +170,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)\n \n #define arch_cmpxchg(ptr,o,n)\t\t\t\t\t\t \\\n   ({\t\t\t\t\t\t\t\t\t \\\n-     __typeof__(*(ptr)) _o_ = (o);\t\t\t\t\t \\\n+     __auto_type _o_ = 1 ? (o) : *(ptr);\t\t\t\t \\\n      __typeof__(*(ptr)) _n_ = (n);\t\t\t\t\t \\\n      (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,\t\t \\\n \t\t\t\t    (unsigned long)_n_, sizeof(*(ptr))); \\\ndiff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h\nindex a88b06f1c35e..e0340579ef69 100644\n--- a/arch/x86/include/asm/cmpxchg.h\n+++ b/arch/x86/include/asm/cmpxchg.h\n@@ -85,7 +85,7 @@ extern void __add_wrong_size(void)\n #define __raw_cmpxchg(ptr, old, new, size, lock)\t\t\t\\\n ({\t\t\t\t\t\t\t\t\t\\\n \t__typeof__(*(ptr)) __ret;\t\t\t\t\t\\\n-\t__typeof__(*(ptr)) __old = (old);\t\t\t\t\\\n+\t__auto_type __old = 1 ? (old) : *(ptr);\t\t\t\t\\\n \t__typeof__(*(ptr)) __new = (new);\t\t\t\t\\\n \tswitch (size) {\t\t\t\t\t\t\t\\\n \tcase __X86_CASE_B:\t\t\t\t\t\t\\\ndiff --git a/arch/xtensa/include/asm/cmpxchg.h b/arch/xtensa/include/asm/cmpxchg.h\nindex b6db4838b175..057fd24ed125 100644\n--- a/arch/xtensa/include/asm/cmpxchg.h\n+++ b/arch/xtensa/include/asm/cmpxchg.h\n@@ -83,7 +83,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)\n }\n \n #define arch_cmpxchg(ptr,o,n)\t\t\t\t\t\t      \\\n-\t({ __typeof__(*(ptr)) _o_ = (o);\t\t\t\t      \\\n+\t({ __auto_type _o_ = 1 ? (o) : *(ptr);\t\t\t\t      \\\n \t   __typeof__(*(ptr)) _n_ = (n);\t\t\t\t      \\\n \t   (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,\t      \\\n \t   \t\t\t        (unsigned long)_n_, sizeof (*(ptr))); \\\ndiff --git a/tools/arch/x86/include/asm/cmpxchg.h b/tools/arch/x86/include/asm/cmpxchg.h\nindex 0ed9ca2766ad..bbd3960c2218 100644\n--- a/tools/arch/x86/include/asm/cmpxchg.h\n+++ b/tools/arch/x86/include/asm/cmpxchg.h\n@@ -35,7 +35,7 @@ extern void __cmpxchg_wrong_size(void)\n #define __raw_cmpxchg(ptr, old, new, size, lock)\t\t\t\\\n ({\t\t\t\t\t\t\t\t\t\\\n \t__typeof__(*(ptr)) __ret;\t\t\t\t\t\\\n-\t__typeof__(*(ptr)) __old = (old);\t\t\t\t\\\n+\t__auto_type __old = 1 ? (old) : *(ptr);\t\t\t\t\\\n \t__typeof__(*(ptr)) __new = (new);\t\t\t\t\\\n \tswitch (size) {\t\t\t\t\t\t\t\\\n \tcase __X86_CASE_B:\t\t\t\t\t\t\\\n","prefixes":["v2"]}