Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1132827lqh; Sun, 5 May 2024 18:46:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVYjbFi8St3wrcwZEE6+ZadI5B1JfNo/21erx6CMBrL2jDFev7wrHYyVONHfA/m4WxhgAeUPdsJBY4M/gw1AagjJJHwz/FRw34eOOO+HA== X-Google-Smtp-Source: AGHT+IE8KIML/Oi32jw4lZZHaj01YSKECQH9QDRDROJKAJ5VL867IjDx47YLns3w9zptDTyRBxTQ X-Received: by 2002:a05:620a:218a:b0:790:d62a:da08 with SMTP id g10-20020a05620a218a00b00790d62ada08mr8794343qka.4.1714960006296; Sun, 05 May 2024 18:46:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714960006; cv=pass; d=google.com; s=arc-20160816; b=EKST6BtX+9x/VrL1y21l/Rn+3uov0sqFzbYQJ0Zx6Ew6dg8dmuVJg5HGm9I6dO6Q0Q Gr/rmVs2lmhzqFlHlzWRQ4X68dWUMhsSBvP7TujiZUI++n00PFXiqiOBnSUj5zY27FeI Z5Jd4ehb3fQpIM/E3yNKpEDSDq3d7S0fY+e31/WGBbH2qMR+TPBQF9M7QUZYa3ktVoQ/ M89XVCh8uxVBpnN+u0CbpkGwayIVtFfcSDnCXpBA2a4V3huiK56FefoXdwltU3HcirUU CqH82QVm3j4zyYizXmjCqLoesKshI6/+rE+U467TH0MAuFtyMZrg2fxMOS9GXHx3zKqG zWNA== 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 :date:subject:cc:to:from:dkim-signature; bh=O1yoif+153AIw3iNaB4BG80MPHwUmzwez6HYhpKPz5Y=; fh=VxfC4o9dHtvPriFbo4ekgOAy0PSOlfRAtAeu9WZc1eE=; b=EM+6+V6XgE+ZeJlMIi2gy7LZ6VxYPTpouVX8qyZDgYE9end0KZuLkB6bwX4ZwcXo52 H6v45vBdvWX+KT7i8CnFw8Y0E19xgVAVuslTRiUpYCofpaWlR10Hf7RshYqMnQ5I/Zju 8BbHh1iecN0SQcx01H/AxI7t/PuGc056AWcAnpU3yOEOn87d5x7dtx0eLnYjurJsHWxR PqIgD2NtckilPAm8WlH8bHDBDN0xr6hY1H24x1n5KRk2xt6hTplmLOO6nT5BN6oypXFX v7ZoWQhiO4OJWkTMcLTWMk7Jx6aCadR7msGWqdR/R7+27Ge03d9YmTs1/aX+FctwSk1H 7/eA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=S11NdwUp; 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-169239-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169239-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b26-20020a05620a04fa00b0078eb9b45f48si7387117qkh.308.2024.05.05.18.46.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 18:46:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169239-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=S11NdwUp; 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-169239-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169239-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id F2ADF1C2140D for ; Mon, 6 May 2024 01:46:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3670040856; Mon, 6 May 2024 01:46:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S11NdwUp" Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 C877740847; Mon, 6 May 2024 01:46:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714959993; cv=none; b=XdccPzwUCpBY3bRmSvPeHMRGaLIgrESvo50HGkuvGXlm1YOQqQB6Mz7Si2FKaCPVSF3KhytBR87L42SeyW42y4nc+kfp1rz11zAOB+ZpJSdprpVxPbZVY42P7J8IM6R3uYphhBu7Go+IFFkMcsRlLFGAPtgWo0+/vPLk0jBqE/Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714959993; c=relaxed/simple; bh=VM7uBtgDykOSCEFvxGZTHdHh834Ycngh2ZDz0aAHDjQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Nk3y1MSr3kSeo//tEgIX3w2eYQm+/oKcgNzotsQmtTYgYY21WK9lg5Y3THyqDGi9d51sJwYqCn3jtIZY62FpR8fBLDii4BcVmr/20DBIRDOILiDHbaLXM5HagEDFyXDpUWqyIVXfc+Ft+ZaI97zSueETdaVD0PtxFnkfTzSmXQ8= 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=S11NdwUp; arc=none smtp.client-ip=209.85.210.180 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-pf1-f180.google.com with SMTP id d2e1a72fcca58-6f447260f9dso832966b3a.0; Sun, 05 May 2024 18:46:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714959991; x=1715564791; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O1yoif+153AIw3iNaB4BG80MPHwUmzwez6HYhpKPz5Y=; b=S11NdwUp+cZ+wm63qCy5U4UyRRh61yP1zIznYdaPQqvbOylzs9GcxIBstH1BFLnrTp bYkySOecncSatzkWqtXqDQwW/APpQbfm16F2KCsZ36uF1toY3b+YotrxrDV5Kn708f79 nnlobA4XmCUbApFesQzHUXbVcDzhZTdGL7S+1chWd/kFXA7i9ghWwIbWjjkyrDhqKizI ElG3dikFlUd9IG2PCWS6RViewlT/UyqtigqzJQEIj6TtlrtbBWbUOY7vCivfEUAEBwih PH0IkE9CT51J4lraopgl8rcpatmb8Hwo9li4Aum7m9Z0vQ1rLeeI0BJ1WHitnOB5QeL8 YjXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714959991; x=1715564791; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O1yoif+153AIw3iNaB4BG80MPHwUmzwez6HYhpKPz5Y=; b=l9zTIpUtLtWoR/5M2n/w9x7REc/Q9GbufbHxd/9WA0z48EAtARn6xZYWOT2M1lzDSW HlZ3rdS/6gVaFhgHWO+iM2woJIQNgaHnA95wXe70XjdiWzBaDtj9wb1k3WYf4pync1Jb 6ObsySWHnTOA3PlnWvdX9mNHeWd24eeZlLJE6G8YZ3zV7j9Y4hW217eDaaCM1BnQeuJ3 iFtOb5r3aA9IUvpRpHQvhkPpoHHllDHbCobWfZDrwmOIgHGTCywAqRkrr3KQnQJrd+fQ Z2nNlxrKMLWSqFt7Cz1HNJ5lBlt6riy7x3oFCbc62e91Eb6szIwCaoIb2wTj+V2DtzJV S6wQ== X-Forwarded-Encrypted: i=1; AJvYcCXNrxkckw1MoJ/GwnEXWOH1V2Q+6egZajTtzYgqimQCMW/Wln4sjrgjE1Qt+JaNkdNrDtb5ZpenmikQVcnCP5g0k3b1mmULiUK7a3tQAzKbXsrhkuc92ATCoec8l7swhaM0vSM82LIAtpIioikpl4+kLfcQLRCiiVpCBomHWUz9aL6e X-Gm-Message-State: AOJu0Ywk2r7iZsAZXivxZSs9a5SdlyBVzSFPR2Rr3kQJ5OYgbh2K7q96 vrIQgWlNVVQkxGfxHVaGjnoq0u9UQaLSKmFUGnHPZ3ibcUAX9ZlQ X-Received: by 2002:a05:6a00:2185:b0:6ed:4f2e:ef22 with SMTP id h5-20020a056a00218500b006ed4f2eef22mr9949394pfi.31.1714959990994; Sun, 05 May 2024 18:46:30 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id fj30-20020a056a003a1e00b006eac4297ed3sm6608511pfb.20.2024.05.05.18.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 18:46:30 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, joe@perches.com, linux-doc@vger.kernel.org Cc: apw@canonical.com, broonie@kernel.org, chenhuacai@loongson.cn, chris@zankel.net, corbet@lwn.net, dwaipayanray1@gmail.com, herbert@gondor.apana.org.au, linux-kernel@vger.kernel.org, linux@roeck-us.net, lukas.bulwahn@gmail.com, mac.xxn@outlook.com, sfr@canb.auug.org.au, v-songbaohua@oppo.com, workflows@vger.kernel.org, Max Filippov Subject: [PATCH RESEND v6 1/2] Documentation: coding-style: ask function-like macros to evaluate parameters Date: Mon, 6 May 2024 13:46:05 +1200 Message-Id: <20240506014606.8638-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240506014606.8638-1-21cnbao@gmail.com> References: <20240506014606.8638-1-21cnbao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Barry Song Recent commit 77292bb8ca69c80 ("crypto: scomp - remove memcpy if sg_nents is 1 and pages are lowmem") leads to warnings on xtensa and loongarch, In file included from crypto/scompress.c:12: include/crypto/scatterwalk.h: In function 'scatterwalk_pagedone': include/crypto/scatterwalk.h:76:30: warning: variable 'page' set but not used [-Wunused-but-set-variable] 76 | struct page *page; | ^~~~ crypto/scompress.c: In function 'scomp_acomp_comp_decomp': >> crypto/scompress.c:174:38: warning: unused variable 'dst_page' [-Wunused-variable] 174 | struct page *dst_page = sg_page(req->dst); | The reason is that flush_dcache_page() is implemented as a noop macro on these platforms as below, #define flush_dcache_page(page) do { } while (0) The driver code, for itself, seems be quite innocent and placing maybe_unused seems pointless, struct page *dst_page = sg_page(req->dst); for (i = 0; i < nr_pages; i++) flush_dcache_page(dst_page + i); And it should be independent of architectural implementation differences. Let's provide guidance on coding style for requesting parameter evaluation or proposing the migration to a static inline function. Signed-off-by: Barry Song Suggested-by: Max Filippov Reviewed-by: Mark Brown Acked-by: Joe Perches Cc: Chris Zankel Cc: Huacai Chen Cc: Herbert Xu Cc: Guenter Roeck Cc: Stephen Rothwell Cc: Andy Whitcroft Cc: Dwaipayan Ray Cc: Joe Perches Cc: Jonathan Corbet Cc: Lukas Bulwahn Cc: Xining Xu --- Documentation/process/coding-style.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst index 9c7cf7347394..7e768c65aa92 100644 --- a/Documentation/process/coding-style.rst +++ b/Documentation/process/coding-style.rst @@ -827,6 +827,29 @@ 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) + { + } + +Due to historical practices, many files still employ the "cast to (void)" +approach to evaluate parameters. However, this method is not advisable. +Inline functions address the issue of "expression with side effects +evaluated more than once", circumvent unused-variable problems, and +are generally better documented than macros for some reason. + +.. code-block:: c + + /* + * Avoid doing this whenever possible and instead opt for static + * inline functions + */ + #define macrofun(foo) do { (void) (foo); } while (0) + Things to avoid when using macros: 1) macros that affect control flow: -- 2.34.1