Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp632647lqp; Thu, 21 Mar 2024 10:44:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVzO+IFmpGVk5IcMrznXJxO/37vA0AWkr+W4hVVpfOekaxmYT33+mmBe7nuehseryAShyHDqMuvk0KggwlgP3aB9Muq6+HIjUYflWb7tw== X-Google-Smtp-Source: AGHT+IEgWd2SrT6sKcGwjIV8/IduAgbFjYdD9iw/6JreszHTkmkH56CKOFWF6zxVwNcwRoX22Y+W X-Received: by 2002:a05:620a:2990:b0:78a:28f9:76d with SMTP id r16-20020a05620a299000b0078a28f9076dmr5405887qkp.59.1711043076973; Thu, 21 Mar 2024 10:44:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711043076; cv=pass; d=google.com; s=arc-20160816; b=sOO/05x74ZnjgBBcC8944Adrt63WmiavCLr1dqaSpxhtsl+NR6mgscepETGcuxO1JO TjUk94hPtF/a2m8z/L6AOVSpH3VwPTQhOdleL+k14/PDW++vw/5KBOVsHT7d/N/IMyXk swaA3xmSV8yZCb3K/lnUhdZsH9KxnmeC05eyEf6QHggvCEQD50Dn4AyqVN+TcVZUXqIB kZtRPkz3VCcWETQ4PjfmPBg2ocy5nsDtSIu1rgk6iu7ZwD6FrajCeFZP8O4xPAV9s9up up7Mv9juy2NTJooa/XL4L5jNiqPc80gpDaIs70184CddiOY9AM6w7spKG/+Yrw5jA1OE SXFw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=sq4mw09KWKbhSL7hN1ZWtT3dM2Tfia2SQ0iyylaoLYk=; fh=5s4TNFT8KxXRlsk3CqxAnNH8GXGUCsMS4MGWlaWIN+Q=; b=YRxp+jbybg1zbOd7mORunrxSV3UruNwksJViMvEBivxje2S15REwzguiSoDdqxXFyU uJR+LuRBlfAEVmvhq13H8hF235+ImLnN/Fkgm0EceTuUpndpriadwwpOKoCFyYaZgKUm 8m7tKAdDgZXaq89wyICBpynlMCHHXz0HbwUN5IkHUhrRPAVpKnB9O30yb8vyTvIME9RF 9YfR36AoyeBqm3VUR7w27FXfUpzhEdeBp8tu34D4Ngc0dmjoLRoKA1VCgBV9+2fqu0yO OHex657wWuk0R4D3UESKG4N+vfV1xHfNbWbnhTJ+AfCDlKB1M0rLalgSgoj6bEV/LJN6 5jxQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=BY5BgQ2n; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-110514-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110514-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a28-20020a05620a103c00b0078a0d51b9e6si191649qkk.695.2024.03.21.10.44.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 10:44:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110514-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=BY5BgQ2n; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-110514-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110514-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id AC01E1C21628 for ; Thu, 21 Mar 2024 17:44:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 56BB3131742; Thu, 21 Mar 2024 17:44:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="BY5BgQ2n" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 435E684A28; Thu, 21 Mar 2024 17:44:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711043069; cv=none; b=bxe5RgrnojKXhejIzi7mWgQBHXzVWz0BZ96Edv7ybvQM9jNMgz3zoumjfhseAwzD/A64U8dO27VWkOd/Uaduj2ZkAdmqHcUQxHXrvnVNmj12xMUKOQ5bfU/6dsvXAm+P/0qoovg69f+Sg5mDcmgxio1JIKtyDqDdFLlUXAnXMs4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711043069; c=relaxed/simple; bh=9bS/UCPvtpMdK1sW9IEcljYoLWk/3hdHxUQ46x96FGA=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=LyOvz/hxWywabRNfhJ5d6qFtMA/GlGbDsX9Oz+uar4rMwbtjhNk2R0+HxGmyrEwosO7thqdixXaYJAG85RRniZIDGyR9PsRRjs0JVWYVe/49UQxaHyqWI4xGW4LTnjGs2bY1BZehfFPM+xsAlefeTTcdSQvBxppbynkF71OfpN8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=BY5BgQ2n; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 726B3C433F1; Thu, 21 Mar 2024 17:44:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1711043068; bh=9bS/UCPvtpMdK1sW9IEcljYoLWk/3hdHxUQ46x96FGA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=BY5BgQ2nAV68ulHmS4PWQLM7hYYDacnq/NTJQdc0ojwqowP9U9TRKS3Apn+lBgjPT BtGbEcvJIcgF09JGaEMZdAnaqeOrGS82IGuKHnsZ4xAbrQPgFfXmG4/SgGO3T/0vBU WWgbyTJ239GV+cJmh7oA+sfEUtm+BB4ShoNnQkhQ= Date: Thu, 21 Mar 2024 10:44:27 -0700 From: Andrew Morton To: Barry Song <21cnbao@gmail.com> Cc: Stephen Rothwell , corbet@lwn.net, workflows@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Barry Song , Chris Zankel , Huacai Chen , Herbert Xu , Guenter Roeck , Max Filippov Subject: Re: [PATCH] Documentation: coding-style: ask function-like macros to evaluate parameters Message-Id: <20240321104427.730b859087afecf5973d1c58@linux-foundation.org> In-Reply-To: References: <20240320001656.10075-1-21cnbao@gmail.com> <20240320124207.0c127947@canb.auug.org.au> <20240320084919.8e18adb418347feed6bfc8ae@linux-foundation.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 21 Mar 2024 07:48:36 +1300 Barry Song <21cnbao@gmail.com> wrote: > > Stronger than that please. Just tell people not to use macros in such > > situations. Always code it in C. > > While I appreciate the consistency of always using "static inline" > instead of macros, > I've noticed numerous instances of (void) macros throughout the kernel. > > arch/arm64/include/asm/cpuidle.h:#define arm_cpuidle_save_irq_context(c) (void)c > arch/arm64/include/asm/cpuidle.h:#define > arm_cpuidle_restore_irq_context(c) (void)c > arch/loongarch/include/asm/io.h:#define iounmap(addr) ((void)(addr)) > arch/mips/include/asm/cop2.h:#define cop2_save(r) do { (void)(r); } while (0) > arch/mips/include/asm/cop2.h:#define cop2_restore(r) do { (void)(r); } while (0) > arch/mips/include/asm/cop2.h:#define cop2_save(r) do { (void)(r); } while (0) > arch/mips/include/asm/cop2.h:#define cop2_restore(r) do { (void)(r); } while (0) > .... > > I'm uncertain whether people would find it disconcerting if they completely > deviate from the current approach. > > If you believe it won't pose an issue, I can proceed with v3 to eliminate > the first option, casting to (void). I think so. My overall view is that we should write things in C. Only use macros if the thing we're trying to do simply cannot be done in a C function. - inline functions don't have the "expression with side effects evaluated more than once" problem. - inline functions avoid the unused-variable issue which started this thread - inline functions look better - for some reason, people are more inclined to document inline functions than macros.