aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/dma-buf/dma-buf.c
diff options
context:
space:
mode:
authorSumit Semwal <sumit.semwal@linaro.org>2015-05-05 05:26:15 -0400
committerSumit Semwal <sumit.semwal@linaro.org>2015-05-13 05:05:57 -0400
commit9abdffe286c1532a54d5aee31571d3029be4026c (patch)
tree9a2651def7b2ffea3b4fcb78b8ec0a38e460ab46 /drivers/dma-buf/dma-buf.c
parent5ebe6afaf0057ac3eaeb98defd5456894b446d22 (diff)
dma-buf: add ref counting for module as exporter
Add reference counting on a kernel module that exports dma-buf and implements its operations. This prevents the module from being unloaded while DMABUF file is in use. The original patch [1] was submitted by Tomasz Stanislawski, but this is a simpler way to do it. v3: call module_put() as late as possible, per gregkh's comment. v2: move owner to struct dma_buf, and use DEFINE_DMA_BUF_EXPORT_INFO macro to simplify the change. Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org> [1]: https://lkml.org/lkml/2012/8/8/163
Diffstat (limited to 'drivers/dma-buf/dma-buf.c')
-rw-r--r--drivers/dma-buf/dma-buf.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index c5a9138a6a8d..63a9914e42b8 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -29,6 +29,7 @@
29#include <linux/anon_inodes.h> 29#include <linux/anon_inodes.h>
30#include <linux/export.h> 30#include <linux/export.h>
31#include <linux/debugfs.h> 31#include <linux/debugfs.h>
32#include <linux/module.h>
32#include <linux/seq_file.h> 33#include <linux/seq_file.h>
33#include <linux/poll.h> 34#include <linux/poll.h>
34#include <linux/reservation.h> 35#include <linux/reservation.h>
@@ -72,6 +73,7 @@ static int dma_buf_release(struct inode *inode, struct file *file)
72 if (dmabuf->resv == (struct reservation_object *)&dmabuf[1]) 73 if (dmabuf->resv == (struct reservation_object *)&dmabuf[1])
73 reservation_object_fini(dmabuf->resv); 74 reservation_object_fini(dmabuf->resv);
74 75
76 module_put(dmabuf->owner);
75 kfree(dmabuf); 77 kfree(dmabuf);
76 return 0; 78 return 0;
77} 79}
@@ -302,14 +304,20 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
302 return ERR_PTR(-EINVAL); 304 return ERR_PTR(-EINVAL);
303 } 305 }
304 306
307 if (!try_module_get(exp_info->owner))
308 return ERR_PTR(-ENOENT);
309
305 dmabuf = kzalloc(alloc_size, GFP_KERNEL); 310 dmabuf = kzalloc(alloc_size, GFP_KERNEL);
306 if (dmabuf == NULL) 311 if (!dmabuf) {
312 module_put(exp_info->owner);
307 return ERR_PTR(-ENOMEM); 313 return ERR_PTR(-ENOMEM);
314 }
308 315
309 dmabuf->priv = exp_info->priv; 316 dmabuf->priv = exp_info->priv;
310 dmabuf->ops = exp_info->ops; 317 dmabuf->ops = exp_info->ops;
311 dmabuf->size = exp_info->size; 318 dmabuf->size = exp_info->size;
312 dmabuf->exp_name = exp_info->exp_name; 319 dmabuf->exp_name = exp_info->exp_name;
320 dmabuf->owner = exp_info->owner;
313 init_waitqueue_head(&dmabuf->poll); 321 init_waitqueue_head(&dmabuf->poll);
314 dmabuf->cb_excl.poll = dmabuf->cb_shared.poll = &dmabuf->poll; 322 dmabuf->cb_excl.poll = dmabuf->cb_shared.poll = &dmabuf->poll;
315 dmabuf->cb_excl.active = dmabuf->cb_shared.active = 0; 323 dmabuf->cb_excl.active = dmabuf->cb_shared.active = 0;