Commit 8e455145 authored by Christian König's avatar Christian König Committed by Christian König
Browse files

drm/debugfs: rework drm_debugfs_create_files implementation v2



Use managed memory allocation for this. That allows us to not keep
track of all the files any more.

v2: keep drm_debugfs_cleanup(), but rename to drm_debugfs_unregister(),
    we still need to cleanup the symlink

Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230829110115.3442-6-christian.koenig@amd.com


Reviewed-by: default avatarAndi Shyti <andi.shyti@linux.intel.com>
parent ec9c7073
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -99,8 +99,6 @@ void accel_debugfs_register(struct drm_device *dev)
{
	struct drm_minor *minor = dev->accel;

	INIT_LIST_HEAD(&minor->debugfs_list);
	mutex_init(&minor->debugfs_lock);
	minor->debugfs_root = dev->debugfs_root;

	drm_debugfs_create_files(accel_debugfs_list, ACCEL_DEBUGFS_ENTRIES,
+21 −49
Original line number Diff line number Diff line
@@ -234,7 +234,7 @@ EXPORT_SYMBOL(drm_debugfs_gpuva_info);
 *
 * Create a given set of debugfs files represented by an array of
 * &struct drm_info_list in the given root directory. These files will be removed
 * automatically on drm_debugfs_cleanup().
 * automatically on drm_debugfs_dev_fini().
 */
void drm_debugfs_create_files(const struct drm_info_list *files, int count,
			      struct dentry *root, struct drm_minor *minor)
@@ -249,7 +249,7 @@ void drm_debugfs_create_files(const struct drm_info_list *files, int count,
		if (features && !drm_core_check_all_features(dev, features))
			continue;

		tmp = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
		tmp = drmm_kzalloc(dev, sizeof(*tmp), GFP_KERNEL);
		if (tmp == NULL)
			continue;

@@ -258,14 +258,28 @@ void drm_debugfs_create_files(const struct drm_info_list *files, int count,
						0444, root, tmp,
						&drm_debugfs_fops);
		tmp->info_ent = &files[i];

		mutex_lock(&minor->debugfs_lock);
		list_add(&tmp->list, &minor->debugfs_list);
		mutex_unlock(&minor->debugfs_lock);
	}
}
EXPORT_SYMBOL(drm_debugfs_create_files);

int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
			     struct dentry *root, struct drm_minor *minor)
{
	int i;

	for (i = 0; i < count; i++) {
		struct dentry *dent = debugfs_lookup(files[i].name, root);

		if (!dent)
			continue;

		drmm_kfree(minor->dev, d_inode(dent)->i_private);
		debugfs_remove(dent);
	}
	return 0;
}
EXPORT_SYMBOL(drm_debugfs_remove_files);

/**
 * drm_debugfs_dev_init - create debugfs directory for the device
 * @dev: the device which we want to create the directory for
@@ -310,8 +324,6 @@ int drm_debugfs_register(struct drm_minor *minor, int minor_id,
	struct drm_device *dev = minor->dev;
	char name[64];

	INIT_LIST_HEAD(&minor->debugfs_list);
	mutex_init(&minor->debugfs_lock);
	sprintf(name, "%d", minor_id);
	minor->debugfs_symlink = debugfs_create_symlink(name, root,
							dev->unique);
@@ -325,48 +337,8 @@ int drm_debugfs_register(struct drm_minor *minor, int minor_id,
	return 0;
}

int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
			     struct drm_minor *minor)
void drm_debugfs_unregister(struct drm_minor *minor)
{
	struct list_head *pos, *q;
	struct drm_info_node *tmp;
	int i;

	mutex_lock(&minor->debugfs_lock);
	for (i = 0; i < count; i++) {
		list_for_each_safe(pos, q, &minor->debugfs_list) {
			tmp = list_entry(pos, struct drm_info_node, list);
			if (tmp->info_ent == &files[i]) {
				debugfs_remove(tmp->dent);
				list_del(pos);
				kfree(tmp);
			}
		}
	}
	mutex_unlock(&minor->debugfs_lock);
	return 0;
}
EXPORT_SYMBOL(drm_debugfs_remove_files);

static void drm_debugfs_remove_all_files(struct drm_minor *minor)
{
	struct drm_info_node *node, *tmp;

	mutex_lock(&minor->debugfs_lock);
	list_for_each_entry_safe(node, tmp, &minor->debugfs_list, list) {
		debugfs_remove(node->dent);
		list_del(&node->list);
		kfree(node);
	}
	mutex_unlock(&minor->debugfs_lock);
}

void drm_debugfs_cleanup(struct drm_minor *minor)
{
	if (!minor->debugfs_symlink)
		return;

	drm_debugfs_remove_all_files(minor);
	debugfs_remove(minor->debugfs_symlink);
	minor->debugfs_symlink = NULL;
}
+2 −2
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type)
	return 0;

err_debugfs:
	drm_debugfs_cleanup(minor);
	drm_debugfs_unregister(minor);
	return ret;
}

@@ -222,7 +222,7 @@ static void drm_minor_unregister(struct drm_device *dev, enum drm_minor_type typ

	device_del(minor->kdev);
	dev_set_drvdata(minor->kdev, NULL); /* safety belt */
	drm_debugfs_cleanup(minor);
	drm_debugfs_unregister(minor);
}

/*
+2 −2
Original line number Diff line number Diff line
@@ -184,7 +184,7 @@ void drm_debugfs_dev_fini(struct drm_device *dev);
void drm_debugfs_dev_register(struct drm_device *dev);
int drm_debugfs_register(struct drm_minor *minor, int minor_id,
			 struct dentry *root);
void drm_debugfs_cleanup(struct drm_minor *minor);
void drm_debugfs_unregister(struct drm_minor *minor);
void drm_debugfs_connector_add(struct drm_connector *connector);
void drm_debugfs_connector_remove(struct drm_connector *connector);
void drm_debugfs_crtc_add(struct drm_crtc *crtc);
@@ -205,7 +205,7 @@ static inline int drm_debugfs_register(struct drm_minor *minor, int minor_id,
	return 0;
}

static inline void drm_debugfs_cleanup(struct drm_minor *minor)
static inline void drm_debugfs_unregister(struct drm_minor *minor)
{
}

+8 −1
Original line number Diff line number Diff line
@@ -1746,8 +1746,15 @@ static void tegra_dc_early_unregister(struct drm_crtc *crtc)
	unsigned int count = ARRAY_SIZE(debugfs_files);
	struct drm_minor *minor = crtc->dev->primary;
	struct tegra_dc *dc = to_tegra_dc(crtc);
	struct dentry *root;

#ifdef CONFIG_DEBUG_FS
	root = crtc->debugfs_entry;
#else
	root = NULL;
#endif

	drm_debugfs_remove_files(dc->debugfs_files, count, minor);
	drm_debugfs_remove_files(dc->debugfs_files, count, root, minor);
	kfree(dc->debugfs_files);
	dc->debugfs_files = NULL;
}
Loading