git: fc0a5ae09430 - main - linuxkpi: Add device under parent, not under class

From: Jean-Sébastien Pédron <dumbbell_at_FreeBSD.org>
Date: Wed, 09 Sep 2026 20:34:37 UTC
The branch main has been updated by dumbbell:

URL: https://cgit.FreeBSD.org/src/commit/?id=fc0a5ae094308609927e9c355928d08923278325

commit fc0a5ae094308609927e9c355928d08923278325
Author:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
AuthorDate: 2026-02-08 10:06:37 +0000
Commit:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
CommitDate: 2026-09-09 20:01:26 +0000

    linuxkpi: Add device under parent, not under class
    
    In `device_add()`, the function used to add the given device under its
    class. This is used to build a sysctl tree. We ended up with devices or
    "pseudo" devices (like the output connectors of a GPU). For example with
    an output connector:
    
        sysctl sys.class.drm.card0-DP-1
    
    This device should be added under its parent if it has one. With this
    fix, the same output connector is now:
    
        sysctl sys.device.drmn1.card0.card0-DP-1
    
    Reviewed by:    bz
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D55175
---
 sys/compat/linuxkpi/common/include/linux/device.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/device.h b/sys/compat/linuxkpi/common/include/linux/device.h
index 2913810923f1..a26d07a1e7a3 100644
--- a/sys/compat/linuxkpi/common/include/linux/device.h
+++ b/sys/compat/linuxkpi/common/include/linux/device.h
@@ -458,7 +458,10 @@ device_add(struct device *dev)
 		if (dev->devt == 0)
 			dev->devt = makedev(0, device_get_unit(dev->bsddev));
 	}
-	kobject_add(&dev->kobj, &dev->class->kobj, dev_name(dev));
+	if (dev->parent != NULL)
+		kobject_add(&dev->kobj, &dev->parent->kobj, dev_name(dev));
+	else
+		kobject_add(&dev->kobj, &dev->class->kobj, dev_name(dev));
 
 	if (dev->groups)
 		return (sysfs_create_groups(&dev->kobj, dev->groups));