]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
of: dynamic: Add of_changeset_update_prop_string
authorChen-Yu Tsai <wenst@chromium.org>
Wed, 6 Nov 2024 09:33:28 +0000 (17:33 +0800)
committerWolfram Sang <wsa+renesas@sang-engineering.com>
Wed, 27 Nov 2024 11:03:48 +0000 (12:03 +0100)
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>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
drivers/of/dynamic.c
include/linux/of.h

index d45a8df61380159af831b6f9b1650c4e46264b87..0aba760f7577ef604183e37139168c2520d0787f 100644 (file)
@@ -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 = {
+               .name = (char *)prop_name,
+               .length = strlen(str) + 1,
+               .value = (void *)str,
+       };
+
+       return of_changeset_update_prop_helper(ocs, np, &prop);
+}
+EXPORT_SYMBOL_GPL(of_changeset_update_prop_string);
index 086a60f3b8a6da1452f27757361af91d6c5c8bbd..d0307e3b093d37baf596d7db6298cdd59b91195d 100644 (file)
@@ -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);