mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: Sergey Bashirov <sergeybashirov@gmail.com>,
	Dan Carpenter <dan.carpenter@linaro.org>,
	Jeff Layton <jlayton@kernel.org>, NeilBrown <neil@brown.name>,
	Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] NFSD: Change ret code of xdr_stream_decode_opaque_fixed
Date: Thu, 17 Jul 2025 16:08:07 -0400	[thread overview]
Message-ID: <a7f6e186-ad9c-47eb-88d7-64605d7a7854@oracle.com> (raw)
In-Reply-To: <20250717194838.69200-1-sergeybashirov@gmail.com>

On 7/17/25 3:48 PM, 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.
> 
> This patch also simplifies the error checking to avoid potential integer
> promotion issues.
> 
> Signed-off-by: Sergey Bashirov <sergeybashirov@gmail.com>
> ---
>  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(-)
> 
> diff --git a/fs/nfsd/blocklayoutxdr.c b/fs/nfsd/blocklayoutxdr.c
> index 266b2737882e1..2a4dcb428d823 100644
> --- a/fs/nfsd/blocklayoutxdr.c
> +++ b/fs/nfsd/blocklayoutxdr.c
> @@ -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.


>  			nfserr = nfserr_bad_xdr;
>  			goto fail;
>  		}
> diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
> index 67f6632f723b4..dd80163e0140c 100644
> --- a/include/linux/nfs_xdr.h
> +++ b/include/linux/nfs_xdr.h
> @@ -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.


>  		return -EIO;
>  	return 0;
>  }
> 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/pointer/decoder/fixed_length_opaque.j2 b/tools/net/sunrpc/xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2
> index b4695ece1884b..ea9295f91aecc 100644
> --- a/tools/net/sunrpc/xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2
> +++ b/tools/net/sunrpc/xdrgen/templates/C/pointer/decoder/fixed_length_opaque.j2
> @@ -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.


>  		return false;
> diff --git a/tools/net/sunrpc/xdrgen/templates/C/struct/decoder/fixed_length_opaque.j2 b/tools/net/sunrpc/xdrgen/templates/C/struct/decoder/fixed_length_opaque.j2
> index b4695ece1884b..ea9295f91aecc 100644
> --- a/tools/net/sunrpc/xdrgen/templates/C/struct/decoder/fixed_length_opaque.j2
> +++ b/tools/net/sunrpc/xdrgen/templates/C/struct/decoder/fixed_length_opaque.j2
> @@ -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.


> 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;
>  };

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


-- 
Chuck Lever

  reply	other threads:[~2025-07-17 20:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-17 19:48 Sergey Bashirov
2025-07-17 20:08 ` Chuck Lever [this message]
2025-07-17 20:42 ` Dan Carpenter

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=a7f6e186-ad9c-47eb-88d7-64605d7a7854@oracle.com \
    --to=chuck.lever@oracle.com \
    --cc=Dai.Ngo@oracle.com \
    --cc=dan.carpenter@linaro.org \
    --cc=jlayton@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=sergeybashirov@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®