Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp725112lqp; Thu, 21 Mar 2024 13:38:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXpgF8MxPx/F8Ljiw6HnMDC5fzabzbz7pUuGIkb+oQMgee9Ti4AJt6mm9z4KubbZ9YV79GP4ZIdkoiiTBIMhCgPLaMIfZ/MOwi+/Edjlw== X-Google-Smtp-Source: AGHT+IFTuAUrZ+wQ06trMS7GVLxiJfd/2dAFfY3FBba03UvrGaeZzUOUfxODWgNsSy1egM4YdQMf X-Received: by 2002:a17:903:124c:b0:1de:e8ce:9d8f with SMTP id u12-20020a170903124c00b001dee8ce9d8fmr611840plh.18.1711053503301; Thu, 21 Mar 2024 13:38:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711053503; cv=pass; d=google.com; s=arc-20160816; b=oC4ivlurYinYAHmTsT7uRqD24eVWe8BUIaHOQy685o1p+qW7cQf7PyJUio4dEZf+no ON94yT7mTdFz7u7DoQGbrRNNxSwLlYy7D2TQLfnkj+5RZE4YVoglIYxc78tOw9oWXBeC mKIrLPej1leJNclWWMmEO3FiDhjMF/38U/X3UT47+WrP9ym6cBAgspUE4cZRQ2buJ1vL KR7CkbCXy3Stn4MzPx6POzHPwqaM/2JhFwJwQyBCS/v47lk1uCfWhYCO6u342RLVSpPu Fl4m57fsc6zI/rfoqozhp49dZPX6aAWo5AZ5sTFjcKJO5ygHy4r1Scsd8xScmTnupcxH SWEg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=dvUundGT9VWuWy9NB7xPMf/jJU0G9U18//kTI/zsuts=; fh=7prpAP7DnciShNp9fp+8bS7H6eF+HMWt6FIwYVl4CUQ=; b=XUbmJ2aAqQgBrsCQAoJV2vGSaohWWpFg8dgfM+gbkOhrAHmAlh0Dl4un5GsxdPtT2G ic8D1IXaM2502i8hX+tKciPTF52DdUO7kLL92VDRrViBNepN+Gzhf7wdoqkS+8vToQuu 8LaWhHM1nS2xO+E662Y/2d5CWSNomhzPgiA4s218w+i9pM42kXBPeEHauCP5HBP4rH/3 DNeVbTlYZyBQ0M18dnG6SM+JfSps1NQ1y3FP/qAqplzT8HU0AcgPpiMJ7ES+3y8upUf2 gmu4/KssLBbXdgyhfeW8xN/CETfuSgaOb2l0+V1J/dlYz5PwA3H632T1KVbeeH2rB4PN Ys+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=X3eqR5Br; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-110646-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110646-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d22-20020a170902b71600b001e001920c4dsi368727pls.547.2024.03.21.13.38.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 13:38:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110646-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=X3eqR5Br; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-110646-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110646-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 54C4E288242 for ; Thu, 21 Mar 2024 20:30:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A18F11353FB; Thu, 21 Mar 2024 20:29:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X3eqR5Br" Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BA03134CF8; Thu, 21 Mar 2024 20:29:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711052993; cv=none; b=i/O+OP1xI/BHmlDIfKMuQQG3UlqfDL6g4m0tQu+41yVmpv76ZJxgUqZ02DJE78GmUncWcfv0JmIHGe3QNtjFLxMeqdk/QJ1TCcfhnS0+l4iAAei9P6dlNlHO/bPiOaQVgv0p0hLFS7VUC2r//dcANkZ/2ZPmHVXfTGSzHZfVKUU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711052993; c=relaxed/simple; bh=2wXA6Ael6yWaRfU8iCscuDKtn9ua3SRp6qM1HO4Qv5I=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=jzDBxUMMoRO/gXZto+K5SkhKOj7wVM557A66TtWxMyHW17fKVARa8nUbdnFDghkh4hnZR/gUsZYHn7069WopLU5KY0GbOcZiCJlfmE8hqwbQJmzJHWmaNoExxE28ep0S5SVSt9X6QnPVceYdI0Yy1K/pXZPDKLbNpMcDHhMs4QY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=X3eqR5Br; arc=none smtp.client-ip=209.85.222.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ua1-f41.google.com with SMTP id a1e0cc1a2514c-7e09ba2ac02so703682241.1; Thu, 21 Mar 2024 13:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711052991; x=1711657791; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dvUundGT9VWuWy9NB7xPMf/jJU0G9U18//kTI/zsuts=; b=X3eqR5Br4QqLd5fqP4NQjCJrPpM4Dz7mZJRZM3Sowr6Aa0LrZbkOoRLuUXmL5bbvYe 8y6WNEMAknK0bqv+P0Wp7+KB5x/EV2GPB0hYQZU/iT7n8br5gotV6GNFj1TksmgozCZB GhhiHTMEqd9CXlXADrOtFc02Fm67ZEmiLgwN/KWUuSPGrbuYEVkoOsdlDcDq1P2HKx4I BAxSItGGhxhQqxmhyCDqiwHtMVR6aPF9ISbqA4+8wquzHLqanXpQCQMoi02MS0bBKiuM QyVD7N+zNOfQGpt926RNZUyK4cOevt3D6L8dlmUWfWZrAI5JB+PPC9JjRgm/OKJdsW5I u5Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711052991; x=1711657791; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dvUundGT9VWuWy9NB7xPMf/jJU0G9U18//kTI/zsuts=; b=mAFV29ihD1sYzO747klMC8eJv2Bcx5L6gqPQKvHgKlOCvNWkypib5yb0u/xRM3N34I yFeOx67aDXG1oJlhU1mpUIqpiwkZadQl3KcGaaTc7sg0d1qZXnP0X5cUYHMUyfR8710f Oy9hm5Kzajzvug03EbvrfoOO9i9nQ/y8vAtSKUifyQjNz3s5fENWUm7Wwg/gKrCGBe0d o97XCP7wjHuBFhHOHh/h39n7MwTOf8Oq8vBDZmm040Ik/OV6B6KIGSI3GDS147KIbnyS /XKhAgDSwb7deqRA0iyf+cCzjDWP5VEsZIGutro1j77/f1CKFItVzK3HcqBkIdQz7ULG 3flw== X-Forwarded-Encrypted: i=1; AJvYcCWTRy2VFHpWN7an/aaM6RvqpoAgAUCu0ksS2LkNGMPTVF4OB0OdU2nziaVh1Dh/Q2MSr0OTecEEd7ZeSMWE5UofFF3FiWD7wOy628CrZ9xgoEs7+MYklc06rTWLB1KWxoVnszdIYiKmxU/hbFU/d3o88NciWSaB93qymccW/44U9miI X-Gm-Message-State: AOJu0YwszI1IIYvmrq6FF7i3K2C+TZCGzSm/WeVQLmdlKEoJRfrf6q3K 6XD//FxZ7Wi0a3rlA0Ik/DKStOkNQkyhh4uPqFrtbl6uIb3kxvdIHVE9mlrBIDv398O3bPawGmf nd6XAyqtpC0BOFfIurs7nz3EE53g= X-Received: by 2002:a05:6102:dd4:b0:476:b885:4c0 with SMTP id e20-20020a0561020dd400b00476b88504c0mr810811vst.23.1711052991024; Thu, 21 Mar 2024 13:29:51 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240320001656.10075-1-21cnbao@gmail.com> <20240320124207.0c127947@canb.auug.org.au> <20240320084919.8e18adb418347feed6bfc8ae@linux-foundation.org> In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Fri, 22 Mar 2024 09:29:39 +1300 Message-ID: Subject: Re: [PATCH] Documentation: coding-style: ask function-like macros to evaluate parameters To: Mark Brown , Andrew Morton 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Mar 22, 2024 at 12:15=E2=80=AFAM Mark Brown wr= ote: > > On Thu, Mar 21, 2024 at 07:48:36AM +1300, Barry Song wrote: > > On Thu, Mar 21, 2024 at 4:49=E2=80=AFAM Andrew Morton wrote: > > > > Stronger than that please. Just tell people not to use macros in suc= h > > > 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. > > ... > > > I'm uncertain whether people would find it disconcerting if they comple= tely > > deviate from the current approach. > > > If you believe it won't pose an issue, I can proceed with v3 to elimina= te > > the first option, casting to (void). > > It might be worth adding a note somewhere in the file that talks about > how the coding style document is convering the current state of the art > but some files might older and not following the current style. This > isn't going to be the only thing where there'll be issues like this. I'm not entirely sure where to add the comment, but at least I can address this specific case by rewriting it as follows: diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst index 9c7cf7347394..791d333a57fd 100644 --- a/Documentation/process/coding-style.rst +++ b/Documentation/process/coding-style.rst @@ -827,6 +827,22 @@ Macros with multiple statements should be enclosed in a do - while block: do_this(b, c); \ } while (0) +Function-like macros with unused parameters should be replaced by static +inline functions to avoid the issue of unused variables: + +.. code-block:: c + + static inline void fun(struct foo *foo) + { + } + +For historical reasons, many files still use the cast to (void) to evaluat= e +parameters, but this method is not recommended: + +.. code-block:: c + + #define macrofun(foo) do { (void) (foo); } while (0) + Things to avoid when using macros: 1) macros that affect control flow: Mark, Andrew, Does it make sense to you? Thanks Barry