Skip to contentSkip to conversation

dtc: Simplify error handling for unparseable input

PATCH David Gibson 2 participants 9 messages Mar 24, 2008 – Mar 26, 2008

lore
Share & tools
lore
#0 lore raw

Currently, main() tests if it got a valid input tree from whichever dt_from_*() function it invoked and if not, die()s. For one thing, this test has, for no good reason, three different ways for those functions to communicate a failure to provide input (bi NULL, bi->dt NULL, or bi->error non-zero). For another, in every case save one, if the dt_from_*() functions are unable to provide input they will immediately die() (with a more specific error message) rather than proceeding to the test in main().

Therefore, this patch removes this test, making the one case that could have triggered it (in dt_from_source()) call die() directly instead. With this change, the error field in struct boot_info is now unused, so remove it.

---
 dtc.c        |    3 ---
 dtc.h        |    1 -
 livetree.c   |    1 -
 treesource.c |    6 ++++--
 4 files changed, 4 insertions(+), 7 deletions(-)
dtc.h +0 -1
Index: dtc/dtc.h
===================================================================
@@ -232,7 +232,6 @@
 struct boot_info {
 	struct reserve_info *reservelist;
 	struct node *dt;		/* the device tree */
-	int error;
 };
 
 struct boot_info *build_boot_info(struct reserve_info *reservelist,
livetree.c +0 -1
Index: dtc/livetree.c
===================================================================
@@ -172,7 +172,6 @@
 	bi = xmalloc(sizeof(*bi));
 	bi->reservelist = reservelist;
 	bi->dt = tree;
-	bi->error = 0;
 
 	return bi;
 }
dtc.c +0 -3
Index: dtc/dtc.c
===================================================================
@@ -201,9 +201,6 @@
 	if (inf && inf->file != stdin)
 		fclose(inf->file);
 
-	if (! bi || ! bi->dt || bi->error)
-		die("Couldn't read input tree\n");
-
 	fill_fullpaths(bi->dt, "");
 	process_checks(force, bi);
 
treesource.c +4 -2
Index: dtc/treesource.c
===================================================================
@@ -36,9 +36,11 @@
 	yyin = srcpos_file->file;
 
 	if (yyparse() != 0)
-		return NULL;
+		die("Unable to parse input tree\n");
+
+	if (treesource_error)
+		die("Syntax error parsing input tree\n");
 
-	the_boot_info->error = treesource_error;
 	return the_boot_info;
 }
 
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#1 lore raw

dtc.h line 235

Quoted 10 lines · David Gibson

Index: dtc/dtc.h
===================================================================

dtc.h +0 -1
@@ -232,7 +232,6 @@
 struct boot_info {
 	struct reserve_info *reservelist;
 	struct node *dt;		/* the device tree */
-	int error;
 };

If you remove this, there'll be no way to indicate semantic errors other than die() (the NULL approaches are no good, since they inhibit recovery), which is suboptimal if the error is not immediately fatal.

-Scott

#2 lore raw
Quoted 15 lines · Scott Wood

dtc.h line 235

Quoted 10 lines · David Gibson

Index: dtc/dtc.h
===================================================================

dtc.h +0 -1
@@ -232,7 +232,6 @@
 struct boot_info {
 	struct reserve_info *reservelist;
 	struct node *dt;		/* the device tree */
-	int error;
 };

If you remove this, there'll be no way to indicate semantic errors other than die() (the NULL approaches are no good, since they inhibit recovery), which is suboptimal if the error is not immediately fatal.

But everything is immediately fatal. When we have a *real* example of something that's not, we can restore an error code.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#3 lore raw
Quoted 7 lines · David Gibson
Quoted 3 lines · Scott Wood

If you remove this, there'll be no way to indicate semantic errors other than die() (the NULL approaches are no good, since they inhibit recovery), which is suboptimal if the error is not immediately fatal.

But everything is immediately fatal. When we have a *real* example of something that's not, we can restore an error code.

Failed binary includes are not immediately fatal.

-Scott

#4 lore raw
Quoted 10 lines · Scott Wood
Quoted 7 lines · David Gibson
Quoted 3 lines · Scott Wood

If you remove this, there'll be no way to indicate semantic errors other than die() (the NULL approaches are no good, since they inhibit recovery), which is suboptimal if the error is not immediately fatal.

But everything is immediately fatal. When we have a *real* example of something that's not, we can restore an error code.

Failed binary includes are not immediately fatal.

And is there any advantage to having them not immediately fatal?

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#5 lore raw
Quoted 11 lines · David Gibson
Quoted 8 lines · Scott Wood
Quoted 6 lines · David Gibson
Quoted 3 lines · Scott Wood

If you remove this, there'll be no way to indicate semantic errors other than die() (the NULL approaches are no good, since they inhibit recovery), which is suboptimal if the error is not immediately fatal.

But everything is immediately fatal. When we have a *real* example of something that's not, we can restore an error code.

Failed binary includes are not immediately fatal.

And is there any advantage to having them not immediately fatal?

It's generally nice to the user if you can report as many bugs as you can rather than fail on the first one.

It's also nice to someone down the road trying to turn this code into a library if it passes return status up the call chain gracefully.

-Scott

#6 lore raw
Quoted 9 lines · Scott Wood
Quoted 8 lines · David Gibson
Quoted 7 lines · Scott Wood
Quoted 6 lines · David Gibson
Quoted 5 lines · Scott Wood

If you remove this, there'll be no way to indicate semantic errors other
than die() (the NULL approaches are no good, since they inhibit recovery),
which is suboptimal if the error is not immediately fatal.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

But everything is immediately fatal. When we have a *real* example of something that's not, we can restore an error code.

Failed binary includes are not immediately fatal.

And is there any advantage to having them not immediately fatal?

It's generally nice to the user if you can report as many bugs as you can rather than fail on the first one.

Hrm, I guess. There's only so far it's worth going to achieve that though.

Quoted 2 lines

It's also nice to someone down the road trying to turn this code into a library if it passes return status up the call chain gracefully.

Can you think of any reason we'd want to do that? And that would require fixing so many other places that the two cases which do return an error (that's including binary includes) hardly signify.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#7 lore raw
Quoted 11 lines · David Gibson
Quoted 2 lines · Scott Wood

It's generally nice to the user if you can report as many bugs as you can rather than fail on the first one.

Hrm, I guess. There's only so far it's worth going to achieve that though.

Quoted 2 lines

It's also nice to someone down the road trying to turn this code into a library if it passes return status up the call chain gracefully.

Can you think of any reason we'd want to do that?

Anything that wants to do something automated with device tree source that doesn't fit neatly into command-line execution. Nothing specific.

Quoted 3 lines

And that would require fixing so many other places that the two cases which do return an error (that's including binary includes) hardly signify.

Yeah, I just wanted to avoid going further down that path if possible.

I won't protest too loudly if the general consensus is to just die(), though.

-Scott

#8 lore raw
In reply to Scott Wood
Quoted 9 lines · Scott Wood
Quoted 8 lines · David Gibson
Quoted 7 lines · Scott Wood
Quoted 6 lines · David Gibson
Quoted 5 lines · Scott Wood

If you remove this, there'll be no way to indicate semantic errors other
than die() (the NULL approaches are no good, since they inhibit recovery),
which is suboptimal if the error is not immediately fatal.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

But everything is immediately fatal. When we have a *real* example of something that's not, we can restore an error code.

Failed binary includes are not immediately fatal.

And is there any advantage to having them not immediately fatal?

It's generally nice to the user if you can report as many bugs as you can rather than fail on the first one.

Oh.. and this patch doesn't actually preclude that. We still have the treesource_error variable and can report errors that way during the parse. The die() just comes at the end of dt_from_source(), instead of in main().

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson