From d35d623f52f9bf58b2dc2fa08156de936e1d6770 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Fri, 13 Oct 2017 00:35:57 -0700 Subject: of/resolver: Simplify to be32_add_cpu() This is the same as be32_add_cpu(), so simplify the code and remove the now unused local variable. Signed-off-by: Stephen Boyd Reviewed-by: Frank Rowand Signed-off-by: Rob Herring --- drivers/of/resolver.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'drivers/of/resolver.c') diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c index 99309cb7d372..2d58253bf2f7 100644 --- a/drivers/of/resolver.c +++ b/drivers/of/resolver.c @@ -165,7 +165,6 @@ static int adjust_local_phandle_references(struct device_node *local_fixups, struct property *prop_fix, *prop; int err, i, count; unsigned int off; - phandle phandle; if (!local_fixups) return 0; @@ -195,9 +194,7 @@ static int adjust_local_phandle_references(struct device_node *local_fixups, if ((off + 4) > prop->length) return -EINVAL; - phandle = be32_to_cpu(*(__be32 *)(prop->value + off)); - phandle += phandle_delta; - *(__be32 *)(prop->value + off) = cpu_to_be32(phandle); + be32_add_cpu(prop->value + off, phandle_delta); } } -- cgit v1.2.1 From eeb09506c58a326e1c571b7f9ee30b7fdbc6239d Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Fri, 13 Oct 2017 00:35:58 -0700 Subject: of/resolver: Replace kmalloc + memcpy with kmemdup() Save one line. Signed-off-by: Stephen Boyd Reviewed-by: Frank Rowand Signed-off-by: Rob Herring --- drivers/of/resolver.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/of/resolver.c') diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c index 2d58253bf2f7..bd21a66f6930 100644 --- a/drivers/of/resolver.c +++ b/drivers/of/resolver.c @@ -84,10 +84,9 @@ static int update_usages_of_a_phandle_reference(struct device_node *overlay, int offset, len; int err = 0; - value = kmalloc(prop_fixup->length, GFP_KERNEL); + value = kmemdup(prop_fixup->value, prop_fixup->length, GFP_KERNEL); if (!value) return -ENOMEM; - memcpy(value, prop_fixup->value, prop_fixup->length); /* prop_fixup contains a list of tuples of path:property_name:offset */ end = value + prop_fixup->length; -- cgit v1.2.1 From f948d6d8b792bb90041edc12eac35faf83030994 Mon Sep 17 00:00:00 2001 From: Frank Rowand Date: Tue, 17 Oct 2017 16:36:29 -0700 Subject: of: overlay: avoid race condition between applying multiple overlays The process of applying an overlay consists of: - unflatten an overlay FDT (flattened device tree) into an EDT (expanded device tree) - fixup the phandle values in the overlay EDT to fit in a range above the phandle values in the live device tree - create the overlay changeset to reflect the contents of the overlay EDT - apply the overlay changeset, to modify the live device tree, potentially changing the maximum phandle value in the live device tree There is currently no protection against two overlay applies concurrently determining what range of phandle values are in use in the live device tree, and subsequently changing that range. Add a mutex to prevent multiple overlay applies from occurring simultaneously. Move of_resolve_phandles() into of_overlay_apply() so that it does not have to be duplicated by each caller of of_overlay_apply(). The test in of_resolve_phandles() that the overlay tree is detached is temporarily disabled so that old style overlay unittests do not fail. Signed-off-by: Frank Rowand Signed-off-by: Rob Herring --- drivers/of/resolver.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers/of/resolver.c') diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c index bd21a66f6930..cfaeef5f6cb1 100644 --- a/drivers/of/resolver.c +++ b/drivers/of/resolver.c @@ -271,11 +271,18 @@ int of_resolve_phandles(struct device_node *overlay) err = -EINVAL; goto out; } + +#if 0 + Temporarily disable check so that old style overlay unittests + do not fail when of_resolve_phandles() is moved into + of_overlay_apply(). + if (!of_node_check_flag(overlay, OF_DETACHED)) { pr_err("overlay not detached\n"); err = -EINVAL; goto out; } +#endif phandle_delta = live_tree_max_phandle() + 1; adjust_overlay_phandles(overlay, phandle_delta); -- cgit v1.2.1