From nobody Wed Feb 11 16:10:08 2026 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (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 405B82D044; Thu, 28 Mar 2024 02:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711592519; cv=none; b=NBHbkjUGDvkA/1WckwcMkY0TnBFcuPmTscWvZBMTT0dwpdWr8q45TY2Mcj6ug9i8eZTtyakmVHo8oPyUCkxD87SXrTRJp2pVtjZYd570HnrsptpPJfCFottrI7L7VvlyXWjezFxTZsbVOHG/RHOJe0d7/ABK7dHHaetgSTRv/YM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711592519; c=relaxed/simple; bh=0OWXMJ+nfoPG2U6D2lWpTASlzsVWSH/1XiZ8Ckg/xk8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uJ+mwdPeeN9P5fnQS/aDXF79dZ9Jss0WbtBPrjjhZZwGOeAYJHZx/Q7xj1zDzVjEoM2OCjgJ1ftKE1VW3PTNpgjxtulh/orSUyg9jR+oRl3aell85FTPRMvHvpU/jLHjWQe0bwd7hnU8c1Hz64ULL4D6t7zuy7zRjHN5uNCF2WM= 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=WjR78QTJ; arc=none smtp.client-ip=209.85.167.176 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WjR78QTJ" Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3bbbc6b4ed1so281522b6e.2; Wed, 27 Mar 2024 19:21:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711592517; x=1712197317; 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=JWYvGOJqkm0rO3q3fSGDNrYx2gNWS9uAp/9tqY5SSZI=; b=WjR78QTJ1z5lk8bYreCbxsWoKiMgtKnSGdx9qPb5LVk7XWHxzudMpCb3wCCInoawVs JQWsNjb+TIXXUbmduWC11kemIdgzMlc39tKkcX/T2MrBTL/A3utOJCCwuGTpAggN1+Do R0RqgTfVrD3GwhIx1qkCOokYpNewOZ2teBBuGy8Ht0goELAkmSuo97nOduiJgsb58eMS ubtB0Ag+ImB1WsMPDrPRyl2RcnVxxo7SKU6QqhBBONR5uVdFLhQchWzDW2NHE46Mcqvp VfpRy1LjKQXi00+NrdWHZuFSpx9K5aih/G0lxaz65EBrJ1AJe8LaOS4cNWuJTcb/xS8u MHkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711592517; x=1712197317; 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=JWYvGOJqkm0rO3q3fSGDNrYx2gNWS9uAp/9tqY5SSZI=; b=Fk5z46NG6aZjmT3janIvTSHUl+/58FifQSqYn/W/qvtQBMvbcLM+TlmGGKHDsbtEcg Tgk3MiyK4rNek0RbQhZF6FWBK0kSBcYzAF/u54fP4hdtojb7vWWxf6bmSIw2xwYb98CT Rvkw3jATakbZIh/Z6KFbmz0A+OTvC5c61etw1PIM1cG/hJu/RXsQ+OzMjDjHucZ0XK2L 4MGg4IVcsAFPOIfo2Ebh9CAs+ySdFcMvRbMMkEeD69eunZFVnyO2LQioqfj5qC8cTLbz UlJvUL41an4Ua/2pvcWtOR/VlBKVXqS5kW6pkGS506ptLBXuCWUa9I/8Q6kGgaBhNK4I Bf2g== X-Forwarded-Encrypted: i=1; AJvYcCWZfQ9ICC5u36fYeppvhtBH8xj5ay4tRQX0iDBcltLHHWmUmLW7xQqtemd7D843vrq3qN35YB/AiCbmPiH8vCg202RKzoKHfVTTgpFtNQFs8avmtSRWD5+Kbq9TqsbNCI7atlSSmf+EPa5NqLgp3nQHCE/ppef/9K0ytCwrLngcia8L X-Gm-Message-State: AOJu0Yy+lJjExchnCDd62EyVjMaBFFx6qPqTnwXv5DzJSAyj4xoxsONl GAuPgb1XczbFnRa0mds8m2mzN6II5QoIMegBmcxoXs8r/jMdp1v7 X-Google-Smtp-Source: AGHT+IFhwoy74Mxg39SWizFElCkR1ejnVAQv+qYEHIVeLmh2VAGr8OMFtTu/ylf16PmqsRapf9IAlw== X-Received: by 2002:a05:6808:1211:b0:3c3:e61f:dc03 with SMTP id a17-20020a056808121100b003c3e61fdc03mr849830oil.33.1711592517335; Wed, 27 Mar 2024 19:21:57 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d26-20020aa7869a000000b006eac233f5c2sm228113pfo.127.2024.03.27.19.21.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 19:21:57 -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 v4 1/2] Documentation: coding-style: ask function-like macros to evaluate parameters Date: Thu, 28 Mar 2024 15:21:35 +1300 Message-Id: <20240328022136.5789-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240328022136.5789-1-21cnbao@gmail.com> References: <20240328022136.5789-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D sg_page(req->d= st); | 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 =3D sg_page(req->dst); for (i =3D 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 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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) =20 +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 evaluate +parameters, but this method is not recommended: + +.. code-block:: c + + #define macrofun(foo) do { (void) (foo); } while (0) + Things to avoid when using macros: =20 1) macros that affect control flow: --=20 2.34.1 From nobody Wed Feb 11 16:10:08 2026 Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) (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 8AB1D374D2; Thu, 28 Mar 2024 02:22:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711592526; cv=none; b=By9fjua5tHn+1PDqd6uLMldYNHYkdCDM2WWoURi5dNJ9Wn9tEkZYF2wmtwpYMSigly5aampqQwaHifVEohil1qOC3yCZ6k1xwuymzXAgEugd7ScyObR8lhyi6wP5/gK/IivOYel3EGuhZbT/02L4EG2bp1i+TNDA+Tps4MINBCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711592526; c=relaxed/simple; bh=/eLhb9Rg4nh9yNL4iwlTn1l8Pyav0reD3p6fibEz1d8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AribWiBZA3eBz0MVeVF+QkfbNU/fb7lRMJ3Jrfec6JsVf1fxn7/66mdGxKLirIag999XqvJeZ9EJllvHHqWao6OFDiek0gMMlyQkaUeawnT0YsEKWsFYOSZti8BiTgLsZEc9UMmpLeO+CsVr+q00SqliabKZ9rh+XDo5DGsI3r8= 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=f8iGeo+M; arc=none smtp.client-ip=209.85.160.44 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f8iGeo+M" Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-222ba2a19bdso267647fac.1; Wed, 27 Mar 2024 19:22:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711592523; x=1712197323; 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=zJKFKvTWiQ1ylayITMd1pxJyaQfArgqbTI5DSxcGrbE=; b=f8iGeo+MnS8W2a21vGPo96OCc+bZwI+ZmmXjd6BvjSw/Z9g8pfF8GQku4UBTywxzCR eBq9j+6Y1CIIATJWDFIibRG9dfl+12eTwCNYIVnscBMFS+YVrMoSjAoGDBHIOXUXGsbh OXiu5b4UQG4PBwMMXdZVC1DqWJFplhOFhEfzaRvgn/qlsXUf6oNkMAUhtNvTGLn2w6B/ cbcAV9e97rCmgefxkDRHJOv8C8DW+S7yaggflHK1w5kmxcdFgjode/kBnn9Xen/P91Q/ kUfYK2uwmkUFKujZveNZQF7Uz0RtwotWLU/SmASRMCaU01r5RDIj6NRVEf99VgF0tx3f s3EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711592523; x=1712197323; 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=zJKFKvTWiQ1ylayITMd1pxJyaQfArgqbTI5DSxcGrbE=; b=ILIqTKCn14mtPzNpktJwXulJkIgyBGMhr5uFhffsykqTYPCCjwXQcgfuWmk7iapcqV ujfPClZE1chv5Atumz6G8gSkX7f4oHAVfViYP4oyDkfGSV9GnQy3XFB6V4sRTK3ZPq/k 4kKvI7Ykuavp0Pv41KlmykUOZrNwXjvUTWPynwrhXe5PG3tqlnOnZ54AdcofE4Cj+b+r xr4rMH5v88Vj7Z/6iPcN6XHjnUU0RGL1yJPxCYlOPoaeJ+329f+iQQrSW6GIoK5rJDDA UchM/v8LiHua5kSTxz180m8KotP+NSMqShucg7PvEiF2A9gAC9C7cfAGvclSLeVUtX9/ r6+g== X-Forwarded-Encrypted: i=1; AJvYcCWZUv26bg4nDgGgl2IPBPICKyj9HnizghLSqUDerXTI+oZhpPlwv/MX/cljwQesOJMKe0VzMin7uyfaVibJmnH7MK2mEWATxcETWn9IhpL828koWWbHxfS5QikB7XFTINeHuzHsNk8AXVUrCBwldeMzPlhzWk0TOE+yGqP70ePNeHl1 X-Gm-Message-State: AOJu0Yy4ALOmK/Uoy79uV6rXNv93PA2eoNqj0n4mUbHUyZECIjv5nSNL fJVM1R39tT4VEPSemXeHYKKMXNeYgQYUaotMobTqsYVDr/9xbHjv X-Google-Smtp-Source: AGHT+IG6vBI7mFQMTCRkMR1DgL0LU5ekXVqi3z1NUbDX1byFjVV13DxPVWJQAAHxY3Ul2lejpzlYyg== X-Received: by 2002:a05:6870:c0c8:b0:229:c1b3:db51 with SMTP id e8-20020a056870c0c800b00229c1b3db51mr1459496oad.47.1711592523713; Wed, 27 Mar 2024 19:22:03 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d26-20020aa7869a000000b006eac233f5c2sm228113pfo.127.2024.03.27.19.21.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 19:22:03 -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 v4 2/2] scripts: checkpatch: check unused parameters for function-like macro Date: Thu, 28 Mar 2024 15:21:36 +1300 Message-Id: <20240328022136.5789-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240328022136.5789-1-21cnbao@gmail.com> References: <20240328022136.5789-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xining Xu If function-like macros do not utilize a parameter, it might result in a build warning. In our coding style guidelines, we advocate for utilizing static inline functions to replace such macros. This patch verifies compliance with the new rule. For a macro such as the one below, #define test(a) do { } while (0) The test result is as follows. ERROR: Parameter 'a' is not used in function-like macro, please use static inline instead #21: FILE: mm/init-mm.c:20: +#define test(a) do { } while (0) total: 1 errors, 0 warnings, 8 lines checked Signed-off-by: Xining Xu Tested-by: Barry Song Cc: Chris Zankel Cc: Huacai Chen Cc: Herbert Xu Cc: Guenter Roeck Cc: Stephen Rothwell Cc: Mark Brown Cc: Andy Whitcroft Cc: Dwaipayan Ray Cc: Joe Perches Cc: Jonathan Corbet Cc: Lukas Bulwahn Cc: Max Filippov --- scripts/checkpatch.pl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 9c4c4a61bc83..bcb886014d60 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -6109,6 +6109,36 @@ sub process { WARN("TRAILING_SEMICOLON", "macros should not use a trailing semicolon\n" . "$herectx"); } + + # match "\s*" rather than "\s+" after the balanced parens, as macro def= inition with arguments + # is not required to have whitespace after arguments + if ($dstat =3D~ /^\+\s*#\s*define\s+$Ident$balanced_parens\s*(\S+.*)(\/= [\/*].*)?/) { + my $params =3D $1 || ""; + my $body =3D $2 || ""; + + # get the individual params + $params =3D~ tr/()//d; + # remove leading and trailing whitespace + $params =3D~ s/^\s+|\s+$//g; + + $ctx =3D~ s/\n*$//; + my $cnt =3D statement_rawlines($ctx); + my $herectx =3D get_stat_here($linenr, $cnt, $here); + + if ($params ne "") { + my @paramList =3D split /,\s*/, $params; + foreach my $param(@paramList) { + if ($param =3D~ /\.\.\.$/) { + # if the param name ends with "...", skip the check + next; + } + if ($body !~ /\b$param\b/) { + WARN("UNUSED_PARAM_IN_MACRO", + "Parameter '$param' is not used in function-like macro\n" . "$here= ctx"); + } + } + } + } } =20 # check for redundant bracing round if etc --=20 2.34.1