git: 9e736b8b8a1e - stable/13 - LinuxKPI: Implement default sysfs kobject attribute operations

From: Vladimir Kondratyev <wulf_at_FreeBSD.org>
Date: Sat, 22 Jan 2022 19:36:22 UTC
The branch stable/13 has been updated by wulf:

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

commit 9e736b8b8a1ec017a4c977385a3e2a33e4b54670
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2021-11-23 09:09:42 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2022-01-22 19:34:36 +0000

    LinuxKPI: Implement default sysfs kobject attribute operations
    
    Required by drm-kmod 5.7
    
    MFC after:      1 week
    Reviewed by:    hselasky
    Differential Revision:  https://reviews.freebsd.org/D33292
    
    (cherry picked from commit 04d42cb453888cbda0fb81d38bd722962ca6fc03)
---
 sys/compat/linuxkpi/common/include/linux/kobject.h |  2 ++
 sys/compat/linuxkpi/common/src/linux_compat.c      | 30 ++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/kobject.h b/sys/compat/linuxkpi/common/include/linux/kobject.h
index 403ec1495c32..8108375ed07e 100644
--- a/sys/compat/linuxkpi/common/include/linux/kobject.h
+++ b/sys/compat/linuxkpi/common/include/linux/kobject.h
@@ -68,6 +68,8 @@ struct attribute {
 	mode_t		mode;
 };
 
+extern const struct sysfs_ops kobj_sysfs_ops;
+
 struct kobj_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c
index 9c6ed96c19b6..666a1bd07970 100644
--- a/sys/compat/linuxkpi/common/src/linux_compat.c
+++ b/sys/compat/linuxkpi/common/src/linux_compat.c
@@ -281,6 +281,36 @@ const struct kobj_type linux_kfree_type = {
 	.release = linux_kobject_kfree
 };
 
+static ssize_t
+lkpi_kobj_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
+{
+	struct kobj_attribute *ka =
+	    container_of(attr, struct kobj_attribute, attr);
+
+	if (ka->show == NULL)
+		return (-EIO);
+
+	return (ka->show(kobj, ka, buf));
+}
+
+static ssize_t
+lkpi_kobj_attr_store(struct kobject *kobj, struct attribute *attr,
+    const char *buf, size_t count)
+{
+	struct kobj_attribute *ka =
+	    container_of(attr, struct kobj_attribute, attr);
+
+	if (ka->store == NULL)
+		return (-EIO);
+
+	return (ka->store(kobj, ka, buf, count));
+}
+
+const struct sysfs_ops kobj_sysfs_ops = {
+	.show	= lkpi_kobj_attr_show,
+	.store	= lkpi_kobj_attr_store,
+};
+
 static void
 linux_device_release(struct device *dev)
 {