[PATCH v2] sunrpc: Change ret code of xdr_stream_decode_opaque_fixed

Sergey Bashirov posted 1 patch 2 months, 2 weeks ago
include/linux/sunrpc/xdr.h                                    | 4 ++--
.../xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2 | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
[PATCH v2] sunrpc: Change ret code of xdr_stream_decode_opaque_fixed
Posted by Sergey Bashirov 2 months, 2 weeks ago
Since the XDR field is fixed in size, the caller already knows how many
bytes were decoded, on success. Thus, xdr_stream_decode_opaque_fixed()
doesn't need to return that value. And, xdr_stream_decode_u32 and _u64
both return zero on success.

Signed-off-by: Sergey Bashirov <sergeybashirov@gmail.com>
---
Changes in v2:
 - Rebased on nfsd-next
 - Checks for negative return values are not touched

 include/linux/sunrpc/xdr.h                                    | 4 ++--
 .../xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2 | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
index e3358c630ba18..ffb699a02b17d 100644
--- a/include/linux/sunrpc/xdr.h
+++ b/include/linux/sunrpc/xdr.h
@@ -730,7 +730,7 @@ xdr_stream_decode_u64(struct xdr_stream *xdr, __u64 *ptr)
  * @len: size of buffer pointed to by @ptr
  *
  * Return values:
- *   On success, returns size of object stored in @ptr
+ *   %0 on success
  *   %-EBADMSG on XDR buffer overflow
  */
 static inline ssize_t
@@ -741,7 +741,7 @@ xdr_stream_decode_opaque_fixed(struct xdr_stream *xdr, void *ptr, size_t len)
 	if (unlikely(!p))
 		return -EBADMSG;
 	xdr_decode_opaque_fixed(p, ptr, len);
-	return len;
+	return 0;
 }
 
 /**
diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2
index 8b4ff08c49e5e..bdc7bd24ffb13 100644
--- a/tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2
+++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2
@@ -13,5 +13,5 @@ xdrgen_decode_{{ name }}(struct xdr_stream *xdr, {{ classifier }}{{ name }} *ptr
 {% if annotate %}
 	/* (fixed-length opaque) */
 {% endif %}
-	return xdr_stream_decode_opaque_fixed(xdr, ptr, {{ size }}) >= 0;
+	return xdr_stream_decode_opaque_fixed(xdr, ptr, {{ size }}) == 0;
 };
-- 
2.43.0
Re: [PATCH v2] sunrpc: Change ret code of xdr_stream_decode_opaque_fixed
Posted by Chuck Lever 2 months, 2 weeks ago
From: Chuck Lever <chuck.lever@oracle.com>

On Fri, 18 Jul 2025 11:09:56 +0300, Sergey Bashirov wrote:
> Since the XDR field is fixed in size, the caller already knows how many
> bytes were decoded, on success. Thus, xdr_stream_decode_opaque_fixed()
> doesn't need to return that value. And, xdr_stream_decode_u32 and _u64
> both return zero on success.
> 
> 

Applied to nfsd-testing, thanks!

[1/1] sunrpc: Change ret code of xdr_stream_decode_opaque_fixed
      commit: 4f48fa0301a4eceee070baa5ca0f0bb470a2a54e

--
Chuck Lever