[RESEND PATCH v1 3/4] power: reset: Add support for reboot mode alternate properties
From: Elliot Berman
Date: Tue Aug 18 2020 - 14:55:13 EST
Reboot mode driver does not currently support reboot commands with
spaces in them [1]. Add an optional new node "reboot-mode-names" and
"reboot-mode-magic" which add an array of strings and u32s, respectively
which would permit any string in this framework.
Signed-off-by: Elliot Berman <eberman@xxxxxxxxxxxxxx>
---
drivers/power/reset/reboot-mode.c | 42 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
index b4076b1..363734d 100644
--- a/drivers/power/reset/reboot-mode.c
+++ b/drivers/power/reset/reboot-mode.c
@@ -64,8 +64,9 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
struct mode_info *info;
struct property *prop;
struct device_node *np = reboot->dev->of_node;
+ const char *mode_name;
size_t len = strlen(PREFIX);
- int ret;
+ int ret, count, i;
INIT_LIST_HEAD(&reboot->head);
@@ -101,6 +102,45 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
list_add_tail(&info->list, &reboot->head);
}
+ count = of_property_count_u32_elems(np, "reboot-mode-magic");
+ for (i = 0; i < count; i++) {
+ info = devm_kzalloc(reboot->dev, sizeof(*info), GFP_KERNEL);
+ if (!info) {
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ if (of_property_read_string_index(np, "reboot-mode-names", i,
+ &mode_name)) {
+ dev_err(reboot->dev, "unable to read reboot-mode-names[%d]\n",
+ i);
+ ret = -EINVAL;
+ goto error;
+ }
+ info->mode = kstrdup_const(mode_name, GFP_KERNEL);
+ if (!info->mode) {
+ ret = -ENOMEM;
+ goto error;
+ } else if (info->mode[0] == '\0') {
+ dev_err(reboot->dev, "invalid reboot-mode-names[%d]: too short!\n",
+ i);
+ kfree_const(info->mode);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ if (of_property_read_u32_index(np, "reboot-mode-magic", i,
+ &info->magic)) {
+ dev_err(reboot->dev, "unable to read reboot-mode-magic[%d]\n",
+ i);
+ kfree_const(info->mode);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ list_add_tail(&info->list, &reboot->head);
+ }
+
reboot->reboot_notifier.notifier_call = reboot_mode_notify;
register_reboot_notifier(&reboot->reboot_notifier);
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project