* [PATCH v2 1/5] of: add of_property_write_string_array()
2026-03-16 11:36 [PATCH v2 0/5] Add helper for security policies Fabian Pflug
@ 2026-03-16 11:36 ` Fabian Pflug
2026-03-16 11:36 ` [PATCH v2 2/5] common: bootm: add policy to commandline Fabian Pflug
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Fabian Pflug @ 2026-03-16 11:36 UTC (permalink / raw)
To: BAREBOX, Sascha Hauer; +Cc: Fabian Pflug
Helper function to write an array of string into a property.
Signed-off-by: Fabian Pflug <f.pflug@pengutronix.de>
---
drivers/of/base.c | 44 +++++++++++++++++++++++++++++++++++++++++++
include/of.h | 3 +++
test/self/of_manipulation.c | 14 +++++++++++++-
test/self/of_manipulation.dts | 5 +++++
4 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 460b5e2f4b..9cd80cf27e 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1570,6 +1570,50 @@ int of_property_write_u64_array(struct device_node *np,
return 0;
}
+/**
+ * of_property_write_string_array - Write strings to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np: device node to which the property value is to be written.
+ * @propname: name of the property to be written.
+ * @values: pointer to array elements to write.
+ * @sz: number of array elements to write.
+ *
+ * Search for a property in a device node and write a string to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created, -EINVAL if no strings specified.
+ */
+int of_property_write_string_array(struct device_node *np,
+ const char *propname, const char **values,
+ size_t sz)
+{
+ const char *val;
+ char *buf = NULL, *next;
+ size_t len = 0;
+ int ret = 0, i;
+
+ for (i = 0; i < sz; i++)
+ len += strlen(values[i]) + 1;
+
+ if (!len)
+ return -EINVAL;
+
+ buf = malloc(len);
+ if (!buf)
+ return -ENOMEM;
+
+ next = buf;
+
+ for (i = 0; i < sz; i++)
+ next = stpcpy(next, values[i]) + 1;
+
+ ret = of_set_property(np, propname, buf, len, 1);
+ free(buf);
+ return ret;
+}
+
/**
* of_property_write_strings - Write strings to a property. If
* the property does not exist, it will be created and appended to the given
diff --git a/include/of.h b/include/of.h
index ba8d1e358d..34439ee763 100644
--- a/include/of.h
+++ b/include/of.h
@@ -310,6 +310,9 @@ extern int of_property_write_string(struct device_node *np, const char *propname
const char *value);
extern int of_property_write_strings(struct device_node *np, const char *propname,
...) __attribute__((__sentinel__));
+int of_property_write_string_array(struct device_node *np,
+ const char *propname, const char **values,
+ size_t sz);
int of_property_sprintf(struct device_node *np, const char *propname, const char *fmt, ...)
__printf(3, 4);
diff --git a/test/self/of_manipulation.c b/test/self/of_manipulation.c
index 8d645b1137..faf948a17b 100644
--- a/test/self/of_manipulation.c
+++ b/test/self/of_manipulation.c
@@ -71,13 +71,19 @@ static void test_of_basics(struct device_node *root)
static void test_of_property_strings(struct device_node *root)
{
- struct device_node *np1, *np2, *np3, *np4;
+ struct device_node *np1, *np2, *np3, *np4, *np5;
char properties[] = "ayy\0bee\0sea";
+ static const char * const prop_array[] = {
+ "ayy",
+ "bee\0\0\0",
+ "sea\0",
+ };
np1 = of_new_node(root, "np1");
np2 = of_new_node(root, "np2");
np3 = of_new_node(root, "np3");
np4 = of_new_node(root, "np4");
+ np5 = of_new_node(root, "np5");
of_property_sprintf(np1, "property-single", "%c%c%c", 'a', 'y', 'y');
@@ -108,6 +114,12 @@ static void test_of_property_strings(struct device_node *root)
of_prepend_property(np4, "property-multi", "ayy", 4);
assert_equal(np3, np4);
+
+ of_property_write_string_array(np5, "property-single", prop_array, 1);
+
+ of_property_write_string_array(np5, "property-multi", prop_array, 3);
+
+ assert_equal(np4, np5);
}
static void __init test_of_manipulation(void)
diff --git a/test/self/of_manipulation.dts b/test/self/of_manipulation.dts
index 2cc6773fa9..7a1fb1217d 100644
--- a/test/self/of_manipulation.dts
+++ b/test/self/of_manipulation.dts
@@ -34,4 +34,9 @@ np4 {
property-single = "ayy";
property-multi = "ayy", "bee", "sea";
};
+
+ np5 {
+ property-single = "ayy";
+ property-multi = "ayy", "bee", "sea";
+ };
};
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 2/5] common: bootm: add policy to commandline
2026-03-16 11:36 [PATCH v2 0/5] Add helper for security policies Fabian Pflug
2026-03-16 11:36 ` [PATCH v2 1/5] of: add of_property_write_string_array() Fabian Pflug
@ 2026-03-16 11:36 ` Fabian Pflug
2026-03-16 11:36 ` [PATCH v2 3/5] security: policy: set active policy on boot Fabian Pflug
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Fabian Pflug @ 2026-03-16 11:36 UTC (permalink / raw)
To: BAREBOX, Sascha Hauer; +Cc: Fabian Pflug
If security policies are used, then the variable bootm.provide_policy
can be set to automatically append the currently selected security
policy to the kernel commandline with the prefix
barebox.security.policy=
This allows the the system to behave different based on the selected
security policy.
Signed-off-by: Fabian Pflug <f.pflug@pengutronix.de>
---
common/bootm.c | 23 +++++++++++++++++++++++
include/bootm.h | 5 +++++
2 files changed, 28 insertions(+)
diff --git a/common/bootm.c b/common/bootm.c
index d43079bb81..9484539bc3 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -22,6 +22,7 @@
#include <uncompress.h>
#include <zero_page.h>
#include <security/config.h>
+#include <security/policy.h>
static LIST_HEAD(handler_list);
static struct sconfig_notifier_block sconfig_notifier;
@@ -75,6 +76,7 @@ static int bootm_dryrun;
static int bootm_earlycon;
static int bootm_provide_machine_id;
static int bootm_provide_hostname;
+static int bootm_provide_policy;
static int bootm_verbosity;
static int bootm_efi_mode = BOOTM_EFI_AVAILABLE;
@@ -97,6 +99,7 @@ void bootm_data_init_defaults(struct bootm_data *data)
data->appendroot = bootm_appendroot;
data->provide_machine_id = bootm_provide_machine_id;
data->provide_hostname = bootm_provide_hostname;
+ data->provide_policy = bootm_provide_policy;
data->verbose = bootm_verbosity;
data->dryrun = bootm_dryrun;
data->efi_boot = bootm_efi_mode;
@@ -118,6 +121,7 @@ void bootm_data_restore_defaults(const struct bootm_data *data)
bootm_appendroot = data->appendroot;
bootm_provide_machine_id = data->provide_machine_id;
bootm_provide_hostname = data->provide_hostname;
+ bootm_provide_policy = data->provide_policy;
bootm_verbosity = data->verbose;
bootm_dryrun = data->dryrun;
bootm_efi_mode = data->efi_boot;
@@ -759,6 +763,20 @@ int bootm_boot(struct bootm_data *bootm_data)
free(hostname_bootarg);
}
+ if (IS_ENABLED(CONFIG_SECURITY_POLICY) && bootm_data->provide_policy) {
+ char *policy_bootargs;
+
+ if (active_policy && !active_policy->name) {
+ pr_err("Providing policy is enabled but policy has no name\n");
+ ret = -EINVAL;
+ goto err_out;
+ }
+
+ policy_bootargs = basprintf("barebox.security.policy=%s", active_policy->name);
+ globalvar_add_simple("linux.bootargs.dyn.policy", policy_bootargs);
+ free(policy_bootargs);
+ }
+
pr_info("\nLoading %s '%s'", file_type_to_string(data->kernel_type),
data->os_file);
if (data->kernel_type == filetype_uimage &&
@@ -967,6 +985,8 @@ static int bootm_init(void)
globalvar_add_simple_bool("bootm.earlycon", &bootm_earlycon);
globalvar_add_simple_bool("bootm.provide_machine_id", &bootm_provide_machine_id);
globalvar_add_simple_bool("bootm.provide_hostname", &bootm_provide_hostname);
+ if (IS_ENABLED(CONFIG_SECURITY_POLICY))
+ globalvar_add_simple_bool("bootm.provide_policy", &bootm_provide_policy);
if (IS_ENABLED(CONFIG_BOOTM_INITRD)) {
globalvar_add_simple("bootm.initrd", NULL);
globalvar_add_simple("bootm.initrd.loadaddr", NULL);
@@ -1030,3 +1050,6 @@ BAREBOX_MAGICVAR(global.bootm.root_dev, "bootm default root device (overrides de
BAREBOX_MAGICVAR(global.bootm.root_param, "bootm root parameter name (normally 'root' for root=/dev/...)");
BAREBOX_MAGICVAR(global.bootm.provide_machine_id, "If true, append systemd.machine_id=$global.machine_id to Kernel command line");
BAREBOX_MAGICVAR(global.bootm.provide_hostname, "If true, append systemd.hostname=$global.hostname to Kernel command line");
+#ifdef CONFIG_SECURITY_POLICY
+BAREBOX_MAGICVAR(global.bootm.provide_policy, "Add barebox.security.policy= option to Kernel");
+#endif
diff --git a/include/bootm.h b/include/bootm.h
index 21feb1ca98..a712010b2b 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -46,6 +46,11 @@ struct bootm_data {
* of global.hostname to Kernel.
*/
bool provide_hostname;
+ /*
+ * provide_policy - if true, try to add barebox.security.policy= with
+ * with value of currently selected policy
+ */
+ bool provide_policy;
enum bootm_efi_mode efi_boot;
unsigned long initrd_address;
unsigned long os_address;
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 3/5] security: policy: set active policy on boot
2026-03-16 11:36 [PATCH v2 0/5] Add helper for security policies Fabian Pflug
2026-03-16 11:36 ` [PATCH v2 1/5] of: add of_property_write_string_array() Fabian Pflug
2026-03-16 11:36 ` [PATCH v2 2/5] common: bootm: add policy to commandline Fabian Pflug
@ 2026-03-16 11:36 ` Fabian Pflug
2026-03-16 11:36 ` [PATCH v2 4/5] security: configure pinctrl based on policy name Fabian Pflug
2026-03-16 11:36 ` [PATCH v2 5/5] security: kernel_pinctrl: fixup pinctrl in kernel dts Fabian Pflug
4 siblings, 0 replies; 7+ messages in thread
From: Fabian Pflug @ 2026-03-16 11:36 UTC (permalink / raw)
To: BAREBOX, Sascha Hauer; +Cc: Fabian Pflug
If init name has been set at compiletime and the policy is available,
because it is part of the path, then set the active policy to the policy
selected by compiletime.
Since this is so early in the bootchain, there is no need to call
security_policy_activate, because there should not be any registered
callbacks at this moment in time.
If no policy could be found, then it will be filled as before by the
first call to is_allowed.
Signed-off-by: Fabian Pflug <f.pflug@pengutronix.de>
---
security/policy.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/security/policy.c b/security/policy.c
index 85333d9e6f..e2d1b10a78 100644
--- a/security/policy.c
+++ b/security/policy.c
@@ -235,6 +235,9 @@ static int security_init(void)
if (*CONFIG_SECURITY_POLICY_PATH)
security_policy_add(default);
+ if (*CONFIG_SECURITY_POLICY_INIT)
+ active_policy = security_policy_get(CONFIG_SECURITY_POLICY_INIT);
+
return 0;
}
pure_initcall(security_init);
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 4/5] security: configure pinctrl based on policy name
2026-03-16 11:36 [PATCH v2 0/5] Add helper for security policies Fabian Pflug
` (2 preceding siblings ...)
2026-03-16 11:36 ` [PATCH v2 3/5] security: policy: set active policy on boot Fabian Pflug
@ 2026-03-16 11:36 ` Fabian Pflug
2026-03-16 11:36 ` [PATCH v2 5/5] security: kernel_pinctrl: fixup pinctrl in kernel dts Fabian Pflug
4 siblings, 0 replies; 7+ messages in thread
From: Fabian Pflug @ 2026-03-16 11:36 UTC (permalink / raw)
To: BAREBOX, Sascha Hauer; +Cc: Fabian Pflug
When using security policies to disable console input on the default
console, it might be more advantagous to also disable the RX pin hard
in pinctrl, so that if there is a software error with the security
policy implementation input does not reach to system and cannot be
exploited.
An example devicetree could look like this:
/ {
chosen {
stdout-path = &uart3;
};
};
&uart3 {
pinctrl-names = "default", "barebox,policy-devel";
pinctrl-0 = <&pinctrl_uart3_tx_only>;
pinctrl-1 = <&pinctrl_uart3_interactive>;
status = "okay";
};
&iomuxc {
pinctrl_uart3_interactive: uart3ingrp {
fsl,pins = <MX8MP_IOMUXC_SD1_DATA6__UART3_DCE_TX 0x140>,
<MX8MP_IOMUXC_SD1_DATA7__UART3_DCE_RX 0x140>;
};
pinctrl_uart3_tx_only: uart3txgrp {
fsl,pins = <MX8MP_IOMUXC_SD1_DATA6__UART3_DCE_TX 0x140>,
<MX8MP_IOMUXC_SD1_DATA7__GPIO2_IO09 0x140>;
};
};
This would apply the devel pinmux on selecting the devel config and the
default on every other configuration.
A Kconfig option to enable this feature has been chosen, because parsing
pinctrl and mapping the names is a lot of string operations, that could
increase boottime for a feature, that is maybe not needed for everyone.
Signed-off-by: Fabian Pflug <f.pflug@pengutronix.de>
---
drivers/base/driver.c | 12 +++++++++++-
security/Kconfig.policy | 8 ++++++++
security/policy.c | 12 ++++++++++++
3 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 20beb1e9e6..147c3cbad8 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -30,6 +30,7 @@
#include <pinctrl.h>
#include <featctrl.h>
#include <linux/clk/clk-conf.h>
+#include <security/policy.h>
#ifdef CONFIG_DEBUG_PROBES
#define pr_report_probe pr_info
@@ -135,7 +136,16 @@ int device_probe(struct device *dev)
pr_report_probe("%*sprobe-> %s\n", depth * 4, "", dev_name(dev));
- pinctrl_select_state_default(dev);
+
+ if (IS_ENABLED(CONFIG_SECURITY_POLICY_PINCTRL)) {
+ char *policy_pinctrl;
+
+ policy_pinctrl = basprintf("barebox,policy-%s", active_policy->name);
+ if (IS_ERR(pinctrl_get_select(dev, policy_pinctrl)))
+ pinctrl_select_state_default(dev);
+ free(policy_pinctrl);
+ } else
+ pinctrl_select_state_default(dev);
of_clk_set_defaults(dev->of_node, false);
list_add(&dev->active, &active_device_list);
diff --git a/security/Kconfig.policy b/security/Kconfig.policy
index 9ea52e91da..8ddb67ac2d 100644
--- a/security/Kconfig.policy
+++ b/security/Kconfig.policy
@@ -68,6 +68,14 @@ config SECURITY_POLICY_DEFAULT_PERMISSIVE
A security policy should always be selected, either early on by
board code or via CONFIG_SECURITY_POLICY_INIT.
+config SECURITY_POLICY_PINCTRL
+ bool "Update pinctrl based on policy-name"
+ help
+ Changing the security policy, will look for a pinctrl with the name
+ barebox,policy-<policyname>. If there is one, it will change the
+ pinctrl for this. This could be used to disable the RX (and TX)
+ Pin in lockdown mode for the console or disable the usage of SPI.
+
config SECURITY_POLICY_PATH
string
depends on SECURITY_POLICY
diff --git a/security/policy.c b/security/policy.c
index e2d1b10a78..4d51af63e7 100644
--- a/security/policy.c
+++ b/security/policy.c
@@ -7,6 +7,7 @@
#include <linux/bitmap.h>
#include <param.h>
#include <device.h>
+#include <pinctrl.h>
#include <stdio.h>
#include <security/policy.h>
@@ -90,12 +91,23 @@ bool is_allowed(const struct security_policy *policy, unsigned option)
int security_policy_activate(const struct security_policy *policy)
{
const struct security_policy *old_policy = active_policy;
+ struct device *dev;
+ char *policy_pinctrl;
if (policy == old_policy)
return 0;
active_policy = policy;
+ if (IS_ENABLED(CONFIG_SECURITY_POLICY_PINCTRL)) {
+ policy_pinctrl = basprintf("barebox,policy-%s", active_policy->name);
+ list_for_each_entry(dev, &active_device_list, active) {
+ if (IS_ERR(pinctrl_get_select(dev, policy_pinctrl)))
+ pinctrl_select_state_default(dev);
+ }
+ free(policy_pinctrl);
+ }
+
for (int i = 0; i < SCONFIG_NUM; i++) {
if (__is_allowed(policy, i) == __is_allowed(old_policy, i))
continue;
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 5/5] security: kernel_pinctrl: fixup pinctrl in kernel dts
2026-03-16 11:36 [PATCH v2 0/5] Add helper for security policies Fabian Pflug
` (3 preceding siblings ...)
2026-03-16 11:36 ` [PATCH v2 4/5] security: configure pinctrl based on policy name Fabian Pflug
@ 2026-03-16 11:36 ` Fabian Pflug
2026-03-17 10:07 ` Sascha Hauer
4 siblings, 1 reply; 7+ messages in thread
From: Fabian Pflug @ 2026-03-16 11:36 UTC (permalink / raw)
To: BAREBOX, Sascha Hauer; +Cc: Fabian Pflug
Going through the kernel dts and replacing
barebox,policy-<active_policy> with default in order to change pinctrl
not only for barebox, but also for kernel when booting with security
profiles.
Signed-off-by: Fabian Pflug <f.pflug@pengutronix.de>
---
security/Makefile | 1 +
security/kernel_pinctrl.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+)
diff --git a/security/Makefile b/security/Makefile
index 1096cbfb9b..2e8cdfe7c2 100644
--- a/security/Makefile
+++ b/security/Makefile
@@ -2,6 +2,7 @@
obj-$(CONFIG_SECURITY_POLICY) += policy.o
obj-$(CONFIG_SECURITY_POLICY_NAMES) += sconfig_names.o
+obj-$(CONFIG_SECURITY_POLICY_PINCTRL) += kernel_pinctrl.o
obj-$(CONFIG_CRYPTO_KEYSTORE) += keystore.o
obj-$(CONFIG_JWT) += jwt.o
obj-pbl-$(CONFIG_HAVE_OPTEE) += optee.o
diff --git a/security/kernel_pinctrl.c b/security/kernel_pinctrl.c
new file mode 100644
index 0000000000..af65961bbc
--- /dev/null
+++ b/security/kernel_pinctrl.c
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <common.h>
+#include <linux/printk.h>
+#include <pinctrl.h>
+#include <security/policy.h>
+#include <security/config.h>
+
+#define NUM_NAMES 10
+
+
+/**
+ * Replace 'default' with 'old_default' and 'barebox,policy-<active_policy>'
+ * with 'default', if both are found in pinctrl.
+ */
+static void kernel_of_fixup_pinctrl(struct device_node *node, char *policy_name)
+{
+ const char *names[NUM_NAMES];
+ int num_read, pos_default, pos_policy;
+ struct device_node *next;
+
+ while (node) {
+ num_read = of_property_read_string_array(node, "pinctrl-names", names, NUM_NAMES);
+
+ pos_default = -1;
+ pos_policy = -1;
+ for (int i = 0; i < num_read; i++) {
+ if (strcmp(policy_name, names[i]) == 0)
+ pos_policy = i;
+ if (strcmp("default", names[i]) == 0)
+ pos_default = i;
+ }
+ if (pos_default >= 0 && pos_policy >= 0) {
+ names[pos_default] = "old_default";
+ names[pos_policy] = "default";
+ of_property_write_string_array(node, "pinctrl-names", names, num_read);
+ }
+
+ next = list_first_entry(&node->list, struct device_node, list);
+ node = next->parent ? next : NULL;
+ }
+}
+
+static int kernel_of_fixup_pinctrl_start(struct device_node *root, void *unused)
+{
+ char *policy_pinctrl;
+
+ policy_pinctrl = basprintf("barebox,policy-%s", active_policy->name);
+ kernel_of_fixup_pinctrl(root, policy_pinctrl);
+ free(policy_pinctrl);
+ return 0;
+}
+
+static int policy_console_pinctrl_init(void)
+{
+ return of_register_fixup(kernel_of_fixup_pinctrl_start, NULL);
+}
+late_initcall(policy_console_pinctrl_init);
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2 5/5] security: kernel_pinctrl: fixup pinctrl in kernel dts
2026-03-16 11:36 ` [PATCH v2 5/5] security: kernel_pinctrl: fixup pinctrl in kernel dts Fabian Pflug
@ 2026-03-17 10:07 ` Sascha Hauer
0 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2026-03-17 10:07 UTC (permalink / raw)
To: Fabian Pflug; +Cc: BAREBOX
On Mon, Mar 16, 2026 at 12:36:32PM +0100, Fabian Pflug wrote:
> Going through the kernel dts and replacing
> barebox,policy-<active_policy> with default in order to change pinctrl
> not only for barebox, but also for kernel when booting with security
> profiles.
>
> Signed-off-by: Fabian Pflug <f.pflug@pengutronix.de>
> ---
> security/Makefile | 1 +
> security/kernel_pinctrl.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 59 insertions(+)
>
> diff --git a/security/Makefile b/security/Makefile
> index 1096cbfb9b..2e8cdfe7c2 100644
> --- a/security/Makefile
> +++ b/security/Makefile
> @@ -2,6 +2,7 @@
>
> obj-$(CONFIG_SECURITY_POLICY) += policy.o
> obj-$(CONFIG_SECURITY_POLICY_NAMES) += sconfig_names.o
> +obj-$(CONFIG_SECURITY_POLICY_PINCTRL) += kernel_pinctrl.o
> obj-$(CONFIG_CRYPTO_KEYSTORE) += keystore.o
> obj-$(CONFIG_JWT) += jwt.o
> obj-pbl-$(CONFIG_HAVE_OPTEE) += optee.o
> diff --git a/security/kernel_pinctrl.c b/security/kernel_pinctrl.c
> new file mode 100644
> index 0000000000..af65961bbc
> --- /dev/null
> +++ b/security/kernel_pinctrl.c
> @@ -0,0 +1,58 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +#include <common.h>
> +#include <linux/printk.h>
> +#include <pinctrl.h>
> +#include <security/policy.h>
> +#include <security/config.h>
> +
> +#define NUM_NAMES 10
> +
> +
> +/**
> + * Replace 'default' with 'old_default' and 'barebox,policy-<active_policy>'
> + * with 'default', if both are found in pinctrl.
> + */
> +static void kernel_of_fixup_pinctrl(struct device_node *node, char *policy_name)
> +{
> + const char *names[NUM_NAMES];
> + int num_read, pos_default, pos_policy;
You could reduce the scope of these variables.
> + struct device_node *next;
> +
> + while (node) {
list_for_each_entry(np, &node->list, list)
Or move the of_tree_for_each_node_from macro to include/of.h
> + num_read = of_property_read_string_array(node, "pinctrl-names", names, NUM_NAMES);
> +
> + pos_default = -1;
> + pos_policy = -1;
> + for (int i = 0; i < num_read; i++) {
> + if (strcmp(policy_name, names[i]) == 0)
> + pos_policy = i;
> + if (strcmp("default", names[i]) == 0)
> + pos_default = i;
> + }
> + if (pos_default >= 0 && pos_policy >= 0) {
> + names[pos_default] = "old_default";
> + names[pos_policy] = "default";
> + of_property_write_string_array(node, "pinctrl-names", names, num_read);
> + }
> +
> + next = list_first_entry(&node->list, struct device_node, list);
> + node = next->parent ? next : NULL;
> + }
> +}
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 7+ messages in thread