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@oss.qualcomm.com>
---
drivers/power/reset/reboot-mode.c | 139 +++++++++++++++++++++++++++++++++++++-
include/linux/reboot-mode.h | 1 +
2 files changed, 137 insertions(+), 3 deletions(-)
diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
index fba53f638da04655e756b5f8b7d2d666d1379535..96d0201697a539c6d048dac021db97e4e3063366 100644
--- a/drivers/power/reset/reboot-mode.c
+++ b/drivers/power/reset/reboot-mode.c
@@ -6,10 +6,12 @@
#include <linux/device.h>
#include <linux/init.h>
#include <linux/kernel.h>
+#include <linux/list.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/reboot.h>
#include <linux/reboot-mode.h>
+#include <linux/slab.h>
#define PREFIX "mode-"
@@ -19,6 +21,42 @@ struct mode_info {
struct list_head list;
};
+struct sysfs_data {
+ const char *mode;
+ struct list_head list;
+};
+
+static ssize_t reboot_modes_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ struct sysfs_data *sysfs_info;
+ struct list_head *head;
+ ssize_t size = 0;
+
+ head = dev_get_drvdata(dev);
+ if (!head)
+ return -ENODATA;
+
+ list_for_each_entry(sysfs_info, head, list)
+ size += sysfs_emit_at(buf, size, "%s ", sysfs_info->mode);
+
+ if (!size)
+ return -ENODATA;
+
+ return size + sysfs_emit_at(buf, size - 1, "\n");
+}
+static DEVICE_ATTR_RO(reboot_modes);
+
+static struct attribute *reboot_mode_attrs[] = {
+ &dev_attr_reboot_modes.attr,
+ NULL,
+};
+ATTRIBUTE_GROUPS(reboot_mode);
+
+static const struct class reboot_mode_class = {
+ .name = "reboot-mode",
+ .dev_groups = reboot_mode_groups,
+};
+
static unsigned int get_reboot_mode_magic(struct reboot_mode_driver *reboot,
const char *cmd)
{
@@ -62,6 +100,61 @@ static int reboot_mode_notify(struct notifier_block *this,
return NOTIFY_DONE;
}
+static int reboot_mode_create_device(struct reboot_mode_driver *reboot)
+{
+ struct sysfs_data *sysfs_info;
+ struct sysfs_data *next;
+ struct list_head *head;
+ struct mode_info *info;
+ int ret;
+
+ head = kzalloc(sizeof(*head), GFP_KERNEL);
+ if (!head) {
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ INIT_LIST_HEAD(head);
+
+ list_for_each_entry(info, &reboot->head, list) {
+ sysfs_info = kzalloc(sizeof(*sysfs_info), GFP_KERNEL);
+ if (!sysfs_info) {
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ sysfs_info->mode = kstrdup_const(info->mode, GFP_KERNEL);
+ if (!sysfs_info->mode) {
+ kfree(sysfs_info);
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ list_add_tail(&sysfs_info->list, head);
+ }
+
+ reboot->reboot_mode_device = device_create(&reboot_mode_class, NULL, 0,
+ (void *)head, reboot->dev->driver->name);
+
+ if (IS_ERR(reboot->reboot_mode_device)) {
+ ret = PTR_ERR(reboot->reboot_mode_device);
+ goto error;
+ }
+
+ return 0;
+
+error:
+ list_for_each_entry_safe(sysfs_info, next, head, list) {
+ list_del(&sysfs_info->list);
+ kfree_const(sysfs_info->mode);
+ kfree(sysfs_info);
+ }
+
+ kfree(head);
+ reboot->reboot_mode_device = NULL;
+ return ret;
+}
+
/**
* reboot_mode_register - register a reboot mode driver
* @reboot: reboot mode driver
@@ -113,16 +206,39 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
reboot->reboot_notifier.notifier_call = reboot_mode_notify;
register_reboot_notifier(&reboot->reboot_notifier);
+ ret = reboot_mode_create_device(reboot);
+ if (ret)
+ goto error;
+
return 0;
error:
- list_for_each_entry(info, &reboot->head, list)
- kfree_const(info->mode);
-
+ reboot_mode_unregister(reboot);
return ret;
}
EXPORT_SYMBOL_GPL(reboot_mode_register);
+static inline void reboot_mode_unregister_device(struct reboot_mode_driver *reboot)
+{
+ struct sysfs_data *sysfs_info;
+ struct sysfs_data *next;
+ struct list_head *head;
+
+ head = dev_get_drvdata(reboot->reboot_mode_device);
+ device_unregister(reboot->reboot_mode_device);
+ reboot->reboot_mode_device = NULL;
+
+ if (head) {
+ list_for_each_entry_safe(sysfs_info, next, head, list) {
+ list_del(&sysfs_info->list);
+ kfree_const(sysfs_info->mode);
+ kfree(sysfs_info);
+ }
+ }
+
+ kfree(head);
+}
+
/**
* reboot_mode_unregister - unregister a reboot mode driver
* @reboot: reboot mode driver
@@ -131,7 +247,11 @@ int reboot_mode_unregister(struct reboot_mode_driver *reboot)
{
struct mode_info *info;
+ if (!reboot->reboot_mode_device)
+ return -ENODEV;
+
unregister_reboot_notifier(&reboot->reboot_notifier);
+ reboot_mode_unregister_device(reboot);
list_for_each_entry(info, &reboot->head, list)
kfree_const(info->mode);
@@ -199,6 +319,19 @@ void devm_reboot_mode_unregister(struct device *dev,
}
EXPORT_SYMBOL_GPL(devm_reboot_mode_unregister);
+static int __init reboot_mode_init(void)
+{
+ return class_register(&reboot_mode_class);
+}
+
+static void __exit reboot_mode_exit(void)
+{
+ class_unregister(&reboot_mode_class);
+}
+
+subsys_initcall(reboot_mode_init);
+module_exit(reboot_mode_exit);
+
MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com>");
MODULE_DESCRIPTION("System reboot mode core library");
MODULE_LICENSE("GPL v2");
diff --git a/include/linux/reboot-mode.h b/include/linux/reboot-mode.h
index 4a2abb38d1d612ec0fdf05eb18c98b210f631b7f..b56783c32068096325f92445b9530d1856c4826c 100644
--- a/include/linux/reboot-mode.h
+++ b/include/linux/reboot-mode.h
@@ -5,6 +5,7 @@
struct reboot_mode_driver {
struct device *dev;
struct list_head head;
+ struct device *reboot_mode_device;
int (*write)(struct reboot_mode_driver *reboot, unsigned int magic);
struct notifier_block reboot_notifier;
};
--
2.34.1
On Fri, 26 Dec 2025 19:56:34 +0100, Shivendra Pratap
<shivendra.pratap@oss.qualcomm.com> said:
> 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@oss.qualcomm.com>
> ---
> drivers/power/reset/reboot-mode.c | 139 +++++++++++++++++++++++++++++++++++++-
> include/linux/reboot-mode.h | 1 +
> 2 files changed, 137 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
> index fba53f638da04655e756b5f8b7d2d666d1379535..96d0201697a539c6d048dac021db97e4e3063366 100644
> --- a/drivers/power/reset/reboot-mode.c
> +++ b/drivers/power/reset/reboot-mode.c
> @@ -6,10 +6,12 @@
> #include <linux/device.h>
> #include <linux/init.h>
> #include <linux/kernel.h>
> +#include <linux/list.h>
> #include <linux/module.h>
> #include <linux/of.h>
> #include <linux/reboot.h>
> #include <linux/reboot-mode.h>
> +#include <linux/slab.h>
>
> #define PREFIX "mode-"
>
> @@ -19,6 +21,42 @@ struct mode_info {
> struct list_head list;
> };
>
> +struct sysfs_data {
Let's make this more descriptive? struct reboot_mode_sysfs_data?
> + const char *mode;
> + struct list_head list;
> +};
> +
> +static ssize_t reboot_modes_show(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> + struct sysfs_data *sysfs_info;
> + struct list_head *head;
> + ssize_t size = 0;
> +
> + head = dev_get_drvdata(dev);
> + if (!head)
> + return -ENODATA;
> +
> + list_for_each_entry(sysfs_info, head, list)
> + size += sysfs_emit_at(buf, size, "%s ", sysfs_info->mode);
> +
> + if (!size)
> + return -ENODATA;
> +
> + return size + sysfs_emit_at(buf, size - 1, "\n");
> +}
> +static DEVICE_ATTR_RO(reboot_modes);
> +
> +static struct attribute *reboot_mode_attrs[] = {
> + &dev_attr_reboot_modes.attr,
> + NULL,
> +};
> +ATTRIBUTE_GROUPS(reboot_mode);
> +
> +static const struct class reboot_mode_class = {
> + .name = "reboot-mode",
> + .dev_groups = reboot_mode_groups,
> +};
> +
> static unsigned int get_reboot_mode_magic(struct reboot_mode_driver *reboot,
> const char *cmd)
> {
> @@ -62,6 +100,61 @@ static int reboot_mode_notify(struct notifier_block *this,
> return NOTIFY_DONE;
> }
>
> +static int reboot_mode_create_device(struct reboot_mode_driver *reboot)
> +{
> + struct sysfs_data *sysfs_info;
> + struct sysfs_data *next;
> + struct list_head *head;
> + struct mode_info *info;
> + int ret;
> +
> + head = kzalloc(sizeof(*head), GFP_KERNEL);
> + if (!head) {
> + ret = -ENOMEM;
> + goto error;
> + }
> +
> + INIT_LIST_HEAD(head);
> +
> + list_for_each_entry(info, &reboot->head, list) {
> + sysfs_info = kzalloc(sizeof(*sysfs_info), GFP_KERNEL);
> + if (!sysfs_info) {
> + ret = -ENOMEM;
> + goto error;
> + }
> +
> + sysfs_info->mode = kstrdup_const(info->mode, GFP_KERNEL);
> + if (!sysfs_info->mode) {
> + kfree(sysfs_info);
> + ret = -ENOMEM;
> + goto error;
> + }
> +
> + list_add_tail(&sysfs_info->list, head);
> + }
> +
> + reboot->reboot_mode_device = device_create(&reboot_mode_class, NULL, 0,
> + (void *)head, reboot->dev->driver->name);
No, why pass the list? You should create an instance of struct sysfs_data per
device_create(). If it needs to contain a list, then let it contain a list but
don't allocate the list_head, that's really unusual.
> +
> + if (IS_ERR(reboot->reboot_mode_device)) {
> + ret = PTR_ERR(reboot->reboot_mode_device);
> + goto error;
> + }
> +
> + return 0;
> +
> +error:
> + list_for_each_entry_safe(sysfs_info, next, head, list) {
> + list_del(&sysfs_info->list);
> + kfree_const(sysfs_info->mode);
> + kfree(sysfs_info);
> + }
> +
> + kfree(head);
> + reboot->reboot_mode_device = NULL;
> + return ret;
> +}
> +
> /**
> * reboot_mode_register - register a reboot mode driver
> * @reboot: reboot mode driver
> @@ -113,16 +206,39 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
> reboot->reboot_notifier.notifier_call = reboot_mode_notify;
> register_reboot_notifier(&reboot->reboot_notifier);
>
> + ret = reboot_mode_create_device(reboot);
> + if (ret)
> + goto error;
> +
> return 0;
>
> error:
> - list_for_each_entry(info, &reboot->head, list)
> - kfree_const(info->mode);
> -
> + reboot_mode_unregister(reboot);
> return ret;
> }
> EXPORT_SYMBOL_GPL(reboot_mode_register);
>
> +static inline void reboot_mode_unregister_device(struct reboot_mode_driver *reboot)
> +{
> + struct sysfs_data *sysfs_info;
> + struct sysfs_data *next;
> + struct list_head *head;
> +
> + head = dev_get_drvdata(reboot->reboot_mode_device);
> + device_unregister(reboot->reboot_mode_device);
> + reboot->reboot_mode_device = NULL;
> +
> + if (head) {
> + list_for_each_entry_safe(sysfs_info, next, head, list) {
> + list_del(&sysfs_info->list);
> + kfree_const(sysfs_info->mode);
> + kfree(sysfs_info);
> + }
This loop is duplicated, can you please factor it out into a dedicated
function?
> + }
> +
> + kfree(head);
> +}
> +
> /**
> * reboot_mode_unregister - unregister a reboot mode driver
> * @reboot: reboot mode driver
> @@ -131,7 +247,11 @@ int reboot_mode_unregister(struct reboot_mode_driver *reboot)
> {
> struct mode_info *info;
>
> + if (!reboot->reboot_mode_device)
> + return -ENODEV;
> +
> unregister_reboot_notifier(&reboot->reboot_notifier);
> + reboot_mode_unregister_device(reboot);
>
> list_for_each_entry(info, &reboot->head, list)
> kfree_const(info->mode);
> @@ -199,6 +319,19 @@ void devm_reboot_mode_unregister(struct device *dev,
> }
> EXPORT_SYMBOL_GPL(devm_reboot_mode_unregister);
>
> +static int __init reboot_mode_init(void)
> +{
> + return class_register(&reboot_mode_class);
> +}
> +
> +static void __exit reboot_mode_exit(void)
> +{
> + class_unregister(&reboot_mode_class);
> +}
> +
> +subsys_initcall(reboot_mode_init);
> +module_exit(reboot_mode_exit);
> +
> MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com>");
> MODULE_DESCRIPTION("System reboot mode core library");
> MODULE_LICENSE("GPL v2");
> diff --git a/include/linux/reboot-mode.h b/include/linux/reboot-mode.h
> index 4a2abb38d1d612ec0fdf05eb18c98b210f631b7f..b56783c32068096325f92445b9530d1856c4826c 100644
> --- a/include/linux/reboot-mode.h
> +++ b/include/linux/reboot-mode.h
> @@ -5,6 +5,7 @@
> struct reboot_mode_driver {
> struct device *dev;
> struct list_head head;
> + struct device *reboot_mode_device;
Why can't this be part of struct (reboot_mode_)sysfs_data?
Bart
> int (*write)(struct reboot_mode_driver *reboot, unsigned int magic);
> struct notifier_block reboot_notifier;
> };
>
> --
> 2.34.1
>
>
On 1/2/2026 6:55 PM, Bartosz Golaszewski wrote:
> On Fri, 26 Dec 2025 19:56:34 +0100, Shivendra Pratap
> <shivendra.pratap@oss.qualcomm.com> said:
>> 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.
[SNIP..]
>>
>> +struct sysfs_data {
>
> Let's make this more descriptive? struct reboot_mode_sysfs_data?
Ack. thanks.
>
>> + const char *mode;
>> + struct list_head list;
>> +};
>> +
[SNIP..]
>> +
>> + reboot->reboot_mode_device = device_create(&reboot_mode_class, NULL, 0,
>> + (void *)head, reboot->dev->driver->name);
>
> No, why pass the list? You should create an instance of struct sysfs_data per
> device_create(). If it needs to contain a list, then let it contain a list but
> don't allocate the list_head, that's really unusual.
>
ok. Will create struct reboot_mode_sysfs_data with a list head and
allocate it as data.
>> +
[SNIP..]
>>
>> +static inline void reboot_mode_unregister_device(struct reboot_mode_driver *reboot)
>> +{
>> + struct sysfs_data *sysfs_info;
>> + struct sysfs_data *next;
>> + struct list_head *head;
>> +
>> + head = dev_get_drvdata(reboot->reboot_mode_device);
>> + device_unregister(reboot->reboot_mode_device);
>> + reboot->reboot_mode_device = NULL;
>> +
>> + if (head) {
>> + list_for_each_entry_safe(sysfs_info, next, head, list) {
>> + list_del(&sysfs_info->list);
>> + kfree_const(sysfs_info->mode);
>> + kfree(sysfs_info);
>> + }
>
> This loop is duplicated, can you please factor it out into a dedicated
> function?
The loop frees the sysfs data. You mean i should directly call
reboot_mode_unregister_device in error path of reboot_mode_create_device
as not to duplicate the loop?
>
[SNIP..]
>> diff --git a/include/linux/reboot-mode.h b/include/linux/reboot-mode.h
>> index 4a2abb38d1d612ec0fdf05eb18c98b210f631b7f..b56783c32068096325f92445b9530d1856c4826c 100644
>> --- a/include/linux/reboot-mode.h
>> +++ b/include/linux/reboot-mode.h
>> @@ -5,6 +5,7 @@
>> struct reboot_mode_driver {
>> struct device *dev;
>> struct list_head head;
>> + struct device *reboot_mode_device;
>
> Why can't this be part of struct (reboot_mode_)sysfs_data?
>
If reboot_mode_device is kept in sysfs_data, we need a reference to free
it. Should I maintain reference for it in "reboot struct" and store
sysfs_data pointer, so that it can be used to call device_unregister()?
Eg:
struct reboot
{
..
..
void *priv;
};
struct reboot_mode_sysfs_data {
struct device *reboot_mode_device;
struct list_head head;
};
---
data = kzalloc(reboot_mode_sysfs_data);
reboot->priv = data;
--
thanks,
Shivendra
On Mon, Jan 5, 2026 at 6:45 PM Shivendra Pratap
<shivendra.pratap@oss.qualcomm.com> wrote:
>
>
>
> On 1/2/2026 6:55 PM, Bartosz Golaszewski wrote:
> > On Fri, 26 Dec 2025 19:56:34 +0100, Shivendra Pratap
> > <shivendra.pratap@oss.qualcomm.com> said:
> >> 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.
>
Sorry for the delayed response.
> [SNIP..]
>
> >>
> >> +struct sysfs_data {
> >
> > Let's make this more descriptive? struct reboot_mode_sysfs_data?
>
> Ack. thanks.
>
> >
> >> + const char *mode;
> >> + struct list_head list;
> >> +};
> >> +
>
> [SNIP..]
>
> >> +
> >> + reboot->reboot_mode_device = device_create(&reboot_mode_class, NULL, 0,
> >> + (void *)head, reboot->dev->driver->name);
> >
> > No, why pass the list? You should create an instance of struct sysfs_data per
> > device_create(). If it needs to contain a list, then let it contain a list but
> > don't allocate the list_head, that's really unusual.
> >
>
> ok. Will create struct reboot_mode_sysfs_data with a list head and
> allocate it as data.
>
> >> +
>
> [SNIP..]
>
> >>
> >> +static inline void reboot_mode_unregister_device(struct reboot_mode_driver *reboot)
> >> +{
> >> + struct sysfs_data *sysfs_info;
> >> + struct sysfs_data *next;
> >> + struct list_head *head;
> >> +
> >> + head = dev_get_drvdata(reboot->reboot_mode_device);
> >> + device_unregister(reboot->reboot_mode_device);
> >> + reboot->reboot_mode_device = NULL;
> >> +
> >> + if (head) {
> >> + list_for_each_entry_safe(sysfs_info, next, head, list) {
> >> + list_del(&sysfs_info->list);
> >> + kfree_const(sysfs_info->mode);
> >> + kfree(sysfs_info);
> >> + }
> >
> > This loop is duplicated, can you please factor it out into a dedicated
> > function?
>
> The loop frees the sysfs data. You mean i should directly call
> reboot_mode_unregister_device in error path of reboot_mode_create_device
> as not to duplicate the loop?
>
I was thinking about wrapping it in a dedicated function and calling
it here and in the error path in reboot_mode_create_device().
> >
>
> [SNIP..]
>
> >> diff --git a/include/linux/reboot-mode.h b/include/linux/reboot-mode.h
> >> index 4a2abb38d1d612ec0fdf05eb18c98b210f631b7f..b56783c32068096325f92445b9530d1856c4826c 100644
> >> --- a/include/linux/reboot-mode.h
> >> +++ b/include/linux/reboot-mode.h
> >> @@ -5,6 +5,7 @@
> >> struct reboot_mode_driver {
> >> struct device *dev;
> >> struct list_head head;
> >> + struct device *reboot_mode_device;
> >
> > Why can't this be part of struct (reboot_mode_)sysfs_data?
> >
>
> If reboot_mode_device is kept in sysfs_data, we need a reference to free
> it. Should I maintain reference for it in "reboot struct" and store
> sysfs_data pointer, so that it can be used to call device_unregister()?
>
> Eg:
> struct reboot
> {
> ..
> ..
> void *priv;
> };
>
> struct reboot_mode_sysfs_data {
> struct device *reboot_mode_device;
> struct list_head head;
> };
>
You can use class_find_device(). Store the address of the associated
reboot_mode_driver in the private structure and compare by it in the
match callback.
Bart
Hi Shivendra,
kernel test robot noticed the following build warnings:
url: https://github.com/intel-lab-lkp/linux/commits/Shivendra-Pratap/Documentation-ABI-Add-sysfs-class-reboot-mode-reboot_modes/20251227-025914
base: cc3aa43b44bdb43dfbac0fcb51c56594a11338a8
patch link: https://lore.kernel.org/r/20251227-next-15nov_expose_sysfs-v22-2-2d153438ba19%40oss.qualcomm.com
patch subject: [PATCH v22 2/2] power: reset: reboot-mode: Expose sysfs for registered reboot_modes
config: x86_64-randconfig-161-20251227 (https://download.01.org/0day-ci/archive/20251227/202512271806.n2lycyZw-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202512271806.n2lycyZw-lkp@intel.com/
smatch warnings:
drivers/power/reset/reboot-mode.c:147 reboot_mode_create_device() error: we previously assumed 'head' could be null (see line 112)
vim +/head +147 drivers/power/reset/reboot-mode.c
e5f49083a20ae0 Shivendra Pratap 2025-12-27 103 static int reboot_mode_create_device(struct reboot_mode_driver *reboot)
e5f49083a20ae0 Shivendra Pratap 2025-12-27 104 {
e5f49083a20ae0 Shivendra Pratap 2025-12-27 105 struct sysfs_data *sysfs_info;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 106 struct sysfs_data *next;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 107 struct list_head *head;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 108 struct mode_info *info;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 109 int ret;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 110
e5f49083a20ae0 Shivendra Pratap 2025-12-27 111 head = kzalloc(sizeof(*head), GFP_KERNEL);
e5f49083a20ae0 Shivendra Pratap 2025-12-27 @112 if (!head) {
e5f49083a20ae0 Shivendra Pratap 2025-12-27 113 ret = -ENOMEM;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 114 goto error;
This should just be return -ENOMEM;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 115 }
e5f49083a20ae0 Shivendra Pratap 2025-12-27 116
e5f49083a20ae0 Shivendra Pratap 2025-12-27 117 INIT_LIST_HEAD(head);
e5f49083a20ae0 Shivendra Pratap 2025-12-27 118
e5f49083a20ae0 Shivendra Pratap 2025-12-27 119 list_for_each_entry(info, &reboot->head, list) {
e5f49083a20ae0 Shivendra Pratap 2025-12-27 120 sysfs_info = kzalloc(sizeof(*sysfs_info), GFP_KERNEL);
e5f49083a20ae0 Shivendra Pratap 2025-12-27 121 if (!sysfs_info) {
e5f49083a20ae0 Shivendra Pratap 2025-12-27 122 ret = -ENOMEM;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 123 goto error;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 124 }
e5f49083a20ae0 Shivendra Pratap 2025-12-27 125
e5f49083a20ae0 Shivendra Pratap 2025-12-27 126 sysfs_info->mode = kstrdup_const(info->mode, GFP_KERNEL);
e5f49083a20ae0 Shivendra Pratap 2025-12-27 127 if (!sysfs_info->mode) {
e5f49083a20ae0 Shivendra Pratap 2025-12-27 128 kfree(sysfs_info);
e5f49083a20ae0 Shivendra Pratap 2025-12-27 129 ret = -ENOMEM;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 130 goto error;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 131 }
e5f49083a20ae0 Shivendra Pratap 2025-12-27 132
e5f49083a20ae0 Shivendra Pratap 2025-12-27 133 list_add_tail(&sysfs_info->list, head);
e5f49083a20ae0 Shivendra Pratap 2025-12-27 134 }
e5f49083a20ae0 Shivendra Pratap 2025-12-27 135
e5f49083a20ae0 Shivendra Pratap 2025-12-27 136 reboot->reboot_mode_device = device_create(&reboot_mode_class, NULL, 0,
e5f49083a20ae0 Shivendra Pratap 2025-12-27 137 (void *)head, reboot->dev->driver->name);
e5f49083a20ae0 Shivendra Pratap 2025-12-27 138
e5f49083a20ae0 Shivendra Pratap 2025-12-27 139 if (IS_ERR(reboot->reboot_mode_device)) {
e5f49083a20ae0 Shivendra Pratap 2025-12-27 140 ret = PTR_ERR(reboot->reboot_mode_device);
e5f49083a20ae0 Shivendra Pratap 2025-12-27 141 goto error;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 142 }
e5f49083a20ae0 Shivendra Pratap 2025-12-27 143
e5f49083a20ae0 Shivendra Pratap 2025-12-27 144 return 0;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 145
e5f49083a20ae0 Shivendra Pratap 2025-12-27 146 error:
e5f49083a20ae0 Shivendra Pratap 2025-12-27 @147 list_for_each_entry_safe(sysfs_info, next, head, list) {
^^^^
But it is a crash instead.
e5f49083a20ae0 Shivendra Pratap 2025-12-27 148 list_del(&sysfs_info->list);
e5f49083a20ae0 Shivendra Pratap 2025-12-27 149 kfree_const(sysfs_info->mode);
e5f49083a20ae0 Shivendra Pratap 2025-12-27 150 kfree(sysfs_info);
e5f49083a20ae0 Shivendra Pratap 2025-12-27 151 }
e5f49083a20ae0 Shivendra Pratap 2025-12-27 152
e5f49083a20ae0 Shivendra Pratap 2025-12-27 153 kfree(head);
e5f49083a20ae0 Shivendra Pratap 2025-12-27 154 reboot->reboot_mode_device = NULL;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 155 return ret;
e5f49083a20ae0 Shivendra Pratap 2025-12-27 156 }
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2026 Red Hat, Inc.