]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
pwm: Register debugfs operations after the pwm class
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Wed, 26 Jun 2024 22:25:27 +0000 (00:25 +0200)
committerUwe Kleine-König <ukleinek@kernel.org>
Wed, 10 Jul 2024 15:53:51 +0000 (17:53 +0200)
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>
Link: https://lore.kernel.org/r/20240626222529.2901200-2-u.kleine-koenig@baylibre.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
drivers/pwm/core.c

index 5c1d20985148cd969782d4d5d195dfc0c36da0c0..84ca846120a25d145eb4b88c8b3598097278352a 100644 (file)
@@ -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);