summaryrefslogtreecommitdiff
path: root/net/sunrpc/xdr.c
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2013-03-29 15:12:10 +0100
committerJiri Kosina <jkosina@suse.cz>2013-03-29 15:12:21 +0100
commit6aeedba20e82150757f2dd5b896f0e09491a987c (patch)
treed33322d9a9bd8c1b3d16019820a3305c3692385b /net/sunrpc/xdr.c
parent4c43755506ececbe903585265aa8408e937620a1 (diff)
parent6dbe51c251a327e012439c4772097a13df43c5b8 (diff)
downloadlinux-3.10-6aeedba20e82150757f2dd5b896f0e09491a987c.tar.gz
linux-3.10-6aeedba20e82150757f2dd5b896f0e09491a987c.tar.bz2
linux-3.10-6aeedba20e82150757f2dd5b896f0e09491a987c.zip
Merge tag v3.9-rc1 into for-3.9/upstream-fixes
This is done so that I am able to apply fix for commit 0322bd3980b3 ("usb hid quirks for Masterkit MA901 usb radio") which went into 3.9-rc1.
Diffstat (limited to 'net/sunrpc/xdr.c')
-rw-r--r--net/sunrpc/xdr.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index 56055632f15..75edcfad6e2 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -879,6 +879,47 @@ xdr_buf_subsegment(struct xdr_buf *buf, struct xdr_buf *subbuf,
}
EXPORT_SYMBOL_GPL(xdr_buf_subsegment);
+/**
+ * xdr_buf_trim - lop at most "len" bytes off the end of "buf"
+ * @buf: buf to be trimmed
+ * @len: number of bytes to reduce "buf" by
+ *
+ * Trim an xdr_buf by the given number of bytes by fixing up the lengths. Note
+ * that it's possible that we'll trim less than that amount if the xdr_buf is
+ * too small, or if (for instance) it's all in the head and the parser has
+ * already read too far into it.
+ */
+void xdr_buf_trim(struct xdr_buf *buf, unsigned int len)
+{
+ size_t cur;
+ unsigned int trim = len;
+
+ if (buf->tail[0].iov_len) {
+ cur = min_t(size_t, buf->tail[0].iov_len, trim);
+ buf->tail[0].iov_len -= cur;
+ trim -= cur;
+ if (!trim)
+ goto fix_len;
+ }
+
+ if (buf->page_len) {
+ cur = min_t(unsigned int, buf->page_len, trim);
+ buf->page_len -= cur;
+ trim -= cur;
+ if (!trim)
+ goto fix_len;
+ }
+
+ if (buf->head[0].iov_len) {
+ cur = min_t(size_t, buf->head[0].iov_len, trim);
+ buf->head[0].iov_len -= cur;
+ trim -= cur;
+ }
+fix_len:
+ buf->len -= (len - trim);
+}
+EXPORT_SYMBOL_GPL(xdr_buf_trim);
+
static void __read_bytes_from_xdr_buf(struct xdr_buf *subbuf, void *obj, unsigned int len)
{
unsigned int this_len;