BACKPORT: ANDROID: GKI: dma-buf: Add support to set a destructor on a dma-buf
dma-buf destructor support is useful as it allows clients an opportunity to undo any attributes, such as security attributes, they have applied to the dma-buf's memory. The destructor is called when the dma-buf is freed, if the destructor returns an error the dma-buf's exporter release function is not called in order to ensure that memory which has not been properly cleaned up isn't returned to the system. Signed-off-by: Liam Mark <lmark@codeaurora.org> Signed-off-by: Swathi Sridhar <swatsrid@codeaurora.org> [surenb: cherry-picked from: 3af4db1543c9 "dma-buf: Add support to set a destructor on a dma-buf"] Bug: 150611569 Test: build Signed-off-by: Suren Baghdasaryan <surenb@google.com> Change-Id: I2d435b99fb9b1747bc1b32a4e0d484957614a5a3 Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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__ */
|
||||
|
||||
Reference in New Issue
Block a user