From nobody Sat Feb 7 06:34:07 2026 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 7BD021863B; Fri, 22 Mar 2024 08:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711097402; cv=none; b=S3K0qa2XzCtaMbakapyCfek/ZGo04n55db7lCR5Gu/GV3T1v0OtDHui/GPEEWuRoFhI1WBpaBmomViarosyEtTxX6ggHyiSDQfPp8jXM9vYnzQ2q6H2jyOIjw52kdbgsPV2jrqQnZliCya86hY30obxeVLE/wwbjuD4XJgIxBs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711097402; c=relaxed/simple; bh=HJlrj6w3n1k06T38Le7twWxRKsTsn+pwv/gvS9S19DY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cSt2jarhRvRosqMQrV4heCJUvnNZIhHP80zggZ7sFu8c2kHJ3/fCJ8GiDsEn1lIwbf4PntW+CSaPoVhbdJeL17Lf8IYM9VFUceV24n+/4s/sIt9/HxZKo7bJAMWNyAdMVX6lx1fw9p3LPRm1JEQP3TgikrvLgcYchY98/AIY+fA= 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=CiFEYJhP; arc=none smtp.client-ip=209.85.214.178 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="CiFEYJhP" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1e07cd7b798so9894225ad.2; Fri, 22 Mar 2024 01:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711097400; x=1711702200; 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=uUTQQORTCNkJLIqJM+PvSaUWiqWoVca3nx315DNzuS4=; b=CiFEYJhPiudDPazq2+chTsPGWqqN1nICU7KWt7sXsbW3p8ZJX/W+CowtgCtntU7evT NBushbuzJ6rN13BVMOmWBi4gAUBj2HNTA0tJsgyp0y3aCVg2SIOQTepltthNPdG+bKRP uU4QdAJRSRcYUt/h83LACVS9rPbG7SxLe4HKeW5+6gtvaeVO+HlQXxB3Uc32ydBRuNvT Sr/Q59RylcH11SMdwWg32FBLFpzxcGVFIhsJxNyrnrIoscfTd5MKVwrhHC71cTHdvUqC IVr4hOQOVakkcE78xIur9IV4mrxNg6rjvwSSAQ9I72GUTWtqN2N7Yq//R10EErr4pxYY ngmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711097400; x=1711702200; 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=uUTQQORTCNkJLIqJM+PvSaUWiqWoVca3nx315DNzuS4=; b=Qus1mT/R9sKOwmiLIlKM4zmdmcI30jenYvtQfTQgRKD/XDD2fNkjvNGzytP3t2KTwA 9kjBCj26Td/pvZ8fHe1WANmY6b5nESOnQUa5MtGWg8ePBnjrOKXWMjockgr86nbN9xbq MMUd4li4CrCNOvzknYDf/IOIry5WbGEkWm+oHoQcWojUqmUMFbEE+cR1GNtz+flGvJ+S xf5tQKREQxuofgPq4fDAqbXSpcZhWbpSfoZrhDjEqP0U/jG6VzHqRsFF+8FKk/RJnHp+ Uptd+//H9XXkuBpKzmcA1WIpliFpzNn4w8WtRhL+IzRJu9bF9Dhh+UHiypwKjSrHD0vb 4ndA== X-Forwarded-Encrypted: i=1; AJvYcCWxcsrh570UpEhdkH7SEcPcbdpfeXdcaiHGi0edZIYWMI/ggOIjJ/ehVJtH/dwrRw8248w7Fmu1MwaAnRuEGfCvo9Kxz4+QfbLkzUPuANPmp6CWwntmQ0c0FJCJDXUnRVY5ORFM X-Gm-Message-State: AOJu0YyJfajOksYh1hSvyUtrRSq6IYbdwp8dVKDyZAEDqexmqiaXK2ta U6FJ4BuPJkrLDUYRLw8AXX6Z8srVtzb3VnlsuKxtc1c6p3OogJ4j X-Google-Smtp-Source: AGHT+IEwAhEBj4WraWXSc21vVqo74nXhRTfrIrcdWT93FDm/yOZTJdKCBPQWzzQS0FLvhVT4z/TOjg== X-Received: by 2002:a17:902:d503:b0:1e0:185d:16d3 with SMTP id b3-20020a170902d50300b001e0185d16d3mr2523534plg.5.1711097399842; Fri, 22 Mar 2024 01:49:59 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id u4-20020a170902e5c400b001dd5a0a20d6sm1328165plf.287.2024.03.22.01.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 01:49:59 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: corbet@lwn.net, workflows@vger.kernel.org, linux-doc@vger.kernel.org, apw@canonical.com, joe@perches.com, dwaipayanray1@gmail.com, lukas.bulwahn@gmail.com Cc: linux-kernel@vger.kernel.org, Barry Song , Andrew Morton , Chris Zankel , Huacai Chen , Herbert Xu , Guenter Roeck , Stephen Rothwell , Mark Brown , Max Filippov Subject: [PATCH v3 1/2] Documentation: coding-style: ask function-like macros to evaluate parameters Date: Fri, 22 Mar 2024 21:49:36 +1300 Message-Id: <20240322084937.66018-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240322084937.66018-1-21cnbao@gmail.com> References: <20240322084937.66018-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. Cc: Andrew Morton Cc: Chris Zankel Cc: Huacai Chen Cc: Herbert Xu Cc: Guenter Roeck Cc: Stephen Rothwell Cc: Mark Brown Suggested-by: Max Filippov Signed-off-by: Barry Song Reviewed-by: Mark Brown --- 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 Sat Feb 7 06:34:07 2026 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 D96291B277; Fri, 22 Mar 2024 08:50:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711097408; cv=none; b=p94Zt7Dfb4ZLcxxir6JbqdVZzeY/Viv8DiQi1BgS61ZzTKtCanPN229GldS1nnHvSDr96Wc1m209/IcJr1UH7CMPJpJLJV+QhDZvc6C5VfoIDc+SPTkAAD1dLRaC6vGiBxTL/lNI9UVH8zDKsCPeJRIKCQfm0imDD3RTyrr3yJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711097408; c=relaxed/simple; bh=U9JfB1zvQO1sWnqC+teAftUQyKNdZFSLzpoIHEeAvGc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=U3ey5xsQfVDdvnBjZg/nIO55VKvC4S5x1H6VcuzTnwqDhvEfykUL5wbZkYgcq//n1cGQltVGYLSdoNw30Hu2+5KY+V2Vt0eC+Mcu0VmN27phulSo+NKXQI8achb0h2hugTjPun/pll1lp7oHUnLhe0SoF/4cA8fCkUReXrXdnr4= 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=bvVuvld4; arc=none smtp.client-ip=209.85.214.181 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="bvVuvld4" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1e04ac4209eso16134575ad.1; Fri, 22 Mar 2024 01:50:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711097406; x=1711702206; 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=UQPV7jUa05dU9iEMp/1ytAeEWTIcwBktdRO6vcJ++jM=; b=bvVuvld4k82mKpuepUJOYBglPOV4ZtQNoUiZnOwGDJBhOIiF/jr8Wkabk0MO3+CURx REnqFBl/d4mwUfLiAWGM4YhVXdJSKrv8rWKe4rIvsvcsxar3xwx+9TCJzBpuDJnYfv1n 1W99R5WviEnsH/QPjcx5zfbHxiytH1gosxTg3tfSvm85H4AxGmtsugaioZOlicK5o7BO yybb4Z0NsVa79lUn/7Awzud0xtYTc8iQOyDglIbLBKWUm0lBftX5iqH5oUVMz7qRbmhi AdkCovW+cd6JfF4coinaWtrr9J72lTqpGR2z8Ur4g3XQoVKakwMOHoUVQQWHvb82E7OB FEgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711097406; x=1711702206; 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=UQPV7jUa05dU9iEMp/1ytAeEWTIcwBktdRO6vcJ++jM=; b=wmUNBdYAFX0Y+v5/RwCi6xOKAcQmmWjbWzCo1LSl5uHDf9lYT9N35qqH1qYYk0Ka83 JhmB9Ykn8ppCYKKTkQBCTH4sQnDg3+r5cVTBUUrOEdXBxHC3kmxWjgSx9MPhzhaNunzX mqYHuBi490SNXTx5VSYP2rqoPpxVZvcRwaTDV47jfoWx3ojcxowIQ3nF1ZHxPHQmOuNk 6ZF0q13hEPyjVW8SFsyvXuGQXPAFZxRdDyUDuRLu6b4zUo+E1C+dPgnkb88m3y12+jqw 0S3Pk5PlyuyCPd+mX7j8z3iPHkXzWGx6MITk7DNLjgHlGDumJXJ/vv/IsYgNzLqoH24P NbYA== X-Forwarded-Encrypted: i=1; AJvYcCWlfdF018QLShzu3vs7Ded2w3okQcktujr5uVKr1ipwSX5T6e3HcCAiAYu9JjvsIodVGCj3RX+f6wi4hhREXSfQtEh3u+buNpilLEsOgwC7TxopfC1ozSVJSHJBnmx4EJm4hm0J X-Gm-Message-State: AOJu0YwAdfHJ9Hp+xHWakDt3/rIX92qj4J2a0uWxwhj/3072Z3JBMT5/ 4ujA9zp+Ub/l0EKkCioL1Bo6lr+fpyQ6p5hzmuctRQkfqG1mqu1n X-Google-Smtp-Source: AGHT+IHaLY2PUDsp7RYl90sQQ2ebshPFnPejDPXg9sP1nM/Tb50mAgFOwo+CJmWObpJ6Ots5cmGUTA== X-Received: by 2002:a17:902:ce8d:b0:1df:ff0c:cccb with SMTP id f13-20020a170902ce8d00b001dfff0ccccbmr2177547plg.53.1711097406131; Fri, 22 Mar 2024 01:50:06 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id u4-20020a170902e5c400b001dd5a0a20d6sm1328165plf.287.2024.03.22.01.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 01:50:05 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: corbet@lwn.net, workflows@vger.kernel.org, linux-doc@vger.kernel.org, apw@canonical.com, joe@perches.com, dwaipayanray1@gmail.com, lukas.bulwahn@gmail.com Cc: linux-kernel@vger.kernel.org, Xining Xu , Andrew Morton , Chris Zankel , Huacai Chen , Herbert Xu , Guenter Roeck , Stephen Rothwell , Mark Brown , Barry Song Subject: [PATCH v3 2/2] scripts: checkpatch: Check unused parameters for function-like macro Date: Fri, 22 Mar 2024 21:49:37 +1300 Message-Id: <20240322084937.66018-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240322084937.66018-1-21cnbao@gmail.com> References: <20240322084937.66018-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 Cc: Andrew Morton Cc: Chris Zankel Cc: Huacai Chen Cc: Herbert Xu Cc: Guenter Roeck Cc: Stephen Rothwell Cc: Mark Brown Signed-off-by: Xining Xu Tested-by: Barry Song --- scripts/checkpatch.pl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 9c4c4a61bc83..6f778f3403b5 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -6109,6 +6109,30 @@ sub process { WARN("TRAILING_SEMICOLON", "macros should not use a trailing semicolon\n" . "$herectx"); } + + if ($dstat =3D~ /^\+\s*#\s*define\s+$Ident\s*(\((?:[^\(\)]++|(?-1))*\))= \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 ($body !~ /\b$param\b/) { + ERROR("UNUSED_PARAM_IN_MACRO", + "Parameter '$param' is not used in function-like macro, please= use static inline instead\n" . "$herectx"); + } + } + } + } } =20 # check for redundant bracing round if etc --=20 2.34.1