Skip to contentSkip to conversation

NFSD: Change ret code of xdr_stream_decode_opaque_fixed

PATCH Superseded Sergey Bashirov 3 participants 3 messages Jul 17, 2025

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFSD: Change ret code of xdr_stream_decode_opaque_fixed

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.

This patch also simplifies the error checking to avoid potential integer promotion issues.

---
 fs/nfsd/blocklayoutxdr.c                                      | 2 +-
 include/linux/nfs_xdr.h                                       | 2 +-
 include/linux/sunrpc/xdr.h                                    | 4 ++--
 .../xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2 | 2 +-
 .../xdrgen/templates/C/struct/decoder/fixed_length_opaque.j2  | 2 +-
 .../xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2 | 2 +-
 6 files changed, 7 insertions(+), 7 deletions(-)
fs/nfsd/blocklayoutxdr.c +1 -1
index 266b2737882e1..2a4dcb428d823 100644
@@ -157,7 +157,7 @@ nfsd4_block_decode_layoutupdate(struct xdr_stream *xdr, struct iomap **iomapp,
 
 		ret = xdr_stream_decode_opaque_fixed(xdr,
 				&bex.vol_id, sizeof(bex.vol_id));
-		if (ret < sizeof(bex.vol_id)) {
+		if (ret) {
 			nfserr = nfserr_bad_xdr;
 			goto fail;
 		}
include/linux/nfs_xdr.h +1 -1
index 67f6632f723b4..dd80163e0140c 100644
@@ -1863,7 +1863,7 @@ static inline int decode_opaque_fixed(struct xdr_stream *xdr,
 				      void *buf, size_t len)
 {
 	ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
-	if (unlikely(ret < 0))
+	if (unlikely(ret))
 		return -EIO;
 	return 0;
 }
include/linux/sunrpc/xdr.h +2 -2
index e3358c630ba18..ffb699a02b17d 100644
@@ -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;
 }
 
 /**
tools/net/sunrpc/xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2 +1 -1
index b4695ece1884b..ea9295f91aecc 100644
@@ -2,5 +2,5 @@
 {% if annotate %}
 	/* member {{ name }} (fixed-length opaque) */
 {% endif %}
-	if (xdr_stream_decode_opaque_fixed(xdr, ptr->{{ name }}, {{ size }}) < 0)
+	if (xdr_stream_decode_opaque_fixed(xdr, ptr->{{ name }}, {{ size }}) != 0)
 		return false;
tools/net/sunrpc/xdrgen/templates/C/struct/decoder/fixed_length_opaque.j2 +1 -1
index b4695ece1884b..ea9295f91aecc 100644
@@ -2,5 +2,5 @@
 {% if annotate %}
 	/* member {{ name }} (fixed-length opaque) */
 {% endif %}
-	if (xdr_stream_decode_opaque_fixed(xdr, ptr->{{ name }}, {{ size }}) < 0)
+	if (xdr_stream_decode_opaque_fixed(xdr, ptr->{{ name }}, {{ size }}) != 0)
 		return false;
tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2 +1 -1
index 8b4ff08c49e5e..bdc7bd24ffb13 100644
@@ -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;
 };
Signature · 1 line
2.43.0
#1 lore raw
Quoted 23 lines · Sergey Bashirov

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.

This patch also simplifies the error checking to avoid potential integer promotion issues.

---
 fs/nfsd/blocklayoutxdr.c                                      | 2 +-
 include/linux/nfs_xdr.h                                       | 2 +-
 include/linux/sunrpc/xdr.h                                    | 4 ++--
 .../xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2 | 2 +-
 .../xdrgen/templates/C/struct/decoder/fixed_length_opaque.j2  | 2 +-
 .../xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2 | 2 +-
 6 files changed, 7 insertions(+), 7 deletions(-)
fs/nfsd/blocklayoutxdr.c +0 -0
index 266b2737882e1..2a4dcb428d823 100644

fs/nfsd/blocklayoutxdr.c nfsd4_block_decode_layoutupdate(struct xdr_stream *xdr, struct iomap **iomapp, · line 160

Quoted 5 lines
fs/nfsd/blocklayoutxdr.c +1 -1
@@ -157,7 +157,7 @@ nfsd4_block_decode_layoutupdate(struct xdr_stream *xdr, struct iomap **iomapp,
 
 		ret = xdr_stream_decode_opaque_fixed(xdr,
 				&bex.vol_id, sizeof(bex.vol_id));
-		if (ret < sizeof(bex.vol_id)) {
+		if (ret) {

I've dropped "nfsd: Implement large extent array support in pNFS" from nfsd-next because of the number of (minor) issues that have been found so far.

Also, I think this patch needs to come before "Implement large extent", and so does the forthcoming patch that moves nfsd4_decode_deviceid4().

So, please rebase this one today's nfsd-next.

include/linux/nfs_xdr.h static inline int decode_opaque_fixed(struct xdr_stream *xdr, · line 1866

Quoted 13 lines
fs/nfsd/blocklayoutxdr.c +0 -0
 			nfserr = nfserr_bad_xdr;
 			goto fail;
 		}
include/linux/nfs_xdr.h +1 -1
index 67f6632f723b4..dd80163e0140c 100644
@@ -1863,7 +1863,7 @@ static inline int decode_opaque_fixed(struct xdr_stream *xdr,
 				      void *buf, size_t len)
 {
 	ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
-	if (unlikely(ret < 0))
+	if (unlikely(ret))

Unless I've misunderstood Dan's bug report, I don't think these call sites need to change ... The compiler should promote the naked integer to the proper integer type so that the less-than comparison is still valid.

Quoted 30 lines
include/linux/nfs_xdr.h +0 -0
 		return -EIO;
 	return 0;
 }
include/linux/sunrpc/xdr.h +2 -2
index e3358c630ba18..ffb699a02b17d 100644
@@ -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;
 }
 
 /**
tools/net/sunrpc/xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2 +0 -0
index b4695ece1884b..ea9295f91aecc 100644

tools/net/sunrpc/xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2 line 5

Quoted 5 lines
tools/net/sunrpc/xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2 +1 -1
@@ -2,5 +2,5 @@
 {% if annotate %}
 	/* member {{ name }} (fixed-length opaque) */
 {% endif %}
-	if (xdr_stream_decode_opaque_fixed(xdr, ptr->{{ name }}, {{ size }}) < 0)
+	if (xdr_stream_decode_opaque_fixed(xdr, ptr->{{ name }}, {{ size }}) != 0)

Ditto.

tools/net/sunrpc/xdrgen/templates/C/struct/decoder/fixed_length_opaque.j2 line 6

Quoted 12 lines
tools/net/sunrpc/xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2 +0 -0
 		return false;
tools/net/sunrpc/xdrgen/templates/C/struct/decoder/fixed_length_opaque.j2 +1 -1
index b4695ece1884b..ea9295f91aecc 100644
@@ -2,5 +2,5 @@
 {% if annotate %}
 	/* member {{ name }} (fixed-length opaque) */
 {% endif %}
-	if (xdr_stream_decode_opaque_fixed(xdr, ptr->{{ name }}, {{ size }}) < 0)
+	if (xdr_stream_decode_opaque_fixed(xdr, ptr->{{ name }}, {{ size }}) != 0)
 		return false;

Ditto.

tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2 xdrgen_decode_{{ name }}(struct xdr_stream *xdr, {{ classifier }}{{ name }} *ptr · line 17

Quoted 11 lines
tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/fixed_length_opaque.j2 +1 -1
index 8b4ff08c49e5e..bdc7bd24ffb13 100644
@@ -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;
 };

The existing comparison will work fine. But "== 0" will match the new return values better. LGTM.

Signature · 1 line
Chuck Lever
#2 lore raw
In reply to Sergey Bashirov

include/linux/nfs_xdr.h static inline int decode_opaque_fixed(struct xdr_stream *xdr, · line 1867

Quoted 11 lines · Sergey Bashirov
include/linux/nfs_xdr.h +1 -1
index 67f6632f723b4..dd80163e0140c 100644
@@ -1863,7 +1863,7 @@ static inline int decode_opaque_fixed(struct xdr_stream *xdr,
 				      void *buf, size_t len)
 {
 	ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
-	if (unlikely(ret < 0))
+	if (unlikely(ret))
 		return -EIO;

We could propagate the error code (-EBADMSG) instead of return -EIO?

regards,
dan carpenter

Quoted 2 lines
include/linux/nfs_xdr.h +0 -0
 	return 0;
 }