From: Shivendra Pratap <shivendra.pratap@oss.qualcomm.com>
To: Lorenzo Pieralisi <lpieralisi@kernel.org>,
Arnd Bergmann <arnd@arndb.de>,
Bjorn Andersson <andersson@kernel.org>,
Sebastian Reichel <sre@kernel.org>, Rob Herring <robh@kernel.org>,
Souvik Chakravarty <Souvik.Chakravarty@arm.com>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Andy Yan <andy.yan@rock-chips.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
Mark Rutland <mark.rutland@arm.com>,
Conor Dooley <conor+dt@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
John Stultz <john.stultz@linaro.org>,
Moritz Fischer <moritz.fischer@ettus.com>,
Bartosz Golaszewski <brgl@kernel.org>,
Sudeep Holla <sudeep.holla@kernel.org>
Cc: Florian Fainelli <florian.fainelli@broadcom.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>,
Andre Draszik <andre.draszik@linaro.org>,
Kathiravan Thirumoorthy
<kathiravan.thirumoorthy@oss.qualcomm.com>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org,
Shivendra Pratap <shivendra.pratap@oss.qualcomm.com>,
Srinivas Kandagatla <srini@kernel.org>
Subject: [PATCH v20 01/10] power: reset: reboot-mode: Remove devres based allocations
Date: Wed, 04 Mar 2026 23:33:01 +0530 [thread overview]
Message-ID: <20260304-arm-psci-system_reset2-vendor-reboots-v20-1-cf7d346b8372@oss.qualcomm.com> (raw)
In-Reply-To: <20260304-arm-psci-system_reset2-vendor-reboots-v20-0-cf7d346b8372@oss.qualcomm.com>
Devres APIs are intended for use in drivers, where the managed lifetime
of resources is tied directly to the driver attach/detach cycle. In
shared subsystem code, there is no guarantee that the subsystem
functions will only be called after a driver has been attached, nor that
they will not be referenced after the managed resources have been
released during driver detach.
To ensure correct lifetime handling, avoid using devres-based
allocations in the reboot-mode and explicitly handle allocation and
cleanup of resources.
Fixes: 4fcd504edbf7 ("power: reset: add reboot mode driver")
Signed-off-by: Shivendra Pratap <shivendra.pratap@oss.qualcomm.com>
---
drivers/power/reset/reboot-mode.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
index fba53f638da04655e756b5f8b7d2d666d1379535..d033043f5250a4de152a7786ef37e88a0ace3bbb 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/module.h>
#include <linux/of.h>
+#include <linux/property.h>
#include <linux/reboot.h>
#include <linux/reboot-mode.h>
+#include <linux/slab.h>
#define PREFIX "mode-"
@@ -74,6 +78,7 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
struct property *prop;
struct device_node *np = reboot->dev->of_node;
size_t len = strlen(PREFIX);
+ u32 magic;
int ret;
INIT_LIST_HEAD(&reboot->head);
@@ -82,19 +87,18 @@ 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);
+ if (device_property_read_u32(reboot->dev, prop->name, &magic)) {
+ pr_debug("reboot mode %s without magic number\n", prop->name);
+ continue;
+ }
+
+ 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);
- continue;
- }
-
+ info->magic = magic;
info->mode = kstrdup_const(prop->name + len, GFP_KERNEL);
if (!info->mode) {
ret = -ENOMEM;
@@ -102,8 +106,7 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
} else if (info->mode[0] == '\0') {
kfree_const(info->mode);
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;
}
@@ -116,8 +119,8 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
return 0;
error:
- list_for_each_entry(info, &reboot->head, list)
- kfree_const(info->mode);
+ kfree(info);
+ reboot_mode_unregister(reboot);
return ret;
}
@@ -130,11 +133,15 @@ 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);
- 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;
}
--
2.34.1
next prev parent reply other threads:[~2026-03-04 18:03 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 18:03 [PATCH v20 00/10] Implement PSCI reboot mode driver for PSCI resets Shivendra Pratap
2026-03-04 18:03 ` Shivendra Pratap [this message]
2026-03-05 10:05 ` [PATCH v20 01/10] power: reset: reboot-mode: Remove devres based allocations Bartosz Golaszewski
2026-03-11 9:21 ` Sebastian Reichel
2026-03-12 8:54 ` Shivendra Pratap
2026-04-01 15:19 ` Krzysztof Kozlowski
2026-04-02 6:15 ` Shivendra Pratap
2026-03-04 18:03 ` [PATCH v20 02/10] power: reset: reboot-mode: Add support for 64 bit magic Shivendra Pratap
2026-03-11 9:22 ` Sebastian Reichel
2026-03-04 18:03 ` [PATCH v20 03/10] power: reset: reboot-mode: Add support for predefined reboot modes Shivendra Pratap
2026-03-11 9:22 ` Sebastian Reichel
2026-03-04 18:03 ` [PATCH v20 04/10] firmware: psci: Introduce command-based reset in psci_sys_reset Shivendra Pratap
2026-03-27 14:07 ` Lorenzo Pieralisi
2026-03-31 17:38 ` Shivendra Pratap
2026-03-04 18:03 ` [PATCH v20 05/10] dt-bindings: arm: Document reboot mode magic Shivendra Pratap
2026-03-04 18:03 ` [PATCH v20 06/10] power: reset: Add psci-reboot-mode driver Shivendra Pratap
2026-03-05 10:02 ` Bartosz Golaszewski
2026-03-05 17:06 ` Shivendra Pratap
2026-03-06 13:32 ` Bartosz Golaszewski
2026-03-27 14:08 ` Lorenzo Pieralisi
2026-03-27 14:09 ` Bartosz Golaszewski
2026-03-27 13:55 ` Lorenzo Pieralisi
2026-03-27 13:59 ` Bartosz Golaszewski
2026-03-31 18:00 ` Shivendra Pratap
2026-04-01 14:37 ` Lorenzo Pieralisi
2026-04-01 14:56 ` Arnd Bergmann
2026-04-02 18:38 ` Shivendra Pratap
2026-04-02 18:35 ` Shivendra Pratap
2026-04-03 15:50 ` Lorenzo Pieralisi
2026-04-03 17:45 ` Shivendra Pratap
2026-03-27 14:14 ` Lorenzo Pieralisi
2026-03-31 17:40 ` Shivendra Pratap
2026-03-04 18:03 ` [PATCH v20 07/10] arm64: dts: qcom: qcm6490: Add psci reboot-modes Shivendra Pratap
2026-03-05 10:57 ` Konrad Dybcio
2026-03-04 18:03 ` [PATCH v20 08/10] arm64: dts: qcom: lemans: " Shivendra Pratap
2026-03-05 11:33 ` Konrad Dybcio
2026-03-05 17:52 ` Shivendra Pratap
2026-03-04 18:03 ` [PATCH v20 09/10] arm64: dts: qcom: monaco: " Shivendra Pratap
2026-03-04 18:03 ` [PATCH v20 10/10] arm64: dts: qcom: talos: " Shivendra Pratap
2026-04-06 7:36 ` [PATCH v20 00/10] Implement PSCI reboot mode driver for PSCI resets Pankaj Patil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260304-arm-psci-system_reset2-vendor-reboots-v20-1-cf7d346b8372@oss.qualcomm.com \
--to=shivendra.pratap@oss.qualcomm.com \
--cc=Souvik.Chakravarty@arm.com \
--cc=andersson@kernel.org \
--cc=andre.draszik@linaro.org \
--cc=andy.yan@rock-chips.com \
--cc=arnd@arndb.de \
--cc=brgl@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=florian.fainelli@broadcom.com \
--cc=john.stultz@linaro.org \
--cc=kathiravan.thirumoorthy@oss.qualcomm.com \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mark.rutland@arm.com \
--cc=matthias.bgg@gmail.com \
--cc=moritz.fischer@ettus.com \
--cc=mukesh.ojha@oss.qualcomm.com \
--cc=robh@kernel.org \
--cc=sre@kernel.org \
--cc=srini@kernel.org \
--cc=sudeep.holla@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox