aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-09 18:29:58 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-09 18:29:58 -0400
commitd0b6e0e380d6a32d479120a8b5d98cdff936ec8c (patch)
tree57b584f4ba8504eb39e9f12234fc78db7fff0477 /net
parent5329571b3c978635f6d832cc884fdd61ff94e0da (diff)
parent7a13e932281e7042a592f4f14db0b348199e7aac (diff)
Merge git://git.linux-nfs.org/pub/linux/nfs-2.6
* git://git.linux-nfs.org/pub/linux/nfs-2.6: NFS: Kill the obsolete NFS_PARANOIA NFS: use __set_current_state() sunrpc: fix crash in rpc_malloc() NFS: Clean up NFSv4 XDR error message NFS: NFS client underestimates how large an NFSv4 SETATTR reply can be SUNRPC: Fix pointer arithmetic bug recently introduced in rpc_malloc/free NFS: Remove redundant check in nfs_check_verifier() NFS: Fix a jiffie wraparound issue
Diffstat (limited to 'net')
-rw-r--r--net/sunrpc/sched.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
index 99014516b73c..b011eb625e49 100644
--- a/net/sunrpc/sched.c
+++ b/net/sunrpc/sched.c
@@ -736,6 +736,11 @@ static void rpc_async_schedule(struct work_struct *work)
736 __rpc_execute(container_of(work, struct rpc_task, u.tk_work)); 736 __rpc_execute(container_of(work, struct rpc_task, u.tk_work));
737} 737}
738 738
739struct rpc_buffer {
740 size_t len;
741 char data[];
742};
743
739/** 744/**
740 * rpc_malloc - allocate an RPC buffer 745 * rpc_malloc - allocate an RPC buffer
741 * @task: RPC task that will use this buffer 746 * @task: RPC task that will use this buffer
@@ -754,18 +759,22 @@ static void rpc_async_schedule(struct work_struct *work)
754 */ 759 */
755void *rpc_malloc(struct rpc_task *task, size_t size) 760void *rpc_malloc(struct rpc_task *task, size_t size)
756{ 761{
757 size_t *buf; 762 struct rpc_buffer *buf;
758 gfp_t gfp = RPC_IS_SWAPPER(task) ? GFP_ATOMIC : GFP_NOWAIT; 763 gfp_t gfp = RPC_IS_SWAPPER(task) ? GFP_ATOMIC : GFP_NOWAIT;
759 764
760 size += sizeof(size_t); 765 size += sizeof(struct rpc_buffer);
761 if (size <= RPC_BUFFER_MAXSIZE) 766 if (size <= RPC_BUFFER_MAXSIZE)
762 buf = mempool_alloc(rpc_buffer_mempool, gfp); 767 buf = mempool_alloc(rpc_buffer_mempool, gfp);
763 else 768 else
764 buf = kmalloc(size, gfp); 769 buf = kmalloc(size, gfp);
765 *buf = size; 770
771 if (!buf)
772 return NULL;
773
774 buf->len = size;
766 dprintk("RPC: %5u allocated buffer of size %zu at %p\n", 775 dprintk("RPC: %5u allocated buffer of size %zu at %p\n",
767 task->tk_pid, size, buf); 776 task->tk_pid, size, buf);
768 return ++buf; 777 return &buf->data;
769} 778}
770 779
771/** 780/**
@@ -775,15 +784,18 @@ void *rpc_malloc(struct rpc_task *task, size_t size)
775 */ 784 */
776void rpc_free(void *buffer) 785void rpc_free(void *buffer)
777{ 786{
778 size_t size, *buf = buffer; 787 size_t size;
788 struct rpc_buffer *buf;
779 789
780 if (!buffer) 790 if (!buffer)
781 return; 791 return;
782 size = *buf; 792
783 buf--; 793 buf = container_of(buffer, struct rpc_buffer, data);
794 size = buf->len;
784 795
785 dprintk("RPC: freeing buffer of size %zu at %p\n", 796 dprintk("RPC: freeing buffer of size %zu at %p\n",
786 size, buf); 797 size, buf);
798
787 if (size <= RPC_BUFFER_MAXSIZE) 799 if (size <= RPC_BUFFER_MAXSIZE)
788 mempool_free(buf, rpc_buffer_mempool); 800 mempool_free(buf, rpc_buffer_mempool);
789 else 801 else