Commit 96df899e authored by Johan Hovold's avatar Johan Hovold Committed by sanglipeng1
Browse files

regulator: core: fix debugfs creation regression

stable inclusion
from stable-v5.10.217
commit 324be157e02944c3c0b7142f4c3637343ce14a38
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAWLXC

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=324be157e02944c3c0b7142f4c3637343ce14a38



--------------------------------

commit 2a4b49bb58123bad6ec0e07b02845f74c23d5e04 upstream.

regulator_get() may sometimes be called more than once for the same
consumer device, something which before commit dbe954d8 ("regulator:
core: Avoid debugfs: Directory ...  already present! error") resulted in
errors being logged.

A couple of recent commits broke the handling of such cases so that
attributes are now erroneously created in the debugfs root directory the
second time a regulator is requested and the log is filled with errors
like:

	debugfs: File 'uA_load' in directory '/' already present!
	debugfs: File 'min_uV' in directory '/' already present!
	debugfs: File 'max_uV' in directory '/' already present!
	debugfs: File 'constraint_flags' in directory '/' already present!

on any further calls.

Fixes: 2715bb11 ("regulator: core: Fix more error checking for debugfs_create_dir()")
Fixes: 08880713 ("regulator: core: Streamline debugfs operations")
Cc: stable@vger.kernel.org
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: default avatarJohan Hovold <johan+linaro@kernel.org>
Link: https://lore.kernel.org/r/20240509133304.8883-1-johan+linaro@kernel.org


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarsanglipeng1 <sanglipeng1@jd.com>
parent 29942c22
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -1751,11 +1751,15 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
		}
	}

	if (err != -EEXIST)
	if (err != -EEXIST) {
		regulator->debugfs = debugfs_create_dir(supply_name, rdev->debugfs);
	if (IS_ERR(regulator->debugfs))
		if (IS_ERR(regulator->debugfs)) {
			rdev_dbg(rdev, "Failed to create debugfs directory\n");
			regulator->debugfs = NULL;
		}
	}

	if (regulator->debugfs) {
		debugfs_create_u32("uA_load", 0444, regulator->debugfs,
				   &regulator->uA_load);
		debugfs_create_u32("min_uV", 0444, regulator->debugfs,
@@ -1764,6 +1768,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
				   &regulator->voltage[PM_SUSPEND_ON].max_uV);
		debugfs_create_file("constraint_flags", 0444, regulator->debugfs,
				    regulator, &constraint_flags_fops);
	}

	/*
	 * Check now if the regulator is an always on regulator - if