From 6f14c02220c791d5c46b0f965b9340c58f3d503d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 31 Mar 2023 11:33:13 +0200 Subject: driver core: create class_is_registered() Some classes (i.e. gpio), want to know if they have been registered or not, and poke around in the class's internal structures to try to figure this out. Because this is not really a good idea, provide a function for classes to call to try to figure this out. Note, this is racy as the state of the class could change at any moment in time after the call is made, but as usually a class only wants to know if it has been registered yet or not, it should be fairly safe to use, and is just as safe as the previous "poke at the class internals" check was. Move the gpiolib code to use this function as proof that it works properly. Cc: Bartosz Golaszewski Cc: Sebastian Reichel Cc: Benjamin Tissoires Cc: linux-gpio@vger.kernel.org Reviewed-by: Linus Walleij Reviewed-by: Rafael J. Wysocki Link: https://lore.kernel.org/r/20230331093318.82288-2-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- include/linux/device/class.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/linux/device/class.h b/include/linux/device/class.h index b53728ca56fb..9cb5db0588c8 100644 --- a/include/linux/device/class.h +++ b/include/linux/device/class.h @@ -84,6 +84,7 @@ extern struct kobject *sysfs_dev_block_kobj; int __must_check class_register(struct class *class); void class_unregister(const struct class *class); +bool class_is_registered(const struct class *class); struct class_compat; struct class_compat *class_compat_register(const char *name); -- cgit v1.2.3