diff options
author | Sumit Semwal <sumit.semwal@linaro.org> | 2015-05-05 05:26:15 -0400 |
---|---|---|
committer | Sumit Semwal <sumit.semwal@linaro.org> | 2015-05-13 05:05:57 -0400 |
commit | 9abdffe286c1532a54d5aee31571d3029be4026c (patch) | |
tree | 9a2651def7b2ffea3b4fcb78b8ec0a38e460ab46 /include/linux/dma-buf.h | |
parent | 5ebe6afaf0057ac3eaeb98defd5456894b446d22 (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 'include/linux/dma-buf.h')
-rw-r--r-- | include/linux/dma-buf.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 2f0b431b73e0..f98bd7068d55 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h | |||
@@ -115,6 +115,8 @@ struct dma_buf_ops { | |||
115 | * @attachments: list of dma_buf_attachment that denotes all devices attached. | 115 | * @attachments: list of dma_buf_attachment that denotes all devices attached. |
116 | * @ops: dma_buf_ops associated with this buffer object. | 116 | * @ops: dma_buf_ops associated with this buffer object. |
117 | * @exp_name: name of the exporter; useful for debugging. | 117 | * @exp_name: name of the exporter; useful for debugging. |
118 | * @owner: pointer to exporter module; used for refcounting when exporter is a | ||
119 | * kernel module. | ||
118 | * @list_node: node for dma_buf accounting and debugging. | 120 | * @list_node: node for dma_buf accounting and debugging. |
119 | * @priv: exporter specific private data for this buffer object. | 121 | * @priv: exporter specific private data for this buffer object. |
120 | * @resv: reservation object linked to this dma-buf | 122 | * @resv: reservation object linked to this dma-buf |
@@ -129,6 +131,7 @@ struct dma_buf { | |||
129 | unsigned vmapping_counter; | 131 | unsigned vmapping_counter; |
130 | void *vmap_ptr; | 132 | void *vmap_ptr; |
131 | const char *exp_name; | 133 | const char *exp_name; |
134 | struct module *owner; | ||
132 | struct list_head list_node; | 135 | struct list_head list_node; |
133 | void *priv; | 136 | void *priv; |
134 | struct reservation_object *resv; | 137 | struct reservation_object *resv; |
@@ -164,7 +167,8 @@ struct dma_buf_attachment { | |||
164 | 167 | ||
165 | /** | 168 | /** |
166 | * struct dma_buf_export_info - holds information needed to export a dma_buf | 169 | * struct dma_buf_export_info - holds information needed to export a dma_buf |
167 | * @exp_name: name of the exporting module - useful for debugging. | 170 | * @exp_name: name of the exporter - useful for debugging. |
171 | * @owner: pointer to exporter module - used for refcounting kernel module | ||
168 | * @ops: Attach allocator-defined dma buf ops to the new buffer | 172 | * @ops: Attach allocator-defined dma buf ops to the new buffer |
169 | * @size: Size of the buffer | 173 | * @size: Size of the buffer |
170 | * @flags: mode flags for the file | 174 | * @flags: mode flags for the file |
@@ -176,6 +180,7 @@ struct dma_buf_attachment { | |||
176 | */ | 180 | */ |
177 | struct dma_buf_export_info { | 181 | struct dma_buf_export_info { |
178 | const char *exp_name; | 182 | const char *exp_name; |
183 | struct module *owner; | ||
179 | const struct dma_buf_ops *ops; | 184 | const struct dma_buf_ops *ops; |
180 | size_t size; | 185 | size_t size; |
181 | int flags; | 186 | int flags; |
@@ -187,7 +192,8 @@ struct dma_buf_export_info { | |||
187 | * helper macro for exporters; zeros and fills in most common values | 192 | * helper macro for exporters; zeros and fills in most common values |
188 | */ | 193 | */ |
189 | #define DEFINE_DMA_BUF_EXPORT_INFO(a) \ | 194 | #define DEFINE_DMA_BUF_EXPORT_INFO(a) \ |
190 | struct dma_buf_export_info a = { .exp_name = KBUILD_MODNAME } | 195 | struct dma_buf_export_info a = { .exp_name = KBUILD_MODNAME, \ |
196 | .owner = THIS_MODULE } | ||
191 | 197 | ||
192 | /** | 198 | /** |
193 | * get_dma_buf - convenience wrapper for get_file. | 199 | * get_dma_buf - convenience wrapper for get_file. |