Skip to contentSkip to conversation

Trivial code cleanup for DT resolver

PATCH In review Stephen Boyd 3 participants 6 messages Oct 13, 2017 – Oct 16, 2017 Device tree

lore
Share & tools
lore
#0 lore raw

cover Trivial code cleanup for DT resolver

Two trivial patches to the DT resolver code.

Stephen Boyd (2):
of/resolver: Simplify to be32_add_cpu() of/resolver: Replace kmalloc + memcpy with kmemdup()

 drivers/of/resolver.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
Signature · 1 line
2.14.GIT
#1 lore raw

PATCH 1/2 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.

---
 drivers/of/resolver.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/of/resolver.c +1 -4
index 99309cb7d372..2d58253bf2f7 100644
@@ -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);
 		}
 	}
 
Signature · 1 line
2.14.GIT
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] of/resolver: Simplify to be32_add_cpu()

Quoted 22 lines · Stephen Boyd

This is the same as be32_add_cpu(), so simplify the code and remove the now unused local variable.

---
 drivers/of/resolver.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/of/resolver.c +0 -1
index 99309cb7d372..2d58253bf2f7 100644
@@ -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;

drivers/of/resolver.c static int adjust_local_phandle_references(struct device_node *local_fixups, · line 200

Quoted 10 lines
drivers/of/resolver.c +1 -3
@@ -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);
 		}
 	}
 

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

PATCH 2/2 of/resolver: Replace kmalloc + memcpy with kmemdup()

In reply to Stephen Boyd

Save one line.

---
 drivers/of/resolver.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/of/resolver.c +1 -2
index 2d58253bf2f7..bd21a66f6930 100644
@@ -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;
Signature · 1 line
2.14.GIT
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] of/resolver: Replace kmalloc + memcpy with kmemdup()

Quoted 14 lines · Stephen Boyd

Save one line.

---
 drivers/of/resolver.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/of/resolver.c +0 -0
index 2d58253bf2f7..bd21a66f6930 100644
@@ -84,10 +84,9 @@ static int update_usages_of_a_phandle_reference(struct device_node *overlay,
 	int offset, len;

drivers/of/resolver.c static int update_usages_of_a_phandle_reference(struct device_node *overlay, · line 92

Quoted 10 lines
drivers/of/resolver.c +1 -2
 	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;

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#5 lore raw

Re: [PATCH 2/2] of/resolver: Replace kmalloc + memcpy with kmemdup()

In reply to Stephen Boyd
Quoted 6 lines · Stephen Boyd

Save one line.

---
 drivers/of/resolver.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Both applied. Thanks.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html