From 51b610b87d018e88fab7e6b1ad68e27e13d2dbf3 Mon Sep 17 00:00:00 2001 From: Vijayanand Jitta Date: Thu, 25 Feb 2021 17:23:25 +0530 Subject: [PATCH] ANDROID: dma-buf: add get_each_dmabuf function Add and export get_each_dmabuf function which helps in traversing the db_list, this will be used by the minidump module to get dmabuf info. Bug: 181203151 Change-Id: Ie24788fcf9cf0a49316cb871dcb9191e8084ccde Signed-off-by: Vijayanand Jitta --- drivers/dma-buf/dma-buf.c | 24 ++++++++++++++++++++++++ include/linux/dma-buf.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 62e5ea655307..0ab865543d1f 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -38,6 +38,30 @@ struct dma_buf_list { static struct dma_buf_list db_list; +/* + * This function helps in traversing the db_list and calls the + * callback function which can extract required info out of each + * dmabuf. + */ +int get_each_dmabuf(int (*callback)(const struct dma_buf *dmabuf, + void *private), void *private) +{ + struct dma_buf *buf; + int ret = mutex_lock_interruptible(&db_list.lock); + + if (ret) + return ret; + + list_for_each_entry(buf, &db_list.head, list_node) { + ret = callback(buf, private); + if (ret) + break; + } + mutex_unlock(&db_list.lock); + return ret; +} +EXPORT_SYMBOL_GPL(get_each_dmabuf); + static char *dmabuffs_dname(struct dentry *dentry, char *buffer, int buflen) { struct dma_buf *dmabuf; diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 893301220f99..f1242b50f627 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -588,6 +588,8 @@ dma_buf_attachment_is_dynamic(struct dma_buf_attachment *attach) return !!attach->importer_ops; } +int get_each_dmabuf(int (*callback)(const struct dma_buf *dmabuf, + void *private), void *private); int is_dma_buf_file(struct file *file); struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, struct device *dev);