aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cifs/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/cifs/misc.c')
-rw-r--r--fs/cifs/misc.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index 1e1626a2cfc3..0dc6f08020ac 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -789,6 +789,11 @@ cifs_aio_ctx_alloc(void)
789{ 789{
790 struct cifs_aio_ctx *ctx; 790 struct cifs_aio_ctx *ctx;
791 791
792 /*
793 * Must use kzalloc to initialize ctx->bv to NULL and ctx->direct_io
794 * to false so that we know when we have to unreference pages within
795 * cifs_aio_ctx_release()
796 */
792 ctx = kzalloc(sizeof(struct cifs_aio_ctx), GFP_KERNEL); 797 ctx = kzalloc(sizeof(struct cifs_aio_ctx), GFP_KERNEL);
793 if (!ctx) 798 if (!ctx)
794 return NULL; 799 return NULL;
@@ -807,7 +812,23 @@ cifs_aio_ctx_release(struct kref *refcount)
807 struct cifs_aio_ctx, refcount); 812 struct cifs_aio_ctx, refcount);
808 813
809 cifsFileInfo_put(ctx->cfile); 814 cifsFileInfo_put(ctx->cfile);
810 kvfree(ctx->bv); 815
816 /*
817 * ctx->bv is only set if setup_aio_ctx_iter() was call successfuly
818 * which means that iov_iter_get_pages() was a success and thus that
819 * we have taken reference on pages.
820 */
821 if (ctx->bv) {
822 unsigned i;
823
824 for (i = 0; i < ctx->npages; i++) {
825 if (ctx->should_dirty)
826 set_page_dirty(ctx->bv[i].bv_page);
827 put_page(ctx->bv[i].bv_page);
828 }
829 kvfree(ctx->bv);
830 }
831
811 kfree(ctx); 832 kfree(ctx);
812} 833}
813 834