dma-buf: Release module reference on creation failure
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 18 Jul 2016 11:16:22 +0000 (12:16 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Mon, 18 Jul 2016 12:10:49 +0000 (14:10 +0200)
If we fail to create the anon file, we need to remember to release the
module reference on the owner.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: linux-media@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Cc: linaro-mm-sig@lists.linaro.org
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1468840582-21469-1-git-send-email-chris@chris-wilson.co.uk
drivers/dma-buf/dma-buf.c

index 20ce068..ddaee60 100644 (file)
@@ -334,6 +334,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
        struct reservation_object *resv = exp_info->resv;
        struct file *file;
        size_t alloc_size = sizeof(struct dma_buf);
+       int ret;
 
        if (!exp_info->resv)
                alloc_size += sizeof(struct reservation_object);
@@ -357,8 +358,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
 
        dmabuf = kzalloc(alloc_size, GFP_KERNEL);
        if (!dmabuf) {
-               module_put(exp_info->owner);
-               return ERR_PTR(-ENOMEM);
+               ret = -ENOMEM;
+               goto err_module;
        }
 
        dmabuf->priv = exp_info->priv;
@@ -379,8 +380,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
        file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf,
                                        exp_info->flags);
        if (IS_ERR(file)) {
-               kfree(dmabuf);
-               return ERR_CAST(file);
+               ret = PTR_ERR(file);
+               goto err_dmabuf;
        }
 
        file->f_mode |= FMODE_LSEEK;
@@ -394,6 +395,12 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
        mutex_unlock(&db_list.lock);
 
        return dmabuf;
+
+err_dmabuf:
+       kfree(dmabuf);
+err_module:
+       module_put(exp_info->owner);
+       return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(dma_buf_export);