diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 78f37f7c3462..83bfedcebc90 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -81,6 +81,9 @@ static char *dmabuffs_dname(struct dentry *dentry, char *buffer, int buflen) static void dma_buf_release(struct dentry *dentry) { struct dma_buf *dmabuf; +#ifdef CONFIG_NO_GKI + int dtor_ret = 0; +#endif dmabuf = dentry->d_fsdata; if (unlikely(!dmabuf)) @@ -99,7 +102,13 @@ static void dma_buf_release(struct dentry *dentry) BUG_ON(dmabuf->cb_shared.active || dmabuf->cb_excl.active); dma_buf_stats_teardown(dmabuf); - dmabuf->ops->release(dmabuf); +#ifdef CONFIG_NO_GKI + if (dmabuf->dtor) + dtor_ret = dmabuf->dtor(dmabuf, dmabuf->dtor_data); + + if (!dtor_ret) +#endif + dmabuf->ops->release(dmabuf); if (dmabuf->resv == (struct dma_resv *)&dmabuf[1]) dma_resv_fini(dmabuf->resv); diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 63ffe57a61d5..d3ad7aeee438 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -359,6 +359,20 @@ struct dma_buf_ops { ANDROID_KABI_RESERVE(2); }; +#ifdef CONFIG_NO_GKI +/** + * 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); +#endif + /** * struct dma_buf - shared buffer object * @size: size of the buffer @@ -425,6 +439,10 @@ struct dma_buf { struct dma_buf *dmabuf; } *sysfs_entry; #endif +#ifdef CONFIG_NO_GKI + dma_buf_destructor dtor; + void *dtor_data; +#endif ANDROID_KABI_RESERVE(1); ANDROID_KABI_RESERVE(2); @@ -626,4 +644,19 @@ void dma_buf_vunmap(struct dma_buf *, void *vaddr); int dma_buf_get_flags(struct dma_buf *dmabuf, unsigned long *flags); int dma_buf_get_uuid(struct dma_buf *dmabuf, uuid_t *uuid); +#ifdef CONFIG_NO_GKI +/** + * 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 #endif /* __DMA_BUF_H__ */