Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp273128lqh; Mon, 6 May 2024 20:28:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXIL7X6iFwaWRj6cF5e1Z1gFCn0dybMoaJ1MucLAt9YdiqQGA/gWktqwxIrMJE/sSaNyn6GVv5iAPolAmdIjoplR9s2BQALwOKTqg/i0Q== X-Google-Smtp-Source: AGHT+IG5bnlGEXgAOFsarD0qxOdtY1bjRge3rKRkjhjLOEg87kd8GP/iGL5LRu/NgL24ORZK/kxj X-Received: by 2002:a17:90a:a884:b0:2b1:af14:a92d with SMTP id h4-20020a17090aa88400b002b1af14a92dmr10824139pjq.27.1715052531781; Mon, 06 May 2024 20:28:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715052531; cv=pass; d=google.com; s=arc-20160816; b=a4zOJrL51gBcPCI619gFGc7AAR++y1yRsLhRKAaPgu1jbgZcH48bgUz7QjaqodYwqc aYxUojiriteneoKeNRO87xo5HCCiytOg4sBzyyzEWkuF2lP5q2FRGqUIu9MnFzuA4/ky ngidSxwlHHwGLr4rDdyjtYNT+SNI7HCT6MjxVff1TzxR9Nk/I1zg1dhYtJ79DRw+GzlM 1iOiX1ROoqwSOpvzJUEY9o/J46fN07ve2oF69d/1xT6G/yUJMMXeuc0alBVVltz4eWJl 7WlO7zCEiHAmUA7CYg057FYcAjLANifFJLK6CFLh/Q1DOaMpjCG3zYcM5MbknLgd6VdW KxKg== 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=SO4svkG2NjlN6TUmciRZsz/RMioTaNbu5km5tihixL8=; fh=cDVsywFC9IllrnlBB2tN0wkeowbjRUy8CHB+l3zGR2E=; b=PFuWtsgJAmXd85KVyKJGUB8/nJ4dWACr0JRpCWH4609LiF0RzG5ZzuA7zMl4W5X4zs p+2vITBCuAFye0+sN6rvIpGBuzDJ/9j72SxD11/bGPGVxnoY9r7UTGTtpEz8q53nRwnA UDvKvumVMM1uEEnXA8MtpRYvcGEswaB/o7XTL5GgOsXA1uo4CLOh0F3oYd1U9Mus172T SqaMHtreH9ENOQBvskcrfugrzuPDAWES/pE0b6teQU5J4mmq2b2MiJ3kBCybZeUBYBiq H93H8ron//y/7FtnQgrTSS+5njh9OslxT7WqnwHSCsjcLU7pVtJyapW9QNvWMbGcIymY pHQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SuczOKv2; 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-170614-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170614-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. [139.178.88.99]) by mx.google.com with ESMTPS id q89-20020a17090a17e200b002b4ca477945si5360281pja.140.2024.05.06.20.28.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 20:28:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170614-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SuczOKv2; 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-170614-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170614-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 68205284ABF for ; Tue, 7 May 2024 03:28:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65D5A4EB5C; Tue, 7 May 2024 03:28:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SuczOKv2" 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 073E751010; Tue, 7 May 2024 03:28:29 +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=1715052511; cv=none; b=beZP7sJVLx7UkQ5CNm0NtQM3oxxUFz/l7CHhL/gCO4fzMk2SxUx8wqV/CKTTT0Y1we7tvzQ7TIIxPq/fL7XWUk2vL0z1/l3rB8wUClMxc+wrcTMMPk2coIFITWH+mX+TernWCSkRmsMeeHVSQ9ZVEO3QxIZoxBqwfPeGvbczQZQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715052511; c=relaxed/simple; bh=RJFOiqz4QzNMe5fUaO49lQKw+BLYKHJV5ZAJCUpwMoU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Niciju62KqKrFDIRM7OE43uCEauU4nyjvf6ti8pEQnGwQmfG1M/u4PdVB/LtT9s94NoX/buLiG/2Kob9AHRjnArfIydNWc5HIUxGUOU67Z967KW6qjjtsf0Nn/kBdyvOsjR4nKyXhN7geWsZQUqTi0vyfonjF2mBDWl3xga7rE8= 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=SuczOKv2; 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 Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1ed41eb3382so19917215ad.0; Mon, 06 May 2024 20:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715052509; x=1715657309; 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=SO4svkG2NjlN6TUmciRZsz/RMioTaNbu5km5tihixL8=; b=SuczOKv2EEwxVN3jnA//e3vuukpTB1USQJtZo4DxwPcyfrlaBVj3P9T6+nfeZ6qUEl Vj3gnX+nVa7p3/iXtzlzr9Erq6uaXUsWYeeid6esYR8dFG+xrgltIviI6j2dUlhgbULN I2dvEO5PiI/0fZuUqj3SWxb+sPhvPj68u7QdqnX65hdUkll37hAKV2b4KXeQnuWzOZQi 5JK/XYRB9H8LzsPKx2TBJW+s+GLkpcyUngvrKcfnS0fZyX/ezpgZFGLWmx2iQaJ9/Uz4 6XOPVnKS3RO6nnVMtKm2NV3S5Vwa/mGcDP81TqycSOZEjb6A5xxE5KKK+ty6R8ks+3Xr Wedw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715052509; x=1715657309; 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=SO4svkG2NjlN6TUmciRZsz/RMioTaNbu5km5tihixL8=; b=mzhRaH1sD7kUJvx47yWuZonuKWeX2TTYbZqE5nwR3dgbL7u4OCAh5A/FENnSfpr9A6 YxM3CtMfFKhZJ6C9BD9FXq7wR9hyQ1dA2TdUY/b4yJB9k5s6m2Ge4Dws9xh6h4xsIwxH DtuVWAAhq0G7AdS7FhEpuo0BYhZGwZnAGpRiUxzAf64nGaahxoGBl4Yy21TWsyzxFkJR JdiOoeLJGenzR3AgO3LnuAg82KxigF8uiO6/qVZY286aK5R2LFUFrGY8Nyr353eiOwfv rL5UOlM1bXgPRdEKugZ90d1yLyxWapNoKSuxCSEWTYGi5/RMdc7lH/SKGe2q9SLMyTEO p9FQ== X-Forwarded-Encrypted: i=1; AJvYcCVrLlM/yooDDVkw17FHtsjElqCdjCJtf84XSq04lfUFYSVRxMm8PPNgQt6sOl6RwD+1PwSx8Rb95c8LV8+JyOLpp5Ya9K76o4x19kknXod0R/JXaY4yiqFjcdq9Rn/zlxZmKIw2oolgXR+JqBSnAiED5KKJNfNuffrDBRE2Tax5/MaM X-Gm-Message-State: AOJu0Yy2+hja8Ml+JCw67Rm1Ig4gW3QJSUufZhcuXxPXwXStMxxO70tu Qvf/JZ2Ssbbow+/ZTqEo8MlzFFaEmyEUrUB2rVMV06mzo5IOaYF4 X-Received: by 2002:a17:902:e5c7:b0:1e8:92:c5e2 with SMTP id u7-20020a170902e5c700b001e80092c5e2mr16956588plf.47.1715052509309; Mon, 06 May 2024 20:28:29 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 20:28:28 -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 , Jeff Johnson , Charlemagne Lasse Subject: [PATCH v7 2/2] scripts: checkpatch: check unused parameters for function-like macro Date: Tue, 7 May 2024 15:27:57 +1200 Message-Id: <20240507032757.146386-3-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: 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. WARNING: Argument 'a' is not used in function-like macro #21: FILE: mm/init-mm.c:20: +#define test(a) do { } while (0) total: 0 errors, 1 warnings, 8 lines checked Signed-off-by: Xining Xu Tested-by: Barry Song Signed-off-by: Barry Song Acked-by: Joe Perches 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: Jonathan Corbet Cc: Lukas Bulwahn Cc: Max Filippov Cc: Jeff Johnson Cc: Charlemagne Lasse --- Documentation/dev-tools/checkpatch.rst | 14 ++++++++++++++ scripts/checkpatch.pl | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst index 127968995847..a9fac978a525 100644 --- a/Documentation/dev-tools/checkpatch.rst +++ b/Documentation/dev-tools/checkpatch.rst @@ -906,6 +906,20 @@ Macros, Attributes and Symbols See: https://lore.kernel.org/lkml/1399671106.2912.21.camel@joe-AO725/ + **MACRO_ARG_UNUSED** + If function-like macros do not utilize a parameter, it might result + in a build warning. We advocate for utilizing static inline functions + to replace such macros. + For example, for a macro such as the one below:: + + #define test(a) do { } while (0) + + there would be a warning like below:: + + WARNING: Argument 'a' is not used in function-like macro. + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#macros-enums-and-rtl + **SINGLE_STATEMENT_DO_WHILE_MACRO** For the multi-statement macros, it is necessary to use the do-while loop to avoid unpredictable code paths. The do-while loop helps to diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 9c4c4a61bc83..2b812210b412 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -6040,6 +6040,12 @@ sub process { CHK("MACRO_ARG_PRECEDENCE", "Macro argument '$arg' may be better as '($arg)' to avoid precedence issues\n" . "$herectx"); } + +# check if this is an unused argument + if ($define_stmt !~ /\b$arg\b/) { + WARN("MACRO_ARG_UNUSED", + "Argument '$arg' is not used in function-like macro\n" . "$herectx"); + } } # check for macros with flow control, but without ## concatenation -- 2.34.1