SUNRPC: Add generic helpers for xdr_stream encode/decode
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi Trond,
Quoted 1 line · Linux Kernel Mailing List
Web: https://git.kernel.org/torvalds/c/0ae060ca2bdfe11181094699b0f=
76437ec210b17
Quoted 20 lines
Commit: 0ae060ca2bdfe11181094699b0f76437ec210b17 Parent: 9761a2469dc287c6d75ca148f4fc483becbcad88 Refname: refs/heads/master Author: Trond Myklebust <[email protected]> AuthorDate: Sun Feb 19 16:08:25 2017 -0500 Committer: Anna Schumaker <[email protected]> CommitDate: Tue Feb 21 16:56:16 2017 -0500SUNRPC: Add generic helpers for
xdr_streamencode/decodeAdd some generic helpers for encoding/decoding opaque structures and basic u32/u64.
Signed-off-by Trond Myklebust <[email protected]>Reviewed-by Chuck Lever <[email protected]>Signed-off-by Anna Schumaker <[email protected]>include/linux/sunrpc/xdr.h +0
-0
include/linux/sunrpc/xdr.h
Quoted 10 lines
include/linux/sunrpc/xdr.h +10
-0+/** +* xdr_stream_decode_u32 - Decode a 32-bit integer +* @xdr: pointer to xdr_stream +* @ptr: location to store integer +* +* Return values: +* %0 on success +* %-EBADMSG on XDR buffer overflow +*/ +static inline ssize_t
I think you should either change the return type to "int", or return the length instead of storing it in *ptr, like all other functions returning ssize_t do.
The latter will probably kill the (false positive) compiler warning I'm seeing, too.
Quoted 13 lines
include/linux/sunrpc/xdr.h +13
-0+xdr_stream_decode_u32(struct xdr_stream *xdr, __u32 *ptr) +{ + const size_t count =3D sizeof(*ptr); + __be32 *p =3D xdr_inline_decode(xdr, count); + +if (unlikely (!p)) +return -EBADMSG ; + *ptr =3D be32_to_cpup(p); +return 0 ; +} + +/** +* xdr_stream_decode_opaque_fixed - Decode fixed length opaque xdr data
include/linux/sunrpc/xdr.h
Quoted 10 lines
include/linux/sunrpc/xdr.h +10
-0+* @xdr: pointer to xdr_stream +* @ptr: location to store data +* @len: size of buffer pointed to by @ptr +* +* Return values: +* On success, returns size of object stored in @ptr +* %-EBADMSG on XDR buffer overflow +*/ +static inline ssize_t +xdr_stream_decode_opaque_fixed(struct xdr_stream *xdr, void *ptr, size_t=
len)
include/linux/sunrpc/xdr.h
Quoted 11 lines
include/linux/sunrpc/xdr.h +11
-0+{ + __be32 *p =3D xdr_inline_decode(xdr, len); + +if (unlikely (!p)) +return -EBADMSG ; +xdr_decode_opaque_fixed (p, ptr, len); +return len; +} + +/** +* xdr_stream_decode_opaque_inline - Decode variable length opaque xdr d=
ata
Quoted 5 lines
+ * @xdr: pointer to
xdr_stream
+ * @ptr: location to store pointer to opaque data
+ * @maxlen: maximum acceptable object size
+ *
+ * Note: the pointer stored in @ptr cannot be assumed valid after the XD=
R
include/linux/sunrpc/xdr.h
Quoted 11 lines
+ * buffer has been destroyed, or even after calling
xdr_inline_decode()
+ * on @xdr. It is therefore expected that the object it points to should
+ * be processed immediately.
+ *
+ * Return values:+ * On success, returns size of object stored in *@ptr + * %-EBADMSG on XDR buffer overflow + * %-EMSGSIZE if the size of the object would exceed @maxlen+ */
include/linux/sunrpc/xdr.h +2
-0+static inline ssize_t +xdr_stream_decode_opaque_inline(struct xdr_stream *xdr, void **ptr, size=
_t maxlen)
include/linux/sunrpc/xdr.h
Quoted 7 lines
include/linux/sunrpc/xdr.h +7
-0+{ +__be32 *p; +__u32 len; + + *ptr =3D NULL; +if (unlikely (xdr_stream_decode_u32 (xdr, &len) <0 )) +return -EBADMSG ;
With gcc-4.1.2, which isn't smart enough to derive the relation between the initialization of &len and the return value:
fs/nfs/nfs4xdr.c: In function =E2=80=98decode_opaque_inline=E2=80=99:
include/linux/sunrpc/xdr.h:409: warning: =E2=80=98len=E2=80=99 may be u=sed
uninitialized in this function
include/linux/sunrpc/xdr.h
Quoted 10 lines
include/linux/sunrpc/xdr.h +10
-0+ if (len !=3D 0) { + p =3D xdr_inline_decode(xdr, len); +if (unlikely (!p)) +return -EBADMSG ; +if (unlikely (len > maxlen)) +return -EMSGSIZE ; + *ptr =3D p; + } +return len; +}
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k= .org
In personal conversations with technical people, I call myself a hacker. Bu= t
when I'm talking to journalists I just say "programmer" or something like t= hat.
-- Linus Torvalds