Loading drivers/dma-buf/dma-buf.c +9 −1 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ static struct dma_buf_list db_list; static int dma_buf_release(struct inode *inode, struct file *file) { struct dma_buf *dmabuf; int dtor_ret = 0; if (!is_dma_buf_file(file)) return -EINVAL; Loading @@ -91,7 +92,14 @@ static int dma_buf_release(struct inode *inode, struct file *file) list_del(&dmabuf->list_node); mutex_unlock(&db_list.lock); if (dmabuf->dtor) dtor_ret = dmabuf->dtor(dmabuf, dmabuf->dtor_data); if (!dtor_ret) dmabuf->ops->release(dmabuf); else pr_warn_ratelimited("Leaking dmabuf %s because destructor failed error:%d\n", dmabuf->name, dtor_ret); dma_buf_ref_destroy(dmabuf); Loading include/linux/dma-buf.h +28 −0 Original line number Diff line number Diff line Loading @@ -371,6 +371,18 @@ struct dma_buf_ops { int (*get_flags)(struct dma_buf *dmabuf, unsigned long *flags); }; /** * dma_buf_destructor - dma-buf destructor function * @dmabuf: [in] pointer to dma-buf * @dtor_data: [in] destructor data associated with this buffer * * The dma-buf destructor which is called when the dma-buf is freed. * * If the destructor returns an error the dma-buf's exporter release function * won't be called. */ typedef int (*dma_buf_destructor)(struct dma_buf *dmabuf, void *dtor_data); /** * struct dma_buf - shared buffer object * @size: size of the buffer Loading Loading @@ -428,6 +440,8 @@ struct dma_buf { } cb_excl, cb_shared; struct list_head refs; dma_buf_destructor dtor; void *dtor_data; }; /** Loading Loading @@ -537,4 +551,18 @@ int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *, void *dma_buf_vmap(struct dma_buf *); void dma_buf_vunmap(struct dma_buf *, void *vaddr); int dma_buf_get_flags(struct dma_buf *dma_buf, unsigned long *flags); /** * dma_buf_set_destructor - set the dma-buf's destructor * @dmabuf: [in] pointer to dma-buf * @dma_buf_destructor [in] the destructor function * @dtor_data: [in] destructor data associated with this buffer */ static inline void dma_buf_set_destructor(struct dma_buf *dmabuf, dma_buf_destructor dtor, void *dtor_data) { dmabuf->dtor = dtor; dmabuf->dtor_data = dtor_data; } #endif /* __DMA_BUF_H__ */ Loading
drivers/dma-buf/dma-buf.c +9 −1 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ static struct dma_buf_list db_list; static int dma_buf_release(struct inode *inode, struct file *file) { struct dma_buf *dmabuf; int dtor_ret = 0; if (!is_dma_buf_file(file)) return -EINVAL; Loading @@ -91,7 +92,14 @@ static int dma_buf_release(struct inode *inode, struct file *file) list_del(&dmabuf->list_node); mutex_unlock(&db_list.lock); if (dmabuf->dtor) dtor_ret = dmabuf->dtor(dmabuf, dmabuf->dtor_data); if (!dtor_ret) dmabuf->ops->release(dmabuf); else pr_warn_ratelimited("Leaking dmabuf %s because destructor failed error:%d\n", dmabuf->name, dtor_ret); dma_buf_ref_destroy(dmabuf); Loading
include/linux/dma-buf.h +28 −0 Original line number Diff line number Diff line Loading @@ -371,6 +371,18 @@ struct dma_buf_ops { int (*get_flags)(struct dma_buf *dmabuf, unsigned long *flags); }; /** * dma_buf_destructor - dma-buf destructor function * @dmabuf: [in] pointer to dma-buf * @dtor_data: [in] destructor data associated with this buffer * * The dma-buf destructor which is called when the dma-buf is freed. * * If the destructor returns an error the dma-buf's exporter release function * won't be called. */ typedef int (*dma_buf_destructor)(struct dma_buf *dmabuf, void *dtor_data); /** * struct dma_buf - shared buffer object * @size: size of the buffer Loading Loading @@ -428,6 +440,8 @@ struct dma_buf { } cb_excl, cb_shared; struct list_head refs; dma_buf_destructor dtor; void *dtor_data; }; /** Loading Loading @@ -537,4 +551,18 @@ int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *, void *dma_buf_vmap(struct dma_buf *); void dma_buf_vunmap(struct dma_buf *, void *vaddr); int dma_buf_get_flags(struct dma_buf *dma_buf, unsigned long *flags); /** * dma_buf_set_destructor - set the dma-buf's destructor * @dmabuf: [in] pointer to dma-buf * @dma_buf_destructor [in] the destructor function * @dtor_data: [in] destructor data associated with this buffer */ static inline void dma_buf_set_destructor(struct dma_buf *dmabuf, dma_buf_destructor dtor, void *dtor_data) { dmabuf->dtor = dtor; dmabuf->dtor_data = dtor_data; } #endif /* __DMA_BUF_H__ */