Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp314330lqh; Thu, 28 Mar 2024 02:58:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVarYHf1VyO9H1i8hHVN+t2QXN88Qyk9IMwnzEbeurjgTUw7Ms0GnGECxGjNefYSuKlFXt+bNvRqrV8GvsiJjnrpkmTa5iyAF8BB/glqA== X-Google-Smtp-Source: AGHT+IEEiBC9f2dqUnSr17QV8Mcj6/ZCMonCR5ba1/phpxDuaenjVACr0+KppEfMOZS5fvtpHv6p X-Received: by 2002:a05:620a:13da:b0:78a:1327:13b2 with SMTP id g26-20020a05620a13da00b0078a132713b2mr1912620qkl.26.1711619880741; Thu, 28 Mar 2024 02:58:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711619880; cv=pass; d=google.com; s=arc-20160816; b=OXLKmjAL79Ata+spS1HMsItviJEHQqWyVv8QHLTSPvh3L8FGEXBC196Fyh/4OWdkEc 68AuHRRgW9rC3zhhV+7OdZrpjW7y/Gk/pInDHQSgZ0/kCxIMVb5Ft9BRPuD83DGmWPJC +RKlkekhH1wP13qLHAdBrzebUdGnAcgjnsoQsDlOFJZVe/sZRKuLJ4CntWfZ6NGCBbN+ 0gbizcVXPkOfflyDsKFRtxIiMSqFi3gOhXBTTyDve2fEBUlvJk9+OGhNGXojZqgvG2dJ D0uKboFqKB+3hj2pKkvN/cVUv5rT6ZK0TRWQ7+qX1d+flltF/ZJ+5VV8guORKs7OfVXZ 89Tg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id; bh=/g8ihaJU1zoD3IP9fFh1ss97luRwFZ/xgv4UbZfoLMA=; fh=lpwEnNOJ8eU8Ml6kbL3rsvss8jWZxKuwmxCjOGhhMhA=; b=0Ftjg7HcL8Forx3ULeQFdmmwaczmtIY8ftRGeaSaLBPUIFKaku5eeVd4sufLPdYWqZ 17BMFvaF7wBdt3uz7OlRxVEMCXmtDWvTaEpWpzyt6jNNatuqD6QGP9hPZ1aENAi4KE1R LM+7CcWN5aUuoIFv8L6kTIeXdqq+seSzhv5kpt1gQtTKtWin3FWoOxxwOolMXphnJlnf EDudFXQvLardVWxd1kLEUz+lBHjayCMAN+qIdG8dPckb1SAkeBczSJ/wGsxSKjxNchqX DEiKHTKWrOsTPIHwsiY9eTq9tZ8AbiOzqsQO59RcaTixc26bwYOpwpkytp8FD1/lRYF4 yXpw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=perches.com); spf=pass (google.com: domain of linux-kernel+bounces-122736-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122736-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bs15-20020a05620a470f00b0078a00fbfbb1si1172640qkb.352.2024.03.28.02.58.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 02:58:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122736-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; arc=pass (i=1 spf=pass spfdomain=perches.com); spf=pass (google.com: domain of linux-kernel+bounces-122736-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122736-linux.lists.archive=gmail.com@vger.kernel.org" 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 76C721C2251E for ; Thu, 28 Mar 2024 09:58:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94AC2657B7; Thu, 28 Mar 2024 09:57:53 +0000 (UTC) Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DB64376E5; Thu, 28 Mar 2024 09:57:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.40.44.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711619873; cv=none; b=dcpHmJuaEC4XaXHXZqub0z+3NF7dva4/btbVy3mI5Qyg+Pzqy3PMpM6qIK4fNQU5PBiZ2hyfldHqHtVG8CQ2JnuHAYmNbax4fQvZswcUMgAR71QIK8J80iaV/RzwiyrugxYnJgRovUUf4bbJEZJT0ICjKCXJZ48LczUriJ4M5xM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711619873; c=relaxed/simple; bh=VfjOP9sNdYzTZcnGwVYgxZE+kwKdHl8h61ANJqp0Foc=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=t5/47agdWp5menBmcOWJltQFNXVjcoiz6pCdNVt3CUCPiAX/MJ7uMVAVxoz46C5TNdf+Q9JkNlsf7l+MzlyCR0Xr1D+EURLnLr2lTvfLVRI5Gc4ekbxSPh9j1UpC52WU6RCL33pZolj24tCSmi3WRGoNVH7uSrpCS0Ux0PMx7XM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=perches.com; spf=pass smtp.mailfrom=perches.com; arc=none smtp.client-ip=216.40.44.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=perches.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=perches.com Received: from omf04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C45471C1348; Thu, 28 Mar 2024 09:57:42 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf04.hostedemail.com (Postfix) with ESMTPA id 734022002D; Thu, 28 Mar 2024 09:57:36 +0000 (UTC) Message-ID: Subject: Re: [PATCH v4 2/2] scripts: checkpatch: check unused parameters for function-like macro From: Joe Perches To: Barry Song <21cnbao@gmail.com>, 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, 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 Date: Thu, 28 Mar 2024 02:57:35 -0700 In-Reply-To: <20240328022136.5789-3-21cnbao@gmail.com> References: <20240328022136.5789-1-21cnbao@gmail.com> <20240328022136.5789-3-21cnbao@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 734022002D X-Rspamd-Server: rspamout08 X-Stat-Signature: 7riserhy3yknb9m7sgmq6fti4q81xd8p X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1+g2gqFrn5/7Zkoo0gSWx2LTXg0VwuKnyU= X-HE-Tag: 1711619856-999954 X-HE-Meta: U2FsdGVkX1/xm2Wdm2oMCUMZ0DkhhGweQNTy8N67yxZaCTWJszs1ZErjTWTfmdVB4tZImk178Kb47yNJ1X4bZ2fvC2kWIycpsMIGfvkozPOruh5kXUgNl6yZXt7Fi5QlHOXoWGgoeFXJNjfgDA9bzcCQHN1gPGbSTVvZsCiIonSzwUwrOMpBxR7MKQ2WhvJdZWVSdV144V8/jhP+0rmIlUfvaPmxV15dm9LWKY3am0ckGHPzumvDereLovNuDt87Mx6oQ0eg6U4wzT6viHNqiQUnx57GlGtqXmKIyyxnQYw6h+RJuMHqDXsl0dHBK9WoUqVURbGXq4cihhQg9LK9OnJHkxppVoF9 On Thu, 2024-03-28 at 15:21 +1300, Barry Song wrote: > From: Xining Xu >=20 > 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. [] > diff --git 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 d= efinition with arguments > + # is not required to have whitespace after arguments > + if ($dstat =3D~ /^\+\s*#\s*define\s+$Ident$balanced_parens\s*(\S+.*)(= \/[\/*].*)?/) { I think '(\/[\/*].*)?' doesn't do what you expect perhaps '(\/[\/\*].*)?' though I don't know why this should be capture group > + my $params =3D $1 || ""; > + my $body =3D $2 || ""; Should never get the || "" as the 2nd capture group is not optional > + > + # 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 "") { probably unnecessary > + my @paramList =3D split /,\s*/, $params; please use split() with parentheses > + foreach my $param(@paramList) { maybe foreach my $param (split(/,/, $params) { $param =3D trim($param); next if ($param =3D~ /\.\.\.$/); > + 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" . "$he= rectx"); > + } > + } It seems this logic is a bit redundant to existing code and might be better added in the block that starts (line 6026) # check if any macro arguments are reused (ignore '...' and 'type') as that already does each param in a #define and ignores ... and type