[PATCHv2 2/3] nvme: Add device_update_groups()
Chaitanya Kulkarni
chaitanyak at nvidia.com
Thu Feb 3 18:22:54 PST 2022
On 2/3/22 13:17, Martin Belanger wrote:
> 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;
> +
consider following, can be done at the time of applying patch :-
const struct device_type *type = dev->type;
struct class *class = dev->class;
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);
>
More information about the Linux-nvme
mailing list