Merge tag 'driver-core-4.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / include / linux / kobject.h
index b49ff230beba19078e8f973f04668ca659382a94..1ab0d624fb36ea0f5ad679dc5fa4e0f780a9d58a 100644 (file)
@@ -119,6 +119,23 @@ extern void kobject_get_ownership(struct kobject *kobj,
                                  kuid_t *uid, kgid_t *gid);
 extern char *kobject_get_path(struct kobject *kobj, gfp_t flag);
 
+/**
+ * kobject_has_children - Returns whether a kobject has children.
+ * @kobj: the object to test
+ *
+ * This will return whether a kobject has other kobjects as children.
+ *
+ * It does NOT account for the presence of attribute files, only sub
+ * directories. It also assumes there is no concurrent addition or
+ * removal of such children, and thus relies on external locking.
+ */
+static inline bool kobject_has_children(struct kobject *kobj)
+{
+       WARN_ON_ONCE(kref_read(&kobj->kref) == 0);
+
+       return kobj->sd && kobj->sd->dir.subdirs;
+}
+
 struct kobj_type {
        void (*release)(struct kobject *kobj);
        const struct sysfs_ops *sysfs_ops;