diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2010-12-14 09:58:59 -0500 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2010-12-16 12:37:25 -0500 |
commit | 4129ccf303593a1922a934697f99e682ff491504 (patch) | |
tree | e0ad1d8e560b19b8e214f69a2608eccd0f791423 /net/sunrpc/rpcb_clnt.c | |
parent | b43cd8c153f6902100ed50c1f7e11a470c73a73f (diff) |
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: Chuck Lever <chuck.lever@oracle.com>
Tested-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'net/sunrpc/rpcb_clnt.c')
-rw-r--r-- | net/sunrpc/rpcb_clnt.c | 60 |
1 files changed, 21 insertions, 39 deletions
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c index fa6d7ca2c851..d2a2ea090f95 100644 --- a/net/sunrpc/rpcb_clnt.c +++ b/net/sunrpc/rpcb_clnt.c | |||
@@ -705,14 +705,11 @@ static int rpcb_enc_mapping(struct rpc_rqst *req, __be32 *p, | |||
705 | 705 | ||
706 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 706 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
707 | 707 | ||
708 | p = xdr_reserve_space(&xdr, sizeof(__be32) * RPCB_mappingargs_sz); | 708 | p = xdr_reserve_space(&xdr, RPCB_mappingargs_sz << 2); |
709 | if (unlikely(p == NULL)) | 709 | *p++ = cpu_to_be32(rpcb->r_prog); |
710 | return -EIO; | 710 | *p++ = cpu_to_be32(rpcb->r_vers); |
711 | 711 | *p++ = cpu_to_be32(rpcb->r_prot); | |
712 | *p++ = htonl(rpcb->r_prog); | 712 | *p = cpu_to_be32(rpcb->r_port); |
713 | *p++ = htonl(rpcb->r_vers); | ||
714 | *p++ = htonl(rpcb->r_prot); | ||
715 | *p = htonl(rpcb->r_port); | ||
716 | 713 | ||
717 | return 0; | 714 | return 0; |
718 | } | 715 | } |
@@ -728,11 +725,11 @@ static int rpcb_dec_getport(struct rpc_rqst *req, __be32 *p, | |||
728 | 725 | ||
729 | rpcb->r_port = 0; | 726 | rpcb->r_port = 0; |
730 | 727 | ||
731 | p = xdr_inline_decode(&xdr, sizeof(__be32)); | 728 | p = xdr_inline_decode(&xdr, 4); |
732 | if (unlikely(p == NULL)) | 729 | if (unlikely(p == NULL)) |
733 | return -EIO; | 730 | return -EIO; |
734 | 731 | ||
735 | port = ntohl(*p); | 732 | port = be32_to_cpup(p); |
736 | dprintk("RPC: %5u PMAP_%s result: %lu\n", task->tk_pid, | 733 | dprintk("RPC: %5u PMAP_%s result: %lu\n", task->tk_pid, |
737 | task->tk_msg.rpc_proc->p_name, port); | 734 | task->tk_msg.rpc_proc->p_name, port); |
738 | if (unlikely(port > USHRT_MAX)) | 735 | if (unlikely(port > USHRT_MAX)) |
@@ -750,7 +747,7 @@ static int rpcb_dec_set(struct rpc_rqst *req, __be32 *p, | |||
750 | 747 | ||
751 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | 748 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
752 | 749 | ||
753 | p = xdr_inline_decode(&xdr, sizeof(__be32)); | 750 | p = xdr_inline_decode(&xdr, 4); |
754 | if (unlikely(p == NULL)) | 751 | if (unlikely(p == NULL)) |
755 | return -EIO; | 752 | return -EIO; |
756 | 753 | ||
@@ -764,24 +761,16 @@ static int rpcb_dec_set(struct rpc_rqst *req, __be32 *p, | |||
764 | return 0; | 761 | return 0; |
765 | } | 762 | } |
766 | 763 | ||
767 | static int encode_rpcb_string(struct xdr_stream *xdr, const char *string, | 764 | static void encode_rpcb_string(struct xdr_stream *xdr, const char *string, |
768 | const u32 maxstrlen) | 765 | const u32 maxstrlen) |
769 | { | 766 | { |
770 | u32 len; | ||
771 | __be32 *p; | 767 | __be32 *p; |
768 | u32 len; | ||
772 | 769 | ||
773 | if (unlikely(string == NULL)) | ||
774 | return -EIO; | ||
775 | len = strlen(string); | 770 | len = strlen(string); |
776 | if (unlikely(len > maxstrlen)) | 771 | BUG_ON(len > maxstrlen); |
777 | return -EIO; | 772 | p = xdr_reserve_space(xdr, 4 + len); |
778 | |||
779 | p = xdr_reserve_space(xdr, sizeof(__be32) + len); | ||
780 | if (unlikely(p == NULL)) | ||
781 | return -EIO; | ||
782 | xdr_encode_opaque(p, string, len); | 773 | xdr_encode_opaque(p, string, len); |
783 | |||
784 | return 0; | ||
785 | } | 774 | } |
786 | 775 | ||
787 | static int rpcb_enc_getaddr(struct rpc_rqst *req, __be32 *p, | 776 | 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 | 786 | ||
798 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 787 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
799 | 788 | ||
800 | p = xdr_reserve_space(&xdr, | 789 | p = xdr_reserve_space(&xdr, (RPCB_program_sz + RPCB_version_sz) << 2); |
801 | sizeof(__be32) * (RPCB_program_sz + RPCB_version_sz)); | 790 | *p++ = cpu_to_be32(rpcb->r_prog); |
802 | if (unlikely(p == NULL)) | 791 | *p = cpu_to_be32(rpcb->r_vers); |
803 | return -EIO; | ||
804 | *p++ = htonl(rpcb->r_prog); | ||
805 | *p = htonl(rpcb->r_vers); | ||
806 | |||
807 | if (encode_rpcb_string(&xdr, rpcb->r_netid, RPCBIND_MAXNETIDLEN)) | ||
808 | return -EIO; | ||
809 | if (encode_rpcb_string(&xdr, rpcb->r_addr, RPCBIND_MAXUADDRLEN)) | ||
810 | return -EIO; | ||
811 | if (encode_rpcb_string(&xdr, rpcb->r_owner, RPCB_MAXOWNERLEN)) | ||
812 | return -EIO; | ||
813 | 792 | ||
793 | encode_rpcb_string(&xdr, rpcb->r_netid, RPCBIND_MAXNETIDLEN); | ||
794 | encode_rpcb_string(&xdr, rpcb->r_addr, RPCBIND_MAXUADDRLEN); | ||
795 | encode_rpcb_string(&xdr, rpcb->r_owner, RPCB_MAXOWNERLEN); | ||
814 | return 0; | 796 | return 0; |
815 | } | 797 | } |
816 | 798 | ||
@@ -827,10 +809,10 @@ static int rpcb_dec_getaddr(struct rpc_rqst *req, __be32 *p, | |||
827 | 809 | ||
828 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | 810 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
829 | 811 | ||
830 | p = xdr_inline_decode(&xdr, sizeof(__be32)); | 812 | p = xdr_inline_decode(&xdr, 4); |
831 | if (unlikely(p == NULL)) | 813 | if (unlikely(p == NULL)) |
832 | goto out_fail; | 814 | goto out_fail; |
833 | len = ntohl(*p); | 815 | len = be32_to_cpup(p); |
834 | 816 | ||
835 | /* | 817 | /* |
836 | * If the returned universal address is a null string, | 818 | * If the returned universal address is a null string, |