mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/4] power: reset: reboot-mode: refactor to allow other mode- prefixes
Date: Tue,  9 Aug 2022 08:29:35 +0200	[thread overview]
Message-ID: <20220809062938.1750369-1-a.fatoum@pengutronix.de> (raw)

We will add support for one more mode- prefix in the follow-up commit,
so rewrite the code to make this addition seamless.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 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 d9b51dfea677..ab23c32a4370 100644
--- a/drivers/power/reset/reboot-mode.c
+++ b/drivers/power/reset/reboot-mode.c
@@ -12,8 +12,6 @@
 #include <globalvar.h>
 #include <magicvar.h>
 
-#define PREFIX "mode-"
-
 static int __priority;
 static struct reboot_mode_driver *__boot_mode;
 
@@ -111,6 +109,17 @@ static void reboot_mode_print(struct reboot_mode_driver *reboot,
 	__pr_printk(7, "\n");
 }
 
+static const char *get_mode_name(const struct property *prop)
+{
+	unsigned prefix_len;
+
+	prefix_len = str_has_prefix(prop->name, "mode-");
+	if (!prefix_len)
+		return NULL;
+
+	return prop->name + prefix_len;
+}
+
 /**
  * reboot_mode_register - register a reboot mode driver
  * @reboot: reboot mode driver
@@ -123,7 +132,6 @@ int reboot_mode_register(struct reboot_mode_driver *reboot,
 {
 	struct property *prop;
 	struct device_node *np = reboot->dev->device_node;
-	size_t len = strlen(PREFIX);
 	const char *alias;
 	size_t nmodes = 0;
 	int i = 0;
@@ -132,7 +140,7 @@ int reboot_mode_register(struct reboot_mode_driver *reboot,
 	for_each_property_of_node(np, prop) {
 		u32 magic;
 
-		if (strncmp(prop->name, PREFIX, len))
+		if (!get_mode_name(prop))
 			continue;
 		if (of_property_read_u32(np, prop->name, &magic))
 			continue;
@@ -154,16 +162,9 @@ int reboot_mode_register(struct reboot_mode_driver *reboot,
 		magic = &reboot->magics[i * nelems];
 		mode = &reboot->modes[i];
 
-		if (strncmp(prop->name, PREFIX, len))
-			continue;
-
-		if (of_property_read_u32_array(np, prop->name, magic, nelems)) {
-			dev_err(reboot->dev, "reboot mode %s without magic number\n",
-				*mode);
+		*mode = get_mode_name(prop);
+		if (!*mode)
 			continue;
-		}
-
-		*mode = prop->name + len;
 		if (*mode[0] == '\0') {
 			ret = -EINVAL;
 			dev_err(reboot->dev, "invalid mode name(%s): too short!\n",
@@ -171,6 +172,12 @@ int reboot_mode_register(struct reboot_mode_driver *reboot,
 			goto error;
 		}
 
+		if (of_property_read_u32_array(np, prop->name, magic, nelems)) {
+			dev_err(reboot->dev, "reboot mode %s without magic number\n",
+				*mode);
+			continue;
+		}
+
 		reboot_mode_print(reboot, *mode, magic);
 
 		i++;
-- 
2.30.2




             reply	other threads:[~2022-08-09  6:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09  6:29 Ahmad Fatoum [this message]
2022-08-09  6:29 ` [PATCH 2/4] power: reset: reboot-mode: parse barebox,mode-* properties Ahmad Fatoum
2022-08-09  6:29 ` [PATCH 3/4] ARM: dts: stm32mp: reuse now upstream tamp node Ahmad Fatoum
2022-08-09  6:29 ` [PATCH 4/4] ARM: dts: stm32mp: add bootrom serial (DFU) reboot mode Ahmad Fatoum
2022-08-09  9:49   ` Sascha Hauer
2022-08-09  9:54     ` Ahmad Fatoum
2022-08-09 11:34 ` [PATCH 1/4] power: reset: reboot-mode: refactor to allow other mode- prefixes Sascha Hauer

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=20220809062938.1750369-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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