diff mbox series

pwm: Register debugfs operations after the pwm class

Message ID 20240626222529.2901200-2-u.kleine-koenig@baylibre.com
State Accepted
Headers show
Series pwm: Register debugfs operations after the pwm class | expand

Commit Message

Uwe Kleine-König June 26, 2024, 10:25 p.m. UTC
While the debugfs operations don't technically depend on an initialized
class, they loop over the idr that only can get entries when the class
is properly initialized.

This also fixes the ugly (but harmless) corner case that the debugfs
file stays around after the pwm class failed to initialize.

While at it, add an appropriate error message when class initialization
fails.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
 drivers/pwm/core.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)


base-commit: 888564d8d708d1c91900ed3a11761f46297fd748

Comments

Uwe Kleine-König July 5, 2024, 9:34 a.m. UTC | #1
Hello,

On Thu, Jun 27, 2024 at 12:25:27AM +0200, Uwe Kleine-König wrote:
> While the debugfs operations don't technically depend on an initialized
> class, they loop over the idr that only can get entries when the class
> is properly initialized.
> 
> This also fixes the ugly (but harmless) corner case that the debugfs
> file stays around after the pwm class failed to initialize.
> 
> While at it, add an appropriate error message when class initialization
> fails.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>

Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-next
.

Best regards
Uwe
diff mbox series

Patch

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 5c1d20985148..84ca846120a2 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -1705,9 +1705,17 @@  DEFINE_SEQ_ATTRIBUTE(pwm_debugfs);
 
 static int __init pwm_init(void)
 {
+	int ret;
+
+	ret = class_register(&pwm_class);
+	if (ret) {
+		pr_err("Failed to initialize PWM class (%pe)\n", ERR_PTR(ret));
+		return ret;
+	}
+
 	if (IS_ENABLED(CONFIG_DEBUG_FS))
 		debugfs_create_file("pwm", 0444, NULL, NULL, &pwm_debugfs_fops);
 
-	return class_register(&pwm_class);
+	return 0;
 }
 subsys_initcall(pwm_init);