drivers: base: component: add function to query the bound status
authorHeiko Stuebner <heiko@sntech.de>
Thu, 20 Feb 2025 23:41:40 +0000 (00:41 +0100)
committerHeiko Stuebner <heiko@sntech.de>
Thu, 27 Feb 2025 13:52:37 +0000 (14:52 +0100)
The component helpers already expose the bound status in debugfs, but at
times it might be necessary to also check that state in the kernel and
act differently depending on the result.

For example the shutdown handler of a drm-driver might need to stop
a whole output pipeline if the drm device is up and running, but may
run into problems if that drm-device has never been set up before,
for example because the binding deferred.

So add a little helper that returns the bound status for a componet
device.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20250220234141.2788785-2-heiko@sntech.de
drivers/base/component.c
include/linux/component.h

index 741497324d78ae02afb124f50fa33acc857126d2..d63e01f4851df8b558771aaceb7260a1ff75bfd7 100644 (file)
@@ -569,6 +569,20 @@ void component_master_del(struct device *parent,
 }
 EXPORT_SYMBOL_GPL(component_master_del);
 
+bool component_master_is_bound(struct device *parent,
+       const struct component_master_ops *ops)
+{
+       struct aggregate_device *adev;
+
+       guard(mutex)(&component_mutex);
+       adev = __aggregate_find(parent, ops);
+       if (!adev)
+               return 0;
+
+       return adev->bound;
+}
+EXPORT_SYMBOL_GPL(component_master_is_bound);
+
 static void component_unbind(struct component *component,
        struct aggregate_device *adev, void *data)
 {
index df4aa75c9e7c86e88c95f5729791384104f94fa9..9d6c664012806e7c35b1138657ab02f9b807f343 100644 (file)
@@ -3,7 +3,7 @@
 #define COMPONENT_H
 
 #include <linux/stddef.h>
-
+#include <linux/types.h>
 
 struct device;
 
@@ -90,6 +90,8 @@ int component_compare_dev_name(struct device *dev, void *data);
 
 void component_master_del(struct device *,
        const struct component_master_ops *);
+bool component_master_is_bound(struct device *parent,
+       const struct component_master_ops *ops);
 
 struct component_match;