Skip to content

Commit 69de442

Browse files
gfxstranddanvet
authored andcommitted
drm/ttm: Initialize debugfs from ttm_global_init()
We create a bunch of debugfs entries as a side-effect of ttm_global_init() and then never clean them up. This isn't usually a problem because we free the whole debugfs directory on module unload. However, if the global reference count ever goes to zero and then ttm_global_init() is called again, we'll re-create those debugfs entries and debugfs will complain in dmesg that we're creating entries that already exist. This patch fixes this problem by changing the lifetime of the whole TTM debugfs directory to match that of the TTM global state. Signed-off-by: Jason Ekstrand <[email protected]> Reviewed-by: Daniel Vetter <[email protected]> Signed-off-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 7bbcb91 commit 69de442

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

drivers/gpu/drm/ttm/ttm_device.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ static unsigned ttm_glob_use_count;
4444
struct ttm_global ttm_glob;
4545
EXPORT_SYMBOL(ttm_glob);
4646

47+
struct dentry *ttm_debugfs_root;
48+
4749
static void ttm_global_release(void)
4850
{
4951
struct ttm_global *glob = &ttm_glob;
@@ -53,6 +55,7 @@ static void ttm_global_release(void)
5355
goto out;
5456

5557
ttm_pool_mgr_fini();
58+
debugfs_remove(ttm_debugfs_root);
5659

5760
__free_page(glob->dummy_read_page);
5861
memset(glob, 0, sizeof(*glob));
@@ -73,6 +76,13 @@ static int ttm_global_init(void)
7376

7477
si_meminfo(&si);
7578

79+
ttm_debugfs_root = debugfs_create_dir("ttm", NULL);
80+
if (IS_ERR(ttm_debugfs_root)) {
81+
ret = PTR_ERR(ttm_debugfs_root);
82+
ttm_debugfs_root = NULL;
83+
goto out;
84+
}
85+
7686
/* Limit the number of pages in the pool to about 50% of the total
7787
* system memory.
7888
*/
@@ -100,6 +110,8 @@ static int ttm_global_init(void)
100110
debugfs_create_atomic_t("buffer_objects", 0444, ttm_debugfs_root,
101111
&glob->bo_count);
102112
out:
113+
if (ret && ttm_debugfs_root)
114+
debugfs_remove(ttm_debugfs_root);
103115
if (ret)
104116
--ttm_glob_use_count;
105117
mutex_unlock(&ttm_global_mutex);

drivers/gpu/drm/ttm/ttm_module.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,6 @@ pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp)
7272
return tmp;
7373
}
7474

75-
struct dentry *ttm_debugfs_root;
76-
77-
static int __init ttm_init(void)
78-
{
79-
ttm_debugfs_root = debugfs_create_dir("ttm", NULL);
80-
return 0;
81-
}
82-
83-
static void __exit ttm_exit(void)
84-
{
85-
debugfs_remove(ttm_debugfs_root);
86-
}
87-
88-
module_init(ttm_init);
89-
module_exit(ttm_exit);
90-
9175
MODULE_AUTHOR("Thomas Hellstrom, Jerome Glisse");
9276
MODULE_DESCRIPTION("TTM memory manager subsystem (for DRM device)");
9377
MODULE_LICENSE("GPL and additional rights");

0 commit comments

Comments
 (0)