Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp273087lqh; Mon, 6 May 2024 20:28:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWOSnwXaWkKl0HcMjt6O5/dqN9lDCAmYc2enGX6VGFisWAVODgERtllcjkIVJ5Hgp9bXbQgFvNwRmFniQh9qpm29iICQqw6DDryRCrHig== X-Google-Smtp-Source: AGHT+IGVXVozupX/thqb6Q4TeHT+KzGxTshNYbAJn+aaWqQ5WV/2m2Zc3qP5vEWvQL+QoJkixYGV X-Received: by 2002:a17:906:5a84:b0:a59:9db2:d988 with SMTP id l4-20020a1709065a8400b00a599db2d988mr5741406ejq.50.1715052519448; Mon, 06 May 2024 20:28:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715052519; cv=pass; d=google.com; s=arc-20160816; b=ZkxSTgBBI2gl97TeDXDi7N8QlIOYI+LSbq9TkM46eR8Cte+fVrFxm1XTXqwyhgjeHb 1wp1I0GT/K+TBu3THoSq7nrxB6cWq1oM6OEzBOByXPbGhHelieWoyypLb25FfkbG2W/0 IF5vKGPNd9WNNiguj0Tg/GknnUKp9f2QC+90RWX9sElUeYGwPeaHDXQJwYtFFEFBaLqN rw+VgryYx+1QiG9xvLcfAZU66trKPOvhzzDWxfOLG4u2l1p/YW2Emh4KOKeG6d1o47Il fMWV/x5ecdUR9k4CDhWguW8kpiFrudNRssbZKRP8WCZYVDzaKRpw7xR4konQR20qznxa c92Q== 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=sYj2j9N2bsysC1KrLgVQncwNWbQsojl5A4N+3j1ZDe0=; b=stLl63VOhCdVFU0hysnUnmfwFFK0hkoKueOVXfr5dDN4Y+XVm6hfxLQYnhTr9jQnJV MPjCOBT+M+RwMFbQnCu6hY5F/5hNgu3melRSTJ2aa53i6b4YbYzICEMWHqfxawogBaYY mpkO/sQGR0/iqzsQnR23CXTknKK+wuoVs46GIyKQ4F70IQNk9kPH+fw9wuE+xqr2ZKIe nUTe+kcLpYhspr9n8eSn13MSlSAnvw/6XqzWmkJkaXCUG6LKWMplyGTe9OE3ddd5A2I6 CZUqlRlGpPXXGPQV7sCEa2rcWcXoRH5AgsKMTxSVablfn/TTiNgU8GIin/wocw7xqYWL WL5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jNOz6v75; 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-170613-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170613-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id nc36-20020a1709071c2400b00a59aa7a3b45si3709346ejc.2.2024.05.06.20.28.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 20:28:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170613-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jNOz6v75; 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-170613-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170613-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 am.mirrors.kernel.org (Postfix) with ESMTPS id F3EAC1F23065 for ; Tue, 7 May 2024 03:28:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71B144F889; Tue, 7 May 2024 03:28:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jNOz6v75" Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 1ED1D4C94; Tue, 7 May 2024 03:28:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715052504; cv=none; b=hJxrRAikffZxWmOTnAMvrXwiGxN324PsN0JylBNr9c2QJ4halmjJ2ngHPr4jGY8QgcdA+ORD+brvHOjHKX8wFcVEK9od4v/mSJym6vwMPzmW2buM142+st2aYx8ipwyI0CTI5U7sQi+TzTYQm9MBwm/bX9oBDYVpE70YsYlczwk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715052504; c=relaxed/simple; bh=VM7uBtgDykOSCEFvxGZTHdHh834Ycngh2ZDz0aAHDjQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Xs8I2tefgqqjYbt7OySHOhMdFzfv5dZ01AjO/fceOGjSeH3GTGcl2C6p5uM6WBf1MdGXGUbCUylMA+Gmy6itPC2fUIATGjaQqrfOU7UGsiMiJ4G3N7Vyg4TyUrFRdv4YxrQ1slXWL9qTm6SdOeR1qTDP00I2u2itQhScrD+jJ34= 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=jNOz6v75; arc=none smtp.client-ip=209.85.210.174 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-f174.google.com with SMTP id d2e1a72fcca58-6f453d2c5a1so2543874b3a.2; Mon, 06 May 2024 20:28:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715052502; x=1715657302; 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=jNOz6v75AKuM7kuVcRxNWPWErhAZJHv1v5kXS/yynL5+HbEVQkVyHQZC1Qoa2TIdTb 6nyOjCNv3hUB49ev4RgqF+6qRqHMz/8/ofnhhIiYynitVwfQdUq+U3GbLpZMprkXf1Li F/euTWUlcG5eM1W3o0umYO0Igc/orm/EayHWdRh3EpDG45wBvj2jsSpuXit1KmjC6Y5l FNCfenRHSknwKkusT25H7Yabz4VJVkwuP2LTzzecX3IHKHOwBA8NRyMGv++3gN8k6+EX MOoxPpE+ceC60RXyQm5TM0mTFFGCa4BI31veqBevmDZsOuRkKYNwd1s5vmOvPcKfoLM+ 4+xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715052502; x=1715657302; 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=F431ORCoslLT7+2nLpkSK7cblpZUR45TVbXrzcpdvjt6YAXSkLFLp6ov+WGKbw9xpI 7KeIBKRqFOlJ3v1KLGwZE0j/BTVgN2iAWkkVdGWXAhVqCNJ6sGqy+IDxTY1B/GJm8/mx 2O4S0oqqb+RHK9Y5y9Zns60QrCoSL2QbYwfhj3al1ppiuJsMdUrEVw2sx8fxm8jFMicS qjG3dQ4bTHFPHIUdcAy5cIAWrjVu88cd2Q7DwollFa4DomAFINy35hQsFuSfE1dNzR+n MxMu57/VjFO2cNYNS4uJaqDcAvklT4vT28mkQCoO2IzXjm4+B71hNoySN96Wt9845lEy ADeA== X-Forwarded-Encrypted: i=1; AJvYcCVFdHfeos1gHK6+ebGUYiyRZWSaOi47PGXmOCdwDE55tmOLcqomP8T/X0IlWfWx9+LPLBYt90q/0kH8nhPKj/VUwZ94QxGe9RKsRtUXD5lkMuuPV3PuWrXbxYaNYRjzG7XZXxZpzsEH5o7yVcg1AM+Bevovsd83fEBvC+QKCsC9nTtL X-Gm-Message-State: AOJu0Yz2S4OqjPhY7oGEKhB3Fnq9zkP4vAnhjQZ134m0DBC1HynYmd5n cT8Tb3qXGe9CNjjQFwqNufVAXAFvV/qjxoKoWIft7YN6yN64OKB2eiNjGA== X-Received: by 2002:a05:6a21:8cc6:b0:1a9:a820:c604 with SMTP id ta6-20020a056a218cc600b001a9a820c604mr16337860pzb.48.1715052502344; Mon, 06 May 2024 20:28:22 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id p16-20020a170902ebd000b001ebd7bdaaffsm8988409plg.288.2024.05.06.20.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 20:28:22 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, 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, joe@perches.com, 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 v7 1/2] Documentation: coding-style: ask function-like macros to evaluate parameters Date: Tue, 7 May 2024 15:27:56 +1200 Message-Id: <20240507032757.146386-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507032757.146386-1-21cnbao@gmail.com> References: <20240507032757.146386-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