]> git.karo-electronics.de Git - linux-beck.git/commitdiff
cifs: allocate kvec array for cifs_readdata as a separate allocation
authorJeff Layton <jlayton@redhat.com>
Tue, 18 Sep 2012 23:20:36 +0000 (16:20 -0700)
committerSteve French <smfrench@gmail.com>
Tue, 25 Sep 2012 02:46:31 +0000 (21:46 -0500)
Eventually, we're going to want to append a list of pages to
cifs_readdata instead of a list of kvecs. To prepare for that, turn
the kvec array allocation into a separate one and just keep a
pointer to it in the readdata.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
fs/cifs/cifsglob.h
fs/cifs/file.c

index cc70ac0bac475fb29ab4be072365d5fc0a615bbd..737289b50ca56b550174211a379edffe2ebf70ea 100644 (file)
@@ -982,7 +982,7 @@ struct cifs_readdata {
        int (*marshal_iov) (struct cifs_readdata *rdata,
                            unsigned int remaining);
        unsigned int                    nr_iov;
-       struct kvec                     iov[1];
+       struct kvec                     *iov;
 };
 
 struct cifs_writedata;
index 8a781226ae33eae5bff03ab5d977ebff25069f67..61b7c834069f369f65cbcc8cd154377f14563169 100644 (file)
@@ -2410,19 +2410,27 @@ ssize_t cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov,
 }
 
 static struct cifs_readdata *
-cifs_readdata_alloc(unsigned int nr_vecs, work_func_t complete)
+cifs_readdata_alloc(unsigned int nr_pages, work_func_t complete)
 {
        struct cifs_readdata *rdata;
+       struct kvec *iov;
 
-       rdata = kzalloc(sizeof(*rdata) +
-                       sizeof(struct kvec) * nr_vecs, GFP_KERNEL);
+       iov = kzalloc(sizeof(*iov) * (nr_pages + 1), GFP_KERNEL);
+       if (!iov)
+               return (struct cifs_readdata *)iov;
+
+       rdata = kzalloc(sizeof(*rdata), GFP_KERNEL);
        if (rdata != NULL) {
                kref_init(&rdata->refcount);
                INIT_LIST_HEAD(&rdata->list);
                init_completion(&rdata->done);
                INIT_WORK(&rdata->work, complete);
                INIT_LIST_HEAD(&rdata->pages);
+               rdata->iov = iov;
+       } else {
+               kfree(iov);
        }
+
        return rdata;
 }
 
@@ -2435,6 +2443,7 @@ cifs_readdata_release(struct kref *refcount)
        if (rdata->cfile)
                cifsFileInfo_put(rdata->cfile);
 
+       kfree(rdata->iov);
        kfree(rdata);
 }