[PATCHv2 2/3] nvme: Add device_update_groups()

Martin Belanger nitram_67 at hotmail.com
Thu Feb 3 13:17:47 PST 2022


From: Martin Belanger <martin.belanger at dell.com>

This is used to update the sysfs groups after device objects are fully
initialized.

Signed-off-by: Martin Belanger <martin.belanger at dell.com>
---
 drivers/base/core.c    | 28 ++++++++++++++++++++++++++++
 include/linux/device.h |  1 +
 2 files changed, 29 insertions(+)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 3d6430eb0c6a..0b5f6d5d2459 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -4473,6 +4473,34 @@ int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid)
 }
 EXPORT_SYMBOL_GPL(device_change_owner);
 
+/**
+ * device_update_groups - update the sysfs groups
+ * @dev: device.
+ *
+ * Returns 0 on success or error code on failure.
+ */
+int device_update_groups(struct device *dev)
+{
+	struct class *class = dev->class;
+	const struct device_type *type = dev->type;
+	int error;
+
+	if (class) {
+		error = sysfs_update_groups(&dev->kobj, class->dev_groups);
+		if (error)
+			return error;
+	}
+
+	if (type) {
+		error = sysfs_update_groups(&dev->kobj, type->groups);
+		if (error)
+			return error;
+	}
+
+	return sysfs_update_groups(&dev->kobj, dev->groups);
+}
+EXPORT_SYMBOL_GPL(device_update_groups);
+
 /**
  * device_shutdown - call ->shutdown() on each device to shutdown.
  */
diff --git a/include/linux/device.h b/include/linux/device.h
index 93459724dcde..a623790173ce 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -841,6 +841,7 @@ int device_rename(struct device *dev, const char *new_name);
 int device_move(struct device *dev, struct device *new_parent,
 		enum dpm_order dpm_order);
 int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid);
+int device_update_groups(struct device *dev);
 const char *device_get_devnode(struct device *dev, umode_t *mode, kuid_t *uid,
 			       kgid_t *gid, const char **tmp);
 int device_is_dependent(struct device *dev, void *target);
-- 
2.34.1




More information about the Linux-nvme mailing list