From nobody Thu Oct 2 18:33:48 2025 Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) (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 043B42C11D6; Sat, 13 Sep 2025 23:59:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.104.135.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757807959; cv=none; b=W0zYVqXF+epW+hGsnotyAuWPiUMEh8nGTCMxJCXxw1gcO9T6eioEZIJm/9YxUx+hPdMTsYGNl1YFWgKfMngp0VrAlU18jRjncxdNSTReMxhQwT5zw/fj0GhyTBHR/Kr/DvkRraNpryDCJgzsJW4Bkm/4dwsUBtIdlku8tVQmf8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757807959; c=relaxed/simple; bh=NCxd5MRWulhhiQGexBU/b6H+S/dHIidGMKcSy5JY6Lo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CTvY7mNc/qkYlHXJ313XAU2JOfnmHCGG3ro3YiC7EPAMOeOy3FKIkPCWWq50Z9AEdiB7UXNw7mWqCnzQUa72u5EQlZK0/D4XDz0tIPnD0zrs1wak/Wa2kLRC/T3wovZNvE0MEBQkQn2HX33PVJRmdrVkvO50qGP8ATQ1BPPCEDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net; spf=pass smtp.mailfrom=fiberby.net; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b=S6SpsJhO; arc=none smtp.client-ip=193.104.135.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fiberby.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="S6SpsJhO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1757807952; bh=NCxd5MRWulhhiQGexBU/b6H+S/dHIidGMKcSy5JY6Lo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S6SpsJhOOKjC2w5l1+EX+OcNvD9Ge6paj7F6JlTfAA/TX5zbP0J5TacS7nMKOC4Uv LPb67ik+J/yIVC9T93JaQKVZMIWsYPfk6aLaM/xi4Gza2EfuMqUR9hYxr4VOLaBYax kNDyJi7ZtyjXj2PmePNkWXEyZbVpmuBdCTZK/D60HkNdkz1C5vgZrJZLRrVGLni1fk cY751tl7X2ToujXIZIQJbnS3WYHfHHaHSSaP8jv181bJw2GOl4BdiSmMNTBmYCwGBb 7NMjxojLnqVHQOhQgccRKNJALmMxfv8cEbSuaIKUMBt3SPTkyUg57kGM6MrIISue54 mgQK8SHYKxNGw== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 6C0AB60128; Sat, 13 Sep 2025 23:59:12 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id 4F10E203A9B; Sat, 13 Sep 2025 23:58:57 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: "Jason A. Donenfeld" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , Donald Hunter , Simon Horman , Jacob Keller , Sabrina Dubroca , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 04/11] tools: ynl-gen: refactor local vars for .attr_put() callers Date: Sat, 13 Sep 2025 23:58:25 +0000 Message-ID: <20250913235847.358851-5-ast@fiberby.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250913235847.358851-1-ast@fiberby.net> References: <20250913235847.358851-1-ast@fiberby.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Refactor the generation of local variables needed when building requests, by moving the logic into the Type classes, and use the same helper in all places where .attr_put() is called. If any attributes requests identical local_vars, then they will be deduplicated, attributes are assumed to only use their local variables transiently. This patch fixes the build errors below: $ make -C tools/net/ynl/generated/ [...] -e GEN wireguard-user.c -e GEN wireguard-user.h -e CC wireguard-user.o wireguard-user.c: In function =E2=80=98wireguard_get_device_dump=E2=80=99: wireguard-user.c:480:9: error: =E2=80=98array=E2=80=99 undeclared (first us= e in func) 480 | array =3D ynl_attr_nest_start(nlh, WGDEVICE_A_PEERS); | ^~~~~ wireguard-user.c:480:9: note: each undeclared identifier is reported only once for each function it appears in wireguard-user.c:481:14: error: =E2=80=98i=E2=80=99 undeclared (first use i= n func) 481 | for (i =3D 0; i < req->_count.peers; i++) | ^ wireguard-user.c: In function =E2=80=98wireguard_set_device=E2=80=99: wireguard-user.c:533:9: error: =E2=80=98array=E2=80=99 undeclared (first us= e in func) 533 | array =3D ynl_attr_nest_start(nlh, WGDEVICE_A_PEERS); | ^~~~~ make: *** [Makefile:52: wireguard-user.o] Error 1 make: Leaving directory '/usr/src/linux/tools/net/ynl/generated' Signed-off-by: Asbj=C3=B8rn Sloth T=C3=B8nnesen --- tools/net/ynl/pyynl/ynl_gen_c.py | 33 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen= _c.py index 3266af19edcd..85b1de6a7fef 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -840,6 +840,9 @@ class TypeArrayNest(Type): '}'] return get_lines, None, local_vars =20 + def attr_put_local_vars(self): + return ['struct nlattr *array;'] + def attr_put(self, ri, var): ri.cw.p(f'array =3D ynl_attr_nest_start(nlh, {self.enum_name});') if self.sub_type in scalars: @@ -2040,6 +2043,18 @@ def put_enum_to_str(family, cw, enum): _put_enum_to_str_helper(cw, enum.render_name, map_name, 'value', enum= =3Denum) =20 =20 +def put_local_vars(struct): + local_vars =3D set() + for _, attr in struct.member_list(): + if attr.presence_type() =3D=3D 'count': + local_vars.add('unsigned int i;') + try: + local_vars |=3D set(attr.attr_put_local_vars()) + except AttributeError: + pass + return list(local_vars) + + def put_req_nested_prototype(ri, struct, suffix=3D';'): func_args =3D ['struct nlmsghdr *nlh', 'unsigned int attr_type', @@ -2062,15 +2077,7 @@ def put_req_nested(ri, struct): init_lines.append(f"hdr =3D ynl_nlmsg_put_extra_header(nlh, {struc= t_sz});") init_lines.append(f"memcpy(hdr, &obj->_hdr, {struct_sz});") =20 - has_anest =3D False - has_count =3D False - for _, arg in struct.member_list(): - has_anest |=3D arg.type =3D=3D 'indexed-array' - has_count |=3D arg.presence_type() =3D=3D 'count' - if has_anest: - local_vars.append('struct nlattr *array;') - if has_count: - local_vars.append('unsigned int i;') + local_vars +=3D put_local_vars(struct) =20 put_req_nested_prototype(ri, struct, suffix=3D'') ri.cw.block_start() @@ -2354,10 +2361,7 @@ def print_req(ri): local_vars +=3D ['size_t hdr_len;', 'void *hdr;'] =20 - for _, attr in ri.struct["request"].member_list(): - if attr.presence_type() =3D=3D 'count': - local_vars +=3D ['unsigned int i;'] - break + local_vars +=3D put_local_vars(ri.struct['request']) =20 print_prototype(ri, direction, terminate=3DFalse) ri.cw.block_start() @@ -2424,6 +2428,9 @@ def print_dump(ri): local_vars +=3D ['size_t hdr_len;', 'void *hdr;'] =20 + if 'request' in ri.op[ri.op_mode]: + local_vars +=3D put_local_vars(ri.struct['request']) + ri.cw.write_func_lvar(local_vars) =20 ri.cw.p('yds.yarg.ys =3D ys;') --=20 2.51.0