Wire the kernfs syscall callback shape (kobject *, const char *)
to the device-level walker. Add device_ktype_populate_one() and
device_ktype_populate_all() adapters that dispatch through
device_sysfs_apply() over dev->kobj.ktype->entries (currently
NULL; the migration commit installs driver_core_sysfs_entries[]).

The adapters early-return when dev->p->dead is set so a populate
racing with device_del() is a no-op.

No behaviour change: the table is empty until the migration commit.

Cc: Greg Kroah-Hartman <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Danilo Krummrich <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Assisted-by: Claude:claude-opus-4.7
Signed-off-by: Pavol Sakac <[email protected]>
---
 drivers/base/core.c | 50 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 46 insertions(+), 4 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index aeb4985eb8838..975b6e0c4dabd 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -33,6 +33,7 @@
 #include <linux/swiotlb.h>
 #include <linux/sysfs.h>
 
+
 #include "base.h"
 #include "physical_location.h"
 #include "power/power.h"
@@ -2841,10 +2842,9 @@ device_sysfs_entries_end(const struct device_sysfs_entry 
*entries)
        return e;
 }
 
-static __maybe_unused int
-device_sysfs_apply(struct device *dev,
-                 const struct device_sysfs_entry *entries,
-                 enum dev_sysfs_action action, const char *name)
+static int device_sysfs_apply(struct device *dev,
+                            const struct device_sysfs_entry *entries,
+                            enum dev_sysfs_action action, const char *name)
 {
        const struct device_sysfs_entry *e;
 
@@ -2972,11 +2972,53 @@ int device_set_sysfs_lazy(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(device_set_sysfs_lazy);
 
+/*
+ * kobj_type populate adapters - thin wrappers from the kobject
+ * callback shape (kobject *, const char *) to the device-level
+ * walker. Both read dev->kobj.ktype->entries (which is currently
+ * NULL until driver_core_sysfs_entries[] is populated below) and
+ * call device_sysfs_apply() with the matching action.
+ *
+ * The walker traverses an empty table today, so these adapters are
+ * no-ops in behavioural terms. They are wired now so that the
+ * ktype plumbing lands as one reviewable unit; subsequent commits
+ * flip rows on without touching dispatch wiring.
+ */
+static int device_ktype_populate_one(struct kobject *kobj, const char *name)
+{
+       struct device *dev = kobj_to_dev(kobj);
+       const struct kobj_type *ktype = dev->kobj.ktype;
+       int ret;
+
+       /* Device is being torn down; do not populate. */
+       if (dev->p->dead)
+               return -ENOENT;
+
+       ret = device_sysfs_apply(dev, ktype ? ktype->entries : NULL,
+                               DEV_SYSFS_ADD_ONE, name);
+       return ret;
+}
+
+static void device_ktype_populate_all(struct kobject *kobj)
+{
+       struct device *dev = kobj_to_dev(kobj);
+       const struct kobj_type *ktype = dev->kobj.ktype;
+
+       /* Device is being torn down; do not populate. */
+       if (dev->p->dead)
+               return;
+
+       device_sysfs_apply(dev, ktype ? ktype->entries : NULL,
+                         DEV_SYSFS_ADD_ALL, NULL);
+}
+
 static const struct kobj_type device_ktype = {
        .release        = device_release,
        .sysfs_ops      = &dev_sysfs_ops,
        .namespace      = device_namespace,
        .get_ownership  = device_get_ownership,
+       .populate       = device_ktype_populate_one,
+       .populate_all   = device_ktype_populate_all,
 };
 
 
-- 
2.47.3




Amazon Web Services Development Center Germany GmbH
Tamara-Danz-Str. 13
10243 Berlin
Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger
Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597


Reply via email to