mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] dt: factor out common code
@ 2014-11-19 13:34 Jan Luebbe
  2014-11-20 13:45 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Luebbe @ 2014-11-19 13:34 UTC (permalink / raw)
  To: barebox

Currently, dt_struct is always checked with the same code after
dt_struct_advance(). Move the check after the switch statement.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
 drivers/of/fdt.c | 33 +++++++++++----------------------
 1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index cfe183350978..d465f9879751 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -120,18 +120,14 @@ struct device_node *of_unflatten_dtb(void *infdt)
 				goto err;
 			}
 
-			dt_struct = dt_struct_advance(&f, dt_struct,
-					sizeof(struct fdt_node_header) + len + 1);
-			if (!dt_struct) {
-				ret = -ESPIPE;
-				goto err;
-			}
-
 			if (!node)
 				node = root;
 			else
 				node = of_new_node(node, pathp);
 
+			dt_struct = dt_struct_advance(&f, dt_struct,
+					sizeof(struct fdt_node_header) + len + 1);
+
 			break;
 
 		case FDT_END_NODE:
@@ -144,10 +140,6 @@ struct device_node *of_unflatten_dtb(void *infdt)
 			node = node->parent;
 
 			dt_struct = dt_struct_advance(&f, dt_struct, FDT_TAGSIZE);
-			if (!dt_struct) {
-				ret = -ESPIPE;
-				goto err;
-			}
 
 			break;
 
@@ -162,25 +154,17 @@ struct device_node *of_unflatten_dtb(void *infdt)
 				goto err;
 			}
 
-			dt_struct = dt_struct_advance(&f, dt_struct,
-					sizeof(struct fdt_property) + len);
-			if (!dt_struct) {
-				ret = -ESPIPE;
-				goto err;
-			}
-
 			p = of_new_property(node, name, nodep, len);
 			if (!strcmp(name, "phandle") && len == 4)
 				node->phandle = be32_to_cpup(p->value);
 
+			dt_struct = dt_struct_advance(&f, dt_struct,
+					sizeof(struct fdt_property) + len);
+
 			break;
 
 		case FDT_NOP:
 			dt_struct = dt_struct_advance(&f, dt_struct, FDT_TAGSIZE);
-			if (!dt_struct) {
-				ret = -ESPIPE;
-				goto err;
-			}
 
 			break;
 
@@ -192,6 +176,11 @@ struct device_node *of_unflatten_dtb(void *infdt)
 			ret = -EINVAL;
 			goto err;
 		}
+
+		if (!dt_struct) {
+			ret = -ESPIPE;
+			goto err;
+		}
 	}
 err:
 	of_delete_node(root);
-- 
2.1.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] dt: factor out common code
  2014-11-19 13:34 [PATCH] dt: factor out common code Jan Luebbe
@ 2014-11-20 13:45 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2014-11-20 13:45 UTC (permalink / raw)
  To: Jan Luebbe; +Cc: barebox

On Wed, Nov 19, 2014 at 02:34:08PM +0100, Jan Luebbe wrote:
> Currently, dt_struct is always checked with the same code after
> dt_struct_advance(). Move the check after the switch statement.
> 
> Signed-off-by: Jan Luebbe <jlu@pengutronix.de>

Applied, thanks

Sascha

> ---
>  drivers/of/fdt.c | 33 +++++++++++----------------------
>  1 file changed, 11 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index cfe183350978..d465f9879751 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -120,18 +120,14 @@ struct device_node *of_unflatten_dtb(void *infdt)
>  				goto err;
>  			}
>  
> -			dt_struct = dt_struct_advance(&f, dt_struct,
> -					sizeof(struct fdt_node_header) + len + 1);
> -			if (!dt_struct) {
> -				ret = -ESPIPE;
> -				goto err;
> -			}
> -
>  			if (!node)
>  				node = root;
>  			else
>  				node = of_new_node(node, pathp);
>  
> +			dt_struct = dt_struct_advance(&f, dt_struct,
> +					sizeof(struct fdt_node_header) + len + 1);
> +
>  			break;
>  
>  		case FDT_END_NODE:
> @@ -144,10 +140,6 @@ struct device_node *of_unflatten_dtb(void *infdt)
>  			node = node->parent;
>  
>  			dt_struct = dt_struct_advance(&f, dt_struct, FDT_TAGSIZE);
> -			if (!dt_struct) {
> -				ret = -ESPIPE;
> -				goto err;
> -			}
>  
>  			break;
>  
> @@ -162,25 +154,17 @@ struct device_node *of_unflatten_dtb(void *infdt)
>  				goto err;
>  			}
>  
> -			dt_struct = dt_struct_advance(&f, dt_struct,
> -					sizeof(struct fdt_property) + len);
> -			if (!dt_struct) {
> -				ret = -ESPIPE;
> -				goto err;
> -			}
> -
>  			p = of_new_property(node, name, nodep, len);
>  			if (!strcmp(name, "phandle") && len == 4)
>  				node->phandle = be32_to_cpup(p->value);
>  
> +			dt_struct = dt_struct_advance(&f, dt_struct,
> +					sizeof(struct fdt_property) + len);
> +
>  			break;
>  
>  		case FDT_NOP:
>  			dt_struct = dt_struct_advance(&f, dt_struct, FDT_TAGSIZE);
> -			if (!dt_struct) {
> -				ret = -ESPIPE;
> -				goto err;
> -			}
>  
>  			break;
>  
> @@ -192,6 +176,11 @@ struct device_node *of_unflatten_dtb(void *infdt)
>  			ret = -EINVAL;
>  			goto err;
>  		}
> +
> +		if (!dt_struct) {
> +			ret = -ESPIPE;
> +			goto err;
> +		}
>  	}
>  err:
>  	of_delete_node(root);
> -- 
> 2.1.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-11-20 13:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-19 13:34 [PATCH] dt: factor out common code Jan Luebbe
2014-11-20 13:45 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox