driver core: add local subsys_get and subsys_put functions
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 8 Feb 2023 11:13:10 +0000 (12:13 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Feb 2023 09:42:57 +0000 (10:42 +0100)
We need to control the reference count of the subsys private structure
instead of directly manipulating the kset reference count of it, so wrap
that logic up in a subsys_get() and subsys_put() function to make it more
obvious as to what is happening.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Link: https://lore.kernel.org/r/20230208111330.439504-2-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/base.h

index 0e806f6410790075d533e8d5379e4951a31db7d2..9e06c18c7a644226c8ba2ade8f7cb794c03cf5e3 100644 (file)
@@ -57,6 +57,19 @@ struct subsys_private {
 };
 #define to_subsys_private(obj) container_of_const(obj, struct subsys_private, subsys.kobj)
 
+static inline struct subsys_private *subsys_get(struct subsys_private *sp)
+{
+       if (sp)
+               kset_get(&sp->subsys);
+       return sp;
+}
+
+static inline void subsys_put(struct subsys_private *sp)
+{
+       if (sp)
+               kset_put(&sp->subsys);
+}
+
 struct driver_private {
        struct kobject kobj;
        struct klist klist_devices;