The branch main has been updated by dumbbell:

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

commit 7e5d7b0e8198beb97de040c64ee327a982201073
Author:     Jean-Sébastien Pédron <dumbb...@freebsd.org>
AuthorDate: 2025-06-18 20:37:10 +0000
Commit:     Jean-Sébastien Pédron <dumbb...@freebsd.org>
CommitDate: 2025-08-09 12:26:23 +0000

    linuxkpi: Add `sysfs_add_file_to_group()` and 
`sysfs_remove_file_from_group()`
    
    They are used by the amdgpu DRM driver for quite some time, but new code
    using them added to Linux 6.9 made me discover that these functions were
    missing and existing code was commentted out.
    
    Reviewed by:    manu
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D50987
---
 sys/compat/linuxkpi/common/include/linux/sysfs.h | 57 ++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/sysfs.h 
b/sys/compat/linuxkpi/common/include/linux/sysfs.h
index 65e023031bb2..470c224a9778 100644
--- a/sys/compat/linuxkpi/common/include/linux/sysfs.h
+++ b/sys/compat/linuxkpi/common/include/linux/sysfs.h
@@ -189,6 +189,50 @@ sysfs_create_file(struct kobject *kobj, const struct 
attribute *attr)
        return (0);
 }
 
+static inline struct kobject *
+__sysfs_lookup_group(struct kobject *kobj, const char *group)
+{
+       int found;
+       struct sysctl_oid *group_oidp;
+       struct kobject *group_kobj;
+
+       found = 0;
+       if (group != NULL) {
+               SYSCTL_FOREACH(group_oidp, SYSCTL_CHILDREN(kobj->oidp)) {
+                       if (strcmp(group_oidp->oid_name, group) != 0)
+                               continue;
+                       found = 1;
+                       break;
+               }
+       } else {
+               found = 1;
+               group_oidp = kobj->oidp;
+       }
+
+       if (!found)
+               return (NULL);
+
+       group_kobj = group_oidp->oid_arg1;
+
+       return (group_kobj);
+}
+
+static inline int
+sysfs_add_file_to_group(struct kobject *kobj,
+    const struct attribute *attr, const char *group)
+{
+       int ret;
+       struct kobject *group_kobj;
+
+       group_kobj = __sysfs_lookup_group(kobj, group);
+       if (group_kobj == NULL)
+               return (-ENOENT);
+
+       ret = sysfs_create_file(group_kobj, attr);
+
+       return (ret);
+}
+
 static inline void
 sysfs_remove_file(struct kobject *kobj, const struct attribute *attr)
 {
@@ -197,6 +241,19 @@ sysfs_remove_file(struct kobject *kobj, const struct 
attribute *attr)
                sysctl_remove_name(kobj->oidp, attr->name, 1, 1);
 }
 
+static inline void
+sysfs_remove_file_from_group(struct kobject *kobj,
+    const struct attribute *attr, const char *group)
+{
+       struct kobject *group_kobj;
+
+       group_kobj = __sysfs_lookup_group(kobj, group);
+       if (group_kobj == NULL)
+               return;
+
+       sysfs_remove_file(group_kobj, attr);
+}
+
 static inline int
 sysctl_handle_bin_attr(SYSCTL_HANDLER_ARGS)
 {

Reply via email to