[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CACMJSesvTLe28Jz83b=zfHD2rvmf7-i_2+2DoV=dgooVqFEYbA@mail.gmail.com>
Date: Wed, 15 Oct 2025 16:40:28 +0200
From: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
To: Shivendra Pratap <shivendra.pratap@....qualcomm.com>
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>, Srinivas Kandagatla <srini@...nel.org>
Subject: Re: [PATCH v16 02/14] power: reset: reboot-mode: Add device tree
node-based registration
On Wed, 15 Oct 2025 at 06:38, Shivendra Pratap
<shivendra.pratap@....qualcomm.com> wrote:
>
> The reboot-mode driver does not have a strict requirement for
> device-based registration. It primarily uses the device's of_node
> to read mode-<cmd> properties and the device pointer for logging.
>
> Remove the dependency on struct device and introduce support for
> firmware node (fwnode) based registration. This enables drivers
> that are not associated with a struct device to leverage the
> reboot-mode framework.
>
> Signed-off-by: Shivendra Pratap <shivendra.pratap@....qualcomm.com>
> ---
> drivers/power/reset/reboot-mode.c | 45 +++++++++++++++++++++++++++++----------
> include/linux/reboot-mode.h | 3 ++-
> 2 files changed, 36 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
> index 8fc3e14638ea757c8dc3808c240ff569cbd74786..c8f71e6f661ae14eb72bdcb1f412cd05faee3dd9 100644
> --- a/drivers/power/reset/reboot-mode.c
> +++ b/drivers/power/reset/reboot-mode.c
> @@ -3,13 +3,17 @@
> * Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd
> */
>
> +#define pr_fmt(fmt) "reboot-mode: " fmt
> +
> #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-"
>
> @@ -69,17 +73,26 @@ static int reboot_mode_notify(struct notifier_block *this,
> /**
> * reboot_mode_register - register a reboot mode driver
> * @reboot: reboot mode driver
> + * @fwnode: Firmware node with reboot-mode configuration
> *
> * Returns: 0 on success or a negative error code on failure.
> */
> -int reboot_mode_register(struct reboot_mode_driver *reboot)
> +int reboot_mode_register(struct reboot_mode_driver *reboot, struct fwnode_handle *fwnode)
> {
> struct mode_info *info;
> + struct mode_info *next;
> + struct device_node *np;
> struct property *prop;
> - struct device_node *np = reboot->dev->of_node;
> size_t len = strlen(PREFIX);
> int ret;
>
> + if (!fwnode)
> + return -EINVAL;
> +
> + np = to_of_node(fwnode);
> + if (!np)
> + return -EINVAL;
> +
> INIT_LIST_HEAD(&reboot->head);
>
> mutex_init(&reboot->rb_lock);
> @@ -89,28 +102,28 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
> if (strncmp(prop->name, PREFIX, len))
> continue;
>
> - info = devm_kzalloc(reboot->dev, sizeof(*info), GFP_KERNEL);
This change is good - devres should not be used in subsystem library
code, only in drivers - but it doesn't seem to belong here, can you
please separate it out and make it backportable?
> + info = kzalloc(sizeof(*info), GFP_KERNEL);
> if (!info) {
> ret = -ENOMEM;
> goto error;
> }
>
> if (of_property_read_u32(np, prop->name, &info->magic)) {
> - dev_err(reboot->dev, "reboot mode %s without magic number\n",
> - info->mode);
> - devm_kfree(reboot->dev, info);
> + pr_err("reboot mode %s without magic number\n", info->mode);
> + kfree(info);
> continue;
> }
>
> info->mode = kstrdup_const(prop->name + len, GFP_KERNEL);
> if (!info->mode) {
> ret = -ENOMEM;
> + kfree(info);
> goto error;
> } else if (info->mode[0] == '\0') {
> kfree_const(info->mode);
> + kfree(info);
> ret = -EINVAL;
> - dev_err(reboot->dev, "invalid mode name(%s): too short!\n",
> - prop->name);
> + pr_err("invalid mode name(%s): too short!\n", prop->name);
> goto error;
> }
>
> @@ -123,8 +136,11 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
> return 0;
>
> error:
> - list_for_each_entry(info, &reboot->head, list)
> + list_for_each_entry_safe(info, next, &reboot->head, list) {
> + list_del(&info->list);
Same here, not deleting the entries currently seems like a bug? Do we
depend on the driver detach to clean up the resources on failure?
> kfree_const(info->mode);
> + kfree(info);
> + }
> }
>
> return ret;
> @@ -138,12 +154,16 @@ EXPORT_SYMBOL_GPL(reboot_mode_register);
> int reboot_mode_unregister(struct reboot_mode_driver *reboot)
> {
> struct mode_info *info;
> + struct mode_info *next;
>
> unregister_reboot_notifier(&reboot->reboot_notifier);
>
> scoped_guard(mutex, &reboot->rb_lock) {
> - list_for_each_entry(info, &reboot->head, list)
> + list_for_each_entry_safe(info, next, &reboot->head, list) {
> + list_del(&info->list);
> kfree_const(info->mode);
> + kfree(info);
> + }
> }
>
> return 0;
> @@ -168,11 +188,14 @@ int devm_reboot_mode_register(struct device *dev,
> struct reboot_mode_driver **dr;
> int rc;
>
> + if (!reboot->dev || !reboot->dev->of_node)
> + return -EINVAL;
> +
> dr = devres_alloc(devm_reboot_mode_release, sizeof(*dr), GFP_KERNEL);
> if (!dr)
> return -ENOMEM;
>
> - rc = reboot_mode_register(reboot);
> + rc = reboot_mode_register(reboot, of_fwnode_handle(reboot->dev->of_node));
> if (rc) {
> devres_free(dr);
> return rc;
> diff --git a/include/linux/reboot-mode.h b/include/linux/reboot-mode.h
> index b73f80708197677db8dc2e43affc519782b7146e..7f05fd873e95ca8249bc167c21aa6b76faba7849 100644
> --- a/include/linux/reboot-mode.h
> +++ b/include/linux/reboot-mode.h
> @@ -2,6 +2,7 @@
> #ifndef __REBOOT_MODE_H__
> #define __REBOOT_MODE_H__
>
> +#include <linux/fwnode.h>
> #include <linux/mutex.h>
>
> struct reboot_mode_driver {
> @@ -13,7 +14,7 @@ struct reboot_mode_driver {
> struct mutex rb_lock;
> };
>
> -int reboot_mode_register(struct reboot_mode_driver *reboot);
> +int reboot_mode_register(struct reboot_mode_driver *reboot, struct fwnode_handle *fwnode);
> int reboot_mode_unregister(struct reboot_mode_driver *reboot);
> int devm_reboot_mode_register(struct device *dev,
> struct reboot_mode_driver *reboot);
>
> --
> 2.34.1
>
Bartosz
Powered by blists - more mailing lists