Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dma-buf: Do not build debugfs related code when !CONFIG_DEBUG_FS

There is no point in compiling in the list and mutex operations which are
only used from the dma-buf debugfs code, if debugfs is not compiled in.

Put the code in questions behind some kconfig guards and so save some text
and maybe even a pointer per object at runtime when not enabled.

Signed-off-by: Tvrtko Ursulin <tursulin@ursulin.net>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Christian König <christian.koenig@amd.com>
Cc: linux-media@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Cc: linaro-mm-sig@lists.linaro.org
Cc: linux-kernel@vger.kernel.org
Cc: kernel-dev@igalia.com
Reviewed-by: T.J. Mercier <tjmercier@google.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240328145323.68872-1-tursulin@igalia.com

authored by

Tvrtko Ursulin and committed by
Maíra Canal
bfc7bc53 d894ea56

+36 -22
+34 -22
drivers/dma-buf/dma-buf.c
··· 35 35 36 36 static inline int is_dma_buf_file(struct file *); 37 37 38 - struct dma_buf_list { 39 - struct list_head head; 40 - struct mutex lock; 41 - }; 38 + #if IS_ENABLED(CONFIG_DEBUG_FS) 39 + static DEFINE_MUTEX(debugfs_list_mutex); 40 + static LIST_HEAD(debugfs_list); 42 41 43 - static struct dma_buf_list db_list; 42 + static void __dma_buf_debugfs_list_add(struct dma_buf *dmabuf) 43 + { 44 + mutex_lock(&debugfs_list_mutex); 45 + list_add(&dmabuf->list_node, &debugfs_list); 46 + mutex_unlock(&debugfs_list_mutex); 47 + } 48 + 49 + static void __dma_buf_debugfs_list_del(struct dma_buf *dmabuf) 50 + { 51 + if (!dmabuf) 52 + return; 53 + 54 + mutex_lock(&debugfs_list_mutex); 55 + list_del(&dmabuf->list_node); 56 + mutex_unlock(&debugfs_list_mutex); 57 + } 58 + #else 59 + static void __dma_buf_debugfs_list_add(struct dma_buf *dmabuf) 60 + { 61 + } 62 + 63 + static void __dma_buf_debugfs_list_del(struct file *file) 64 + { 65 + } 66 + #endif 44 67 45 68 static char *dmabuffs_dname(struct dentry *dentry, char *buffer, int buflen) 46 69 { ··· 112 89 113 90 static int dma_buf_file_release(struct inode *inode, struct file *file) 114 91 { 115 - struct dma_buf *dmabuf; 116 - 117 92 if (!is_dma_buf_file(file)) 118 93 return -EINVAL; 119 94 120 - dmabuf = file->private_data; 121 - if (dmabuf) { 122 - mutex_lock(&db_list.lock); 123 - list_del(&dmabuf->list_node); 124 - mutex_unlock(&db_list.lock); 125 - } 95 + __dma_buf_debugfs_list_del(file->private_data); 126 96 127 97 return 0; 128 98 } ··· 688 672 file->f_path.dentry->d_fsdata = dmabuf; 689 673 dmabuf->file = file; 690 674 691 - mutex_lock(&db_list.lock); 692 - list_add(&dmabuf->list_node, &db_list.head); 693 - mutex_unlock(&db_list.lock); 675 + __dma_buf_debugfs_list_add(dmabuf); 694 676 695 677 return dmabuf; 696 678 ··· 1625 1611 size_t size = 0; 1626 1612 int ret; 1627 1613 1628 - ret = mutex_lock_interruptible(&db_list.lock); 1614 + ret = mutex_lock_interruptible(&debugfs_list_mutex); 1629 1615 1630 1616 if (ret) 1631 1617 return ret; ··· 1634 1620 seq_printf(s, "%-8s\t%-8s\t%-8s\t%-8s\texp_name\t%-8s\tname\n", 1635 1621 "size", "flags", "mode", "count", "ino"); 1636 1622 1637 - list_for_each_entry(buf_obj, &db_list.head, list_node) { 1623 + list_for_each_entry(buf_obj, &debugfs_list, list_node) { 1638 1624 1639 1625 ret = dma_resv_lock_interruptible(buf_obj->resv, NULL); 1640 1626 if (ret) ··· 1671 1657 1672 1658 seq_printf(s, "\nTotal %d objects, %zu bytes\n", count, size); 1673 1659 1674 - mutex_unlock(&db_list.lock); 1660 + mutex_unlock(&debugfs_list_mutex); 1675 1661 return 0; 1676 1662 1677 1663 error_unlock: 1678 - mutex_unlock(&db_list.lock); 1664 + mutex_unlock(&debugfs_list_mutex); 1679 1665 return ret; 1680 1666 } 1681 1667 ··· 1732 1718 if (IS_ERR(dma_buf_mnt)) 1733 1719 return PTR_ERR(dma_buf_mnt); 1734 1720 1735 - mutex_init(&db_list.lock); 1736 - INIT_LIST_HEAD(&db_list.head); 1737 1721 dma_buf_init_debugfs(); 1738 1722 return 0; 1739 1723 }
+2
include/linux/dma-buf.h
··· 370 370 */ 371 371 struct module *owner; 372 372 373 + #if IS_ENABLED(CONFIG_DEBUG_FS) 373 374 /** @list_node: node for dma_buf accounting and debugging. */ 374 375 struct list_head list_node; 376 + #endif 375 377 376 378 /** @priv: exporter specific private data for this buffer object. */ 377 379 void *priv;