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 <wenst@chromium.org>
---
Changes since v3:
- Use new __of_prop_free() helper
- Add new line before header declaration
Changes since v2:
- New patch added in v3
---
drivers/of/dynamic.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
include/linux/of.h | 4 ++++
2 files changed, 48 insertions(+)
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index 110104a936d9..dfd1358d59d5 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -1072,3 +1072,47 @@ int of_changeset_add_prop_bool(struct of_changeset *ocs, struct device_node *np,
return of_changeset_add_prop_helper(ocs, np, &prop);
}
EXPORT_SYMBOL_GPL(of_changeset_add_prop_bool);
+
+static int of_changeset_update_prop_helper(struct of_changeset *ocs,
+ struct device_node *np,
+ const struct property *pp)
+{
+ struct property *new_pp;
+ int ret;
+
+ new_pp = __of_prop_dup(pp, GFP_KERNEL);
+ if (!new_pp)
+ return -ENOMEM;
+
+ ret = of_changeset_update_property(ocs, np, new_pp);
+ if (ret)
+ __of_prop_free(new_pp);
+
+ return ret;
+}
+
+/**
+ * of_changeset_update_prop_string - Add a string property update to a changeset
+ *
+ * @ocs: changeset pointer
+ * @np: device node pointer
+ * @prop_name: name of the property to be updated
+ * @str: pointer to null terminated string
+ *
+ * Create a string property to be updated and add it to a changeset.
+ *
+ * Return: 0 on success, a negative error value in case of an error.
+ */
+int of_changeset_update_prop_string(struct of_changeset *ocs,
+ struct device_node *np,
+ const char *prop_name, const char *str)
+{
+ struct property prop;
+
+ prop.name = (char *)prop_name;
+ prop.length = strlen(str) + 1;
+ prop.value = (void *)str;
+
+ return of_changeset_update_prop_helper(ocs, np, &prop);
+}
+EXPORT_SYMBOL_GPL(of_changeset_update_prop_string);
diff --git a/include/linux/of.h b/include/linux/of.h
index 85b60ac9eec5..046283be1cd3 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -1651,6 +1651,10 @@ static inline int of_changeset_add_prop_u32(struct of_changeset *ocs,
return of_changeset_add_prop_u32_array(ocs, np, prop_name, &val, 1);
}
+int of_changeset_update_prop_string(struct of_changeset *ocs,
+ struct device_node *np,
+ const char *prop_name, const char *str);
+
int of_changeset_add_prop_bool(struct of_changeset *ocs, struct device_node *np,
const char *prop_name);
--
2.46.0.rc2.264.g509ed76dc8-goog
On Thu, Aug 08, 2024 at 05:59:24PM +0800, Chen-Yu Tsai wrote: > 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. ... > +int of_changeset_update_prop_string(struct of_changeset *ocs, > + struct device_node *np, > + const char *prop_name, const char *str) > +{ > + struct property prop; > + > + prop.name = (char *)prop_name; > + prop.length = strlen(str) + 1; > + prop.value = (void *)str; Is it the existing style in the file? Otherwise I often see style like this struct property prop = { .name = (char *)prop_name; .length = strlen(str) + 1; .value = (void *)str; }; in the kernel (IRQ domain, platform core, ...). > + return of_changeset_update_prop_helper(ocs, np, &prop); > +} -- With Best Regards, Andy Shevchenko
On Tue, Aug 13, 2024 at 02:11:30PM +0300, Andy Shevchenko wrote: > On Thu, Aug 08, 2024 at 05:59:24PM +0800, Chen-Yu Tsai wrote: > > 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. > > ... > > > +int of_changeset_update_prop_string(struct of_changeset *ocs, > > + struct device_node *np, > > + const char *prop_name, const char *str) > > +{ > > + struct property prop; > > + > > + prop.name = (char *)prop_name; > > + prop.length = strlen(str) + 1; > > + prop.value = (void *)str; > > Is it the existing style in the file? Otherwise I often see style like this > > struct property prop = { > .name = (char *)prop_name; > .length = strlen(str) + 1; > .value = (void *)str; > }; > > in the kernel (IRQ domain, platform core, ...). Okay with me to use this style regardless of existing style. Rob
On Wed, Aug 14, 2024 at 3:18 AM Rob Herring <robh@kernel.org> wrote: > > On Tue, Aug 13, 2024 at 02:11:30PM +0300, Andy Shevchenko wrote: > > On Thu, Aug 08, 2024 at 05:59:24PM +0800, Chen-Yu Tsai wrote: > > > 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. > > > > ... > > > > > +int of_changeset_update_prop_string(struct of_changeset *ocs, > > > + struct device_node *np, > > > + const char *prop_name, const char *str) > > > +{ > > > + struct property prop; > > > + > > > + prop.name = (char *)prop_name; > > > + prop.length = strlen(str) + 1; > > > + prop.value = (void *)str; > > > > Is it the existing style in the file? Otherwise I often see style like this Yeah. This was mostly copy pasted. > > > > struct property prop = { > > .name = (char *)prop_name; > > .length = strlen(str) + 1; > > .value = (void *)str; > > }; > > > > in the kernel (IRQ domain, platform core, ...). > > Okay with me to use this style regardless of existing style. Ack. I'll update it to the more modern style. ChenYu
© 2016 - 2024 Red Hat, Inc.