Skip to content

Commit 81de291

Browse files
wensWolfram Sang
authored and
Wolfram Sang
committed
of: dynamic: Add of_changeset_update_prop_string
Add a helper function to add string property updates to an OF changeset. This is similar to of_changeset_add_prop_string(), but instead of adding the property (and failing if it exists), it will update the property. This shall be used later in the DT hardware prober. Signed-off-by: Chen-Yu Tsai <[email protected]> Reviewed-by: Rob Herring (Arm) <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent aaf20f8 commit 81de291

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

drivers/of/dynamic.c

+44
Original file line numberDiff line numberDiff line change
@@ -1072,3 +1072,47 @@ int of_changeset_add_prop_bool(struct of_changeset *ocs, struct device_node *np,
10721072
return of_changeset_add_prop_helper(ocs, np, &prop);
10731073
}
10741074
EXPORT_SYMBOL_GPL(of_changeset_add_prop_bool);
1075+
1076+
static int of_changeset_update_prop_helper(struct of_changeset *ocs,
1077+
struct device_node *np,
1078+
const struct property *pp)
1079+
{
1080+
struct property *new_pp;
1081+
int ret;
1082+
1083+
new_pp = __of_prop_dup(pp, GFP_KERNEL);
1084+
if (!new_pp)
1085+
return -ENOMEM;
1086+
1087+
ret = of_changeset_update_property(ocs, np, new_pp);
1088+
if (ret)
1089+
__of_prop_free(new_pp);
1090+
1091+
return ret;
1092+
}
1093+
1094+
/**
1095+
* of_changeset_update_prop_string - Add a string property update to a changeset
1096+
*
1097+
* @ocs: changeset pointer
1098+
* @np: device node pointer
1099+
* @prop_name: name of the property to be updated
1100+
* @str: pointer to null terminated string
1101+
*
1102+
* Create a string property to be updated and add it to a changeset.
1103+
*
1104+
* Return: 0 on success, a negative error value in case of an error.
1105+
*/
1106+
int of_changeset_update_prop_string(struct of_changeset *ocs,
1107+
struct device_node *np,
1108+
const char *prop_name, const char *str)
1109+
{
1110+
struct property prop = {
1111+
.name = (char *)prop_name,
1112+
.length = strlen(str) + 1,
1113+
.value = (void *)str,
1114+
};
1115+
1116+
return of_changeset_update_prop_helper(ocs, np, &prop);
1117+
}
1118+
EXPORT_SYMBOL_GPL(of_changeset_update_prop_string);

include/linux/of.h

+4
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,10 @@ static inline int of_changeset_add_prop_u32(struct of_changeset *ocs,
16511651
return of_changeset_add_prop_u32_array(ocs, np, prop_name, &val, 1);
16521652
}
16531653

1654+
int of_changeset_update_prop_string(struct of_changeset *ocs,
1655+
struct device_node *np,
1656+
const char *prop_name, const char *str);
1657+
16541658
int of_changeset_add_prop_bool(struct of_changeset *ocs, struct device_node *np,
16551659
const char *prop_name);
16561660

0 commit comments

Comments
 (0)