aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/sunrpc
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2020-03-02 15:01:08 -0500
committerChuck Lever <chuck.lever@oracle.com>2020-03-16 12:04:31 -0400
commit96f194b715b61b11f0184c776a1283df8e152033 (patch)
treee5949219bda4aa34a9e52972b17dd41d02ecd5dc /include/linux/sunrpc
parentsvcrdma: Fix double svc_rdma_send_ctxt_put() in an error path (diff)
downloadlinux-dev-96f194b715b61b11f0184c776a1283df8e152033.tar.xz
linux-dev-96f194b715b61b11f0184c776a1283df8e152033.zip
SUNRPC: Add xdr_pad_size() helper
Introduce a helper function to compute the XDR pad size of a variable-length XDR object. Clean up: Replace open-coded calculation of XDR pad sizes. I'm sure I haven't found every instance of this calculation. Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Diffstat (limited to 'include/linux/sunrpc')
-rw-r--r--include/linux/sunrpc/xdr.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
index b41f34977995..83cd9f15c526 100644
--- a/include/linux/sunrpc/xdr.h
+++ b/include/linux/sunrpc/xdr.h
@@ -301,6 +301,21 @@ xdr_align_size(size_t n)
}
/**
+ * xdr_pad_size - Calculate size of an object's pad
+ * @n: Size of an object being XDR encoded (in bytes)
+ *
+ * This implementation avoids the need for conditional
+ * branches or modulo division.
+ *
+ * Return value:
+ * Size (in bytes) of the needed XDR pad
+ */
+static inline size_t xdr_pad_size(size_t n)
+{
+ return xdr_align_size(n) - n;
+}
+
+/**
* xdr_stream_encode_u32 - Encode a 32-bit integer
* @xdr: pointer to xdr_stream
* @n: integer to encode