Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp984065lqp; Fri, 22 Mar 2024 01:50:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWzXt4HKdyqKjfU++ATApV7phdDxOAFTYGzCZxY2nMoNWfVdID80cRjAVjmIU5ittAY/XaLzAqar8kNIa4fk+gzndRol54tEPUm9X85ew== X-Google-Smtp-Source: AGHT+IFcIoIoJYU8qc+JzYiSeMarGGPuGQa6U6s/SC4Wa2ek/7/aLn33j27NOIoAkVJKDbkItRg0 X-Received: by 2002:a17:903:2289:b0:1dc:79e3:c8ed with SMTP id b9-20020a170903228900b001dc79e3c8edmr2411509plh.31.1711097446512; Fri, 22 Mar 2024 01:50:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711097446; cv=pass; d=google.com; s=arc-20160816; b=u/p4M5wW7SRorymUQRYv2bmRyPziAWXmCF2XrPZUCvz7zFv+hkBYVjGu5oQOloBZ/H fQ+1GUWy9KRyGpQ3/DO/W0otULAGdF/pESiCnEMmPkvc/9xRWjTCM8i0ZMJ6EiJjELHh wwQx863+6ucCskXTKKgVkec720J7+GTeUuyG/9NADzuIfmV//8nhJXvOfAP3zfCZxfey vXm9lno2tQBWWwmre+rbrcRLOJFAz0xSlaASKIT7r2K+V1fgkt/onyKLEsqBMCczqgVI 9Uv4ZchAtUCZxtwiN5ItlOaLCbRay40OcKeCBW09yS2ReP31Fs1MkX6uaVHClxsxNzco O6ZA== 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=UQPV7jUa05dU9iEMp/1ytAeEWTIcwBktdRO6vcJ++jM=; fh=1xbQe1GocetmjaC51jcFmuafS/Ag0oCCM9SFjoAp9Zc=; b=u8gAbsHMkKsNLq4rmobJH9pGeG2W/Pl1XcclIWItpuzn+Is9Az4o3oliLxF2/nl4Sq hcxSyTH5mzCVdnLJcpsup3HPZdazkNqVxeSdNHJOcBHIveEGkF04Uf6Nv5Larawei6/d Be0pgMDEDyl9VfFkyvLkF53lDRw4YuY0asx9ElIveC28yQbFx6AktQKY2zqJ09TvUgFK DYG5N1ooUxs+excBMXGoqeINOJqrOklcn+jX0e+HVdaj20fXicR9U609lm4WkPEXhaPM 4wXjEkKe6o+tSX5WHYnJ1LW3MSHhholepdFe6blySkzFVpERd4AB2S7DBEKBk2OZ8fzF weMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bvVuvld4; 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-111161-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111161-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o14-20020a170902d4ce00b001dda51f5c08si1552462plg.31.2024.03.22.01.50.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 01:50:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111161-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bvVuvld4; 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-111161-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111161-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 2CABA284924 for ; Fri, 22 Mar 2024 08:50:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4166E20DDB; Fri, 22 Mar 2024 08:50:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bvVuvld4" 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 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-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: 8bit 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 =~ /^\+\s*#\s*define\s+$Ident\s*(\((?:[^\(\)]++|(?-1))*\))\s+(\S+.*)(\/\/.*)?/) { + my $params = $1 || ""; + my $body = $2 || ""; + + # get the individual params + $params =~ tr/()//d; + # remove leading and trailing whitespace + $params =~ s/^\s+|\s+$//g; + + $ctx =~ s/\n*$//; + my $cnt = statement_rawlines($ctx); + my $herectx = get_stat_here($linenr, $cnt, $here); + + if ($params ne "") { + my @paramList = 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"); + } + } + } + } } # check for redundant bracing round if etc -- 2.34.1