diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2016-07-18 07:16:22 -0400 |
---|---|---|
committer | Daniel Vetter <daniel.vetter@ffwll.ch> | 2016-07-18 08:10:49 -0400 |
commit | a026df4c5fa6bae8eb03b58be720b911494e3da5 (patch) | |
tree | 9f99bd86fcb75d44b15cf938767c01f403619564 | |
parent | f39c9096d611a904ee5f8eb1bd6943e68a071b74 (diff) |
dma-buf: Release module reference on creation failure
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
-rw-r--r-- | drivers/dma-buf/dma-buf.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 20ce0687b111..ddaee60ae52a 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c | |||
@@ -334,6 +334,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) | |||
334 | struct reservation_object *resv = exp_info->resv; | 334 | struct reservation_object *resv = exp_info->resv; |
335 | struct file *file; | 335 | struct file *file; |
336 | size_t alloc_size = sizeof(struct dma_buf); | 336 | size_t alloc_size = sizeof(struct dma_buf); |
337 | int ret; | ||
337 | 338 | ||
338 | if (!exp_info->resv) | 339 | if (!exp_info->resv) |
339 | alloc_size += sizeof(struct reservation_object); | 340 | alloc_size += sizeof(struct reservation_object); |
@@ -357,8 +358,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) | |||
357 | 358 | ||
358 | dmabuf = kzalloc(alloc_size, GFP_KERNEL); | 359 | dmabuf = kzalloc(alloc_size, GFP_KERNEL); |
359 | if (!dmabuf) { | 360 | if (!dmabuf) { |
360 | module_put(exp_info->owner); | 361 | ret = -ENOMEM; |
361 | return ERR_PTR(-ENOMEM); | 362 | goto err_module; |
362 | } | 363 | } |
363 | 364 | ||
364 | dmabuf->priv = exp_info->priv; | 365 | dmabuf->priv = exp_info->priv; |
@@ -379,8 +380,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) | |||
379 | file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, | 380 | file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, |
380 | exp_info->flags); | 381 | exp_info->flags); |
381 | if (IS_ERR(file)) { | 382 | if (IS_ERR(file)) { |
382 | kfree(dmabuf); | 383 | ret = PTR_ERR(file); |
383 | return ERR_CAST(file); | 384 | goto err_dmabuf; |
384 | } | 385 | } |
385 | 386 | ||
386 | file->f_mode |= FMODE_LSEEK; | 387 | file->f_mode |= FMODE_LSEEK; |
@@ -394,6 +395,12 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) | |||
394 | mutex_unlock(&db_list.lock); | 395 | mutex_unlock(&db_list.lock); |
395 | 396 | ||
396 | return dmabuf; | 397 | return dmabuf; |
398 | |||
399 | err_dmabuf: | ||
400 | kfree(dmabuf); | ||
401 | err_module: | ||
402 | module_put(exp_info->owner); | ||
403 | return ERR_PTR(ret); | ||
397 | } | 404 | } |
398 | EXPORT_SYMBOL_GPL(dma_buf_export); | 405 | EXPORT_SYMBOL_GPL(dma_buf_export); |
399 | 406 | ||