[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <41725ac5-843c-0e4d-8f82-a6b7cd8ba9e0@oss.qualcomm.com>
Date: Wed, 12 Nov 2025 22:27:28 +0530
From: Shivendra Pratap <shivendra.pratap@....qualcomm.com>
To: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Cc: Bjorn Andersson <andersson@...nel.org>,
Sebastian Reichel
<sre@...nel.org>, Rob Herring <robh@...nel.org>,
Sudeep Holla <sudeep.holla@....com>,
Souvik Chakravarty <Souvik.Chakravarty@....com>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley
<conor+dt@...nel.org>,
Andy Yan <andy.yan@...k-chips.com>,
Mark Rutland <mark.rutland@....com>,
Lorenzo Pieralisi <lpieralisi@...nel.org>,
Arnd Bergmann <arnd@...db.de>, Konrad Dybcio <konradybcio@...nel.org>,
cros-qcom-dts-watchers@...omium.org, Vinod Koul <vkoul@...nel.org>,
Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>,
Florian Fainelli <florian.fainelli@...adcom.com>,
Moritz Fischer <moritz.fischer@...us.com>,
John Stultz <john.stultz@...aro.org>,
Matthias Brugger <matthias.bgg@...il.com>,
Krzysztof Kozlowski <krzk@...nel.org>,
Dmitry Baryshkov <dmitry.baryshkov@....qualcomm.com>,
Mukesh Ojha <mukesh.ojha@....qualcomm.com>,
Stephen Boyd <swboyd@...omium.org>,
Andre Draszik
<andre.draszik@...aro.org>,
Kathiravan Thirumoorthy <kathiravan.thirumoorthy@....qualcomm.com>,
linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org,
devicetree@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-arm-msm@...r.kernel.org,
Elliot Berman <quic_eberman@...cinc.com>,
Xin Liu <xin.liu@....qualcomm.com>,
Srinivas Kandagatla <srini@...nel.org>
Subject: Re: [PATCH v17 05/12] power: reset: reboot-mode: Expose sysfs for
registered reboot_modes
On 11/10/2025 8:44 PM, Bartosz Golaszewski wrote:
> On Sun, 9 Nov 2025 at 15:38, Shivendra Pratap
> <shivendra.pratap@....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@....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
Powered by blists - more mailing lists