From nobody Fri Dec 19 00:53:55 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 908DF2C2343; Tue, 16 Dec 2025 14:19:39 +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=1765894779; cv=none; b=iIJLOORci7voLJpFubLjlTH37MCZVaNQniGrIcUEmG8u6DD16ck8wXR+VrobrpdQ0NjwBqLRpp7rhpdW0PkirxrGMQL3zP/e2HmFsolRR7TPXb8ArqYXrjWnqthWd2VFKTR7pqRSg34Y9BUqxlBSrtaM0DGrhff4+tWGf/1yG6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765894779; c=relaxed/simple; bh=NGjJSzPHUhLrxbgjeCgA2jiaySSHpT2Q4b/PjRan67U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r8isvdcIQQfHTmG/elR8tvaA5hLtjwyAvpySvMjbGl22DCWIjaraC19SfBBT/h2vcKe2eAiRDm3OqQmvFVT3TbICNSPCHboZ8YhDZIp74nAlARUVuykOHyP2SaQi2c4+Ild2fzPO96Q0V/xQyFrWInsNxWP/DxLW6qVZWbDv7dk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ih32hZy2; 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="Ih32hZy2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19EF0C4CEF5; Tue, 16 Dec 2025 14:19:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765894779; bh=NGjJSzPHUhLrxbgjeCgA2jiaySSHpT2Q4b/PjRan67U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ih32hZy2NMeiMnKdTY5+YicwHWn4JqpOpeLU4Gg/dZs/1rl1st+Xvck9TbQLamu7e qUzq46auSvgvjpYr8MSb8p2TKfpkiINJmO6FuL7bYopitg5etdfb8OHRsWOJwTMDhJ +wH76c6sX6ywS3dXioFLqylSu8M15dL+YRuRDj8/0oe3vkrP5oqg/Z/+/1wjZHPqgq NS0qTBN2tyM4EpU6r8RPLQXTKA4rdpCHtcJZyarpfKel+RWoHcMZNk4leqvFYKMplw HLxoWZ40FY4zOkzjFMp5Ard881++8EudcQAu8zfRWr998iPbcK8wWqtyFgvHmWF1ZI G6mkVgbpFiG+g== Received: from mchehab by mail.kernel.org with local (Exim 4.99) (envelope-from ) id 1vVVtp-00000000sRf-0tiE; Tue, 16 Dec 2025 15:19:37 +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 v6 2/6] kernel-doc: add support to handle DEFINE_ variables Date: Tue, 16 Dec 2025 15:19:24 +0100 Message-ID: <757a45100cfc493984574ff780aa9d90506eecb4.1765894670.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