From nobody Thu Dec 18 20:02:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3667F34BA54; Tue, 16 Dec 2025 14:26:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765895185; cv=none; b=bAUxR4k+lL0SSDGaLTDK6YuwUSNUJA7ojGdPewfdfZC6NK/cp6reldw7RuoqYxnlufUHw+K5OFNic2nRijdGQyRGTlal2ZjyhaWFPFXGhH9l/hXPMtVCF5RawCc6kEzzkEmT/lr+tlSi6PU6x0wu2JO0ep9A6D7VPJvXY3eayIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765895185; c=relaxed/simple; bh=NGjJSzPHUhLrxbgjeCgA2jiaySSHpT2Q4b/PjRan67U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MDAgBLXUx3zEEaw4rU+XC2rM/Zu7D0myn+bD/Zp1CreA2NCS3gPlP7necEIAbVc2sfJuQCi7Z4Qic81hqjfYTQlFEV/TLIoaDvtv0NQ+d0ueo4/0GpxcVgnTDHnD2l/nhanu+akMq9NjAtkDNiVPyOqCsTDPl7Wjn5/jLrZlgyg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q5WwbdsE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Q5WwbdsE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9199C4CEF5; Tue, 16 Dec 2025 14:26:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765895184; bh=NGjJSzPHUhLrxbgjeCgA2jiaySSHpT2Q4b/PjRan67U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q5WwbdsE/K0OG7NIAv8XijYPMHpv9OxMzE7s53Nh7bvPiQmXH7N96Q/RZ6fVajZ5c U/0TIvFqUILi8n2bKc83SfyvVI0JLtEBYr+HmkwzT4RJF30+NktKLaeLl6OGyoWWO3 M+YXRCreLYWlyucxeZVTYAgovAftGkabLMexAflzQasXF9xh4sLGArMp9L+ryN/M1h oVrs0pyDPHg/uOpHFjHG06tVZjdwNUZeUNTlREzgFVb6jraIXP+wupza7BpcMkmUGU TD4o/MYTr58Z5AQzAtpDNXqqPkSc3d+4FcXndl+hSDu2CBH/STZf+aEeAhYnsN4WP5 F3epAUx0IIXWA== Received: from mchehab by mail.kernel.org with local (Exim 4.99) (envelope-from ) id 1vVW0N-00000000stQ-059y; Tue, 16 Dec 2025 15:26:23 +0100 From: Mauro Carvalho Chehab To: Linux Doc Mailing List , Jonathan Corbet Cc: Mauro Carvalho Chehab , "Randy Dunlap" , linux-kernel@vger.kernel.org Subject: [PATCH v7 2/6] kernel-doc: add support to handle DEFINE_ variables Date: Tue, 16 Dec 2025 15:26:13 +0100 Message-ID: <757a45100cfc493984574ff780aa9d90506eecb4.1765894964.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: 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 Sender: Mauro Carvalho Chehab Content-Type: text/plain; charset="utf-8" Improve the parser and output plugin to work with macros, adding support for the common pattern of using DEFINE_* to create variables. Signed-off-by: Mauro Carvalho Chehab --- tools/lib/python/kdoc/kdoc_output.py | 5 ++--- tools/lib/python/kdoc/kdoc_parser.py | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/tools/lib/python/kdoc/kdoc_output.py b/tools/lib/python/kdoc/k= doc_output.py index 50aedbb3d6de..d2bf94275d65 100644 --- a/tools/lib/python/kdoc/kdoc_output.py +++ b/tools/lib/python/kdoc/kdoc_output.py @@ -486,7 +486,7 @@ class RestFormat(OutputFormat): =20 self.lineprefix =3D " " =20 - self.data +=3D f"\n\n.. c:macro:: {name}\n\n{self.lineprefix}{full= _proto}\n\n" + self.data +=3D f"\n\n.. c:macro:: {name}\n\n{self.lineprefix}``{fu= ll_proto}``\n\n" =20 self.print_lineno(ln) self.output_highlight(args.get('purpose', '')) @@ -801,13 +801,12 @@ class ManFormat(OutputFormat): =20 def out_var(self, fname, name, args): out_name =3D self.arg_name(args, name) - prototype =3D args.other_stuff["var_type"] full_proto =3D args.other_stuff["full_proto"] =20 self.data +=3D f'.TH "{self.modulename}" 9 "{out_name}" "{self.man= _date}" "API Manual" LINUX' + "\n" =20 self.data +=3D ".SH NAME\n" - self.data +=3D f"{prototype} \\- {args['purpose']}\n" + self.data +=3D f"{name} \\- {args['purpose']}\n" =20 self.data +=3D ".SH SYNOPSIS\n" self.data +=3D f"{full_proto}\n" diff --git a/tools/lib/python/kdoc/kdoc_parser.py b/tools/lib/python/kdoc/k= doc_parser.py index 06bed1a12a45..aaa352855717 100644 --- a/tools/lib/python/kdoc/kdoc_parser.py +++ b/tools/lib/python/kdoc/kdoc_parser.py @@ -949,12 +949,27 @@ class KernelDoc: # Store the full prototype before modifying it # full_proto =3D proto + declaration_name =3D None + + # + # Handle macro definitions + # + macro_prefixes =3D [ + KernRe(r"DEFINE_[\w_]+\s*\(([\w_]+)\)"), + ] + + for r in macro_prefixes: + match =3D r.search(proto) + if match: + declaration_name =3D match.group(1) + break =20 # # Drop comments and macros to have a pure C prototype # - for search, sub in sub_prefixes: - proto =3D search.sub(sub, proto) + if not declaration_name: + for r, sub in sub_prefixes: + proto =3D r.sub(sub, proto) =20 proto =3D proto.rstrip() =20 @@ -968,14 +983,16 @@ class KernelDoc: return =20 var_type =3D r.group(0) - declaration_name =3D r.group(1) + + if not declaration_name: + declaration_name =3D r.group(1) + default_val =3D r.group(2) if default_val: default_val =3D default_val.lstrip("=3D").strip() =20 self.output_declaration("var", declaration_name, full_proto=3Dfull_proto, - var_type=3Dvar_type, default_val=3Ddefault_val, purpose=3Dself.entry.declaration_purpose) =20 --=20 2.52.0