All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <cel@kernel.org>
To: NeilBrown <neil@brown.name>, Jeff Layton <jlayton@kernel.org>,
	Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <dai.ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: <linux-nfs@vger.kernel.org>
Subject: [PATCH v1 4/4] xdrgen: Take a union's numeric discriminant width from the declaration
Date: Sat, 24 Oct 2026 21:46:16 -0400	[thread overview]
Message-ID: <20261025014616.22236-5-cel@kernel.org> (raw)
In-Reply-To: <20261025014616.22236-1-cel@kernel.org>

_XdrUnion.max_width() counts the discriminant as one XDR word, while
symbolic_width() takes the discriminant's width from the discriminant
declaration. For a hyper discriminant, or a typedef of one, the _sz
macro therefore emits two words where the numeric width counts one.
program.py compares the numeric widths of each procedure's argument
type to choose the type that the *_MAX_ARGS_SZ macro expands to, so a
union argument with a wide discriminant can lose that comparison to a
narrower type. RFC 4506 restricts the discriminant to int, unsigned
int, bool, and enum, and every in-tree .x file complies, so the
generated headers do not change.

Take the numeric discriminant width from the discriminant declaration
as well, so the two methods agree by construction.

Signed-off-by: Chuck Lever <cel@kernel.org>
---
 tools/net/sunrpc/xdrgen/xdr_ast.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py
index 6b012f0f7a42..a57b5f42da1f 100644
--- a/tools/net/sunrpc/xdrgen/xdr_ast.py
+++ b/tools/net/sunrpc/xdrgen/xdr_ast.py
@@ -514,7 +514,7 @@ class _XdrUnion(_XdrAst):
         if self.default:
             if self.default.arm.max_width() > max_width:
                 max_width = self.default.arm.max_width()
-        return 1 + max_width
+        return self.discriminant.max_width() + max_width
 
     def symbolic_width(self) -> List:
         """Return list containing XDR width of type's components"""
-- 
2.56.0


      parent reply	other threads:[~2026-10-25 16:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-25  1:46 [PATCH v1 0/4] xdrgen fixes Chuck Lever
2026-10-25  1:46 ` [PATCH v1 1/4] xdrgen: Handle a union whose arms are all void Chuck Lever
2026-10-25  1:46 ` [PATCH v1 2/4] xdrgen: Key the width tables by type name only Chuck Lever
2026-10-25  1:46 ` [PATCH v1 3/4] xdrgen: Register optional-data names only for typedefs Chuck Lever
2026-10-25  1:46 ` Chuck Lever [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261025014616.22236-5-cel@kernel.org \
    --to=cel@kernel.org \
    --cc=dai.ngo@oracle.com \
    --cc=jlayton@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.