aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc/sched.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/sunrpc/sched.c')
-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