[PATCH v17 05/12] power: reset: reboot-mode: Expose sysfs for registered reboot_modes
Shivendra Pratap
shivendra.pratap at oss.qualcomm.com
Wed Nov 12 08:57:28 PST 2025
On 11/10/2025 8:44 PM, Bartosz Golaszewski wrote:
> On Sun, 9 Nov 2025 at 15:38, Shivendra Pratap
> <shivendra.pratap at oss.qualcomm.com> wrote:
>>
>> Currently, there is no standardized mechanism for userspace to
>> discover which reboot-modes are supported on a given platform.
>> This limitation forces tools and scripts to rely on hardcoded
>> assumptions about the supported reboot-modes.
>>
>> Create a class 'reboot-mode' and a device under it to expose a
>> sysfs interface to show the available reboot mode arguments to
>> userspace. Use the driver_name field of the struct
>> reboot_mode_driver to create the device. For device-based
>> drivers, configure the device driver name as driver_name.
>>
>> This results in the creation of:
>> /sys/class/reboot-mode/<driver>/reboot_modes
>>
>> This read-only sysfs file will exposes the list of supported
>> reboot modes arguments provided by the driver, enabling userspace
>> to query the list of arguments.
>>
>> Signed-off-by: Shivendra Pratap <shivendra.pratap at oss.qualcomm.com>
>> ---
>> drivers/power/reset/reboot-mode.c | 62 ++++++++++++++++++++++++++++++++++++++-
>> include/linux/reboot-mode.h | 2 ++
>> 2 files changed, 63 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
>> index 873ac45cd7659b214b7c21958f580ca381e0a63d..582aa7f8ed7fa485c5a67877558c9b15d3600ef4 100644
>> --- a/drivers/power/reset/reboot-mode.c
>> +++ b/drivers/power/reset/reboot-mode.c
>> @@ -6,6 +6,7 @@
>> #define pr_fmt(fmt) "reboot-mode: " fmt
>>
>> #include <linux/device.h>
>> +#include <linux/err.h>
>> #include <linux/init.h>
>> #include <linux/kernel.h>
>> #include <linux/list.h>
>> @@ -23,6 +24,8 @@ struct mode_info {
>> struct list_head list;
>> };
>>
>> +static struct class *rb_class;
>> +
>
> I know C is a spartan language but the rb_ prefix makes me think of
> the red-black tree. Please call it reboot_mode_class.
sure will make it reboot_mode_class.
>
>> static u64 get_reboot_mode_magic(struct reboot_mode_driver *reboot, const char *cmd)
>> {
>> const char *normal = "normal";
>> @@ -65,6 +68,51 @@ static int reboot_mode_notify(struct notifier_block *this,
>> return NOTIFY_DONE;
>> }
>>
>> +static ssize_t reboot_modes_show(struct device *dev, struct device_attribute *attr, char *buf)
>> +{
>> + struct reboot_mode_driver *reboot;
>> + struct mode_info *info;
>> + ssize_t size = 0;
>> +
>> + reboot = (struct reboot_mode_driver *)dev_get_drvdata(dev);
>
> No need for the cast.
Ack.
>> + if (!reboot)
>> + return -ENODATA;
>> +
>> + list_for_each_entry(info, &reboot->head, list)
>> + size += sysfs_emit_at(buf, size, "%s ", info->mode);
>> +
>> + if (size) {
>> + size += sysfs_emit_at(buf, size - 1, "\n");
>> + return size;
>> + }
>
> This is a weird logic inversion. Just do:
>
> if (!size)
> return -ENODATA;
>
> return size + sysfs_emit_at(buf, size - 1, "\n");
Ack.
>> +
>> + return -ENODATA;
>> +}
>> +static DEVICE_ATTR_RO(reboot_modes);
>> +
>> +static int create_reboot_mode_device(struct reboot_mode_driver *reboot)
>> +{
>> + int ret = 0;
>> +
>> + if (!rb_class) {
>> + rb_class = class_create("reboot-mode");
>> + if (IS_ERR(rb_class))
>> + return PTR_ERR(rb_class);
>> + }
>
> Why the lazy initialization here? Is there any reason you can't
> statically define the class? Don't you need synchronization here if
> multiple drivers try to do this?
reboot-mode framework does not has a init. Should i add a inti_call
here and create a class? Can you suggest a bit more.
For if we at-all continue this lazy init, will add a lock.
thanks,
Shivendra
More information about the linux-arm-kernel
mailing list