浏览代码

regulator: Ensure unique regulator debugfs directory names

If multiple regulator devices of the same type exist in a system,
the regulator driver assigns generic names for the regulators it
provides, and debugfs is enabled, the regulator subsystem attempts
to create multiple entries with the same name in the regulator debugfs
directory. This fails for all but the first regulator, resulting in
multiple "Failed to create debugfs directory" log entries.

To avoid the problem, prepend the debugfs directory name for a regulator
with its parent device name if available, but only if no explicit
regulator name was provided.

Cc: Alan Tull <atull@opensource.altera.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Mark Brown <broonie@kernel.org>
Guenter Roeck 11 年之前
父节点
当前提交
a9eaa81307
共有 1 个文件被更改,包括 12 次插入1 次删除
  1. 12 1
      drivers/regulator/core.c

+ 12 - 1
drivers/regulator/core.c

@@ -3502,7 +3502,18 @@ static struct class regulator_class = {
 
 
 static void rdev_init_debugfs(struct regulator_dev *rdev)
 static void rdev_init_debugfs(struct regulator_dev *rdev)
 {
 {
-	rdev->debugfs = debugfs_create_dir(rdev_get_name(rdev), debugfs_root);
+	struct device *parent = rdev->dev.parent;
+	const char *rname = rdev_get_name(rdev);
+	char name[NAME_MAX];
+
+	/* Avoid duplicate debugfs directory names */
+	if (parent && rname == rdev->desc->name) {
+		snprintf(name, sizeof(name), "%s-%s", dev_name(parent),
+			 rname);
+		rname = name;
+	}
+
+	rdev->debugfs = debugfs_create_dir(rname, debugfs_root);
 	if (!rdev->debugfs) {
 	if (!rdev->debugfs) {
 		rdev_warn(rdev, "Failed to create debugfs directory\n");
 		rdev_warn(rdev, "Failed to create debugfs directory\n");
 		return;
 		return;