Commit 4129ccf3 authored by Chuck Lever's avatar Chuck Lever Committed by Trond Myklebust

SUNRPC: Avoid return code checking in rpcbind XDR encoder functions

Clean up.

The trend in the other XDR encoder functions is to BUG() when encoding
problems occur, since a problem here is always due to a local coding
error.  Then, instead of a status, zero is unconditionally returned.

Update the rpcbind XDR encoders to behave this way.

To finish the update, use the new-style be32_to_cpup() and
cpu_to_be32() macros, and compute the buffer sizes using raw integers
instead of sizeof().  This matches the conventions used in other XDR
functions.
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
Tested-by: default avatarJ. Bruce Fields <bfields@redhat.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent b43cd8c1
...@@ -705,14 +705,11 @@ static int rpcb_enc_mapping(struct rpc_rqst *req, __be32 *p, ...@@ -705,14 +705,11 @@ static int rpcb_enc_mapping(struct rpc_rqst *req, __be32 *p,
xdr_init_encode(&xdr, &req->rq_snd_buf, p); xdr_init_encode(&xdr, &req->rq_snd_buf, p);
p = xdr_reserve_space(&xdr, sizeof(__be32) * RPCB_mappingargs_sz); p = xdr_reserve_space(&xdr, RPCB_mappingargs_sz << 2);
if (unlikely(p == NULL)) *p++ = cpu_to_be32(rpcb->r_prog);
return -EIO; *p++ = cpu_to_be32(rpcb->r_vers);
*p++ = cpu_to_be32(rpcb->r_prot);
*p++ = htonl(rpcb->r_prog); *p = cpu_to_be32(rpcb->r_port);
*p++ = htonl(rpcb->r_vers);
*p++ = htonl(rpcb->r_prot);
*p = htonl(rpcb->r_port);
return 0; return 0;
} }
...@@ -728,11 +725,11 @@ static int rpcb_dec_getport(struct rpc_rqst *req, __be32 *p, ...@@ -728,11 +725,11 @@ static int rpcb_dec_getport(struct rpc_rqst *req, __be32 *p,
rpcb->r_port = 0; rpcb->r_port = 0;
p = xdr_inline_decode(&xdr, sizeof(__be32)); p = xdr_inline_decode(&xdr, 4);
if (unlikely(p == NULL)) if (unlikely(p == NULL))
return -EIO; return -EIO;
port = ntohl(*p); port = be32_to_cpup(p);
dprintk("RPC: %5u PMAP_%s result: %lu\n", task->tk_pid, dprintk("RPC: %5u PMAP_%s result: %lu\n", task->tk_pid,
task->tk_msg.rpc_proc->p_name, port); task->tk_msg.rpc_proc->p_name, port);
if (unlikely(port > USHRT_MAX)) if (unlikely(port > USHRT_MAX))
...@@ -750,7 +747,7 @@ static int rpcb_dec_set(struct rpc_rqst *req, __be32 *p, ...@@ -750,7 +747,7 @@ static int rpcb_dec_set(struct rpc_rqst *req, __be32 *p,
xdr_init_decode(&xdr, &req->rq_rcv_buf, p); xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
p = xdr_inline_decode(&xdr, sizeof(__be32)); p = xdr_inline_decode(&xdr, 4);
if (unlikely(p == NULL)) if (unlikely(p == NULL))
return -EIO; return -EIO;
...@@ -764,24 +761,16 @@ static int rpcb_dec_set(struct rpc_rqst *req, __be32 *p, ...@@ -764,24 +761,16 @@ static int rpcb_dec_set(struct rpc_rqst *req, __be32 *p,
return 0; return 0;
} }
static int encode_rpcb_string(struct xdr_stream *xdr, const char *string, static void encode_rpcb_string(struct xdr_stream *xdr, const char *string,
const u32 maxstrlen) const u32 maxstrlen)
{ {
u32 len;
__be32 *p; __be32 *p;
u32 len;
if (unlikely(string == NULL))
return -EIO;
len = strlen(string); len = strlen(string);
if (unlikely(len > maxstrlen)) BUG_ON(len > maxstrlen);
return -EIO; p = xdr_reserve_space(xdr, 4 + len);
p = xdr_reserve_space(xdr, sizeof(__be32) + len);
if (unlikely(p == NULL))
return -EIO;
xdr_encode_opaque(p, string, len); xdr_encode_opaque(p, string, len);
return 0;
} }
static int rpcb_enc_getaddr(struct rpc_rqst *req, __be32 *p, static int rpcb_enc_getaddr(struct rpc_rqst *req, __be32 *p,
...@@ -797,20 +786,13 @@ static int rpcb_enc_getaddr(struct rpc_rqst *req, __be32 *p, ...@@ -797,20 +786,13 @@ static int rpcb_enc_getaddr(struct rpc_rqst *req, __be32 *p,
xdr_init_encode(&xdr, &req->rq_snd_buf, p); xdr_init_encode(&xdr, &req->rq_snd_buf, p);
p = xdr_reserve_space(&xdr, p = xdr_reserve_space(&xdr, (RPCB_program_sz + RPCB_version_sz) << 2);
sizeof(__be32) * (RPCB_program_sz + RPCB_version_sz)); *p++ = cpu_to_be32(rpcb->r_prog);
if (unlikely(p == NULL)) *p = cpu_to_be32(rpcb->r_vers);
return -EIO;
*p++ = htonl(rpcb->r_prog);
*p = htonl(rpcb->r_vers);
if (encode_rpcb_string(&xdr, rpcb->r_netid, RPCBIND_MAXNETIDLEN))
return -EIO;
if (encode_rpcb_string(&xdr, rpcb->r_addr, RPCBIND_MAXUADDRLEN))
return -EIO;
if (encode_rpcb_string(&xdr, rpcb->r_owner, RPCB_MAXOWNERLEN))
return -EIO;
encode_rpcb_string(&xdr, rpcb->r_netid, RPCBIND_MAXNETIDLEN);
encode_rpcb_string(&xdr, rpcb->r_addr, RPCBIND_MAXUADDRLEN);
encode_rpcb_string(&xdr, rpcb->r_owner, RPCB_MAXOWNERLEN);
return 0; return 0;
} }
...@@ -827,10 +809,10 @@ static int rpcb_dec_getaddr(struct rpc_rqst *req, __be32 *p, ...@@ -827,10 +809,10 @@ static int rpcb_dec_getaddr(struct rpc_rqst *req, __be32 *p,
xdr_init_decode(&xdr, &req->rq_rcv_buf, p); xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
p = xdr_inline_decode(&xdr, sizeof(__be32)); p = xdr_inline_decode(&xdr, 4);
if (unlikely(p == NULL)) if (unlikely(p == NULL))
goto out_fail; goto out_fail;
len = ntohl(*p); len = be32_to_cpup(p);
/* /*
* If the returned universal address is a null string, * If the returned universal address is a null string,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment