On Tue, Nov 9, 2010 at 12:22 PM, Peter Stuge <[email protected]> wrote: > Øyvind Harboe wrote: >> >> >> + if (detected_failure != ERROR_OK) >> >> >> + return detected_failure; >> >> >> + return retval; >> >> > >> >> > Please just use retval also for the error. > .. >> > the value of retval becomes irrelevant > .. >> Reading over the code, I can't match up what you write. > > Please look again at the above. > > There is always only *one* return value from every function, so it > seems logical that only one variable would be needed to store the > value that the function will ultimately return. > > The code above from your patch highlights this too. The if() > condition has a priority higher than the previous value of retval. > If the condition is true, retval is irrelevant. > > Another way to express this is to remove the extra variable and the > extra condition above and simply set retval (thus clobbering the > now-irrelevant value of retval) at the point where detected_failure > gets set. > > There are numerous benefits with regard to readability of the code. > Most importantly the high level logic for this function stays more > clear that it will be with two sources of return values being > arbitered between at the *end* of the function, as opposed to a > single source of (ie. single variable for) return value which in the > normal case is not touched at all, but in error cases will be changed > (since it is not irrelevant) into an error return code.
It looks funky, but there *is* something funky going on here. I don't mind setting retval = detcted_failure if detected_failure != OK if that is better. >> The normal behavior is: >> >> - detect and report failure. This is a failure that has occurred >> in the hardware previously, there is no error condition currently. >> The current function executes without any error as such. >> >> - once this error is detected, continue with the rest of the polling >> code. >> >> If an error was detected(which may have occurred millions of cycles >> before the current fn was even invoked), then report that error >> at the end of the fn. > > detected_failure is *outside* the function? Sorry then, I guess I > looked too quickly at the patch. :\ I still think the above is kinda > ugly though. Is there any way for a nicer approach? Also, is the > logic you just described really OK? It seems that some information > about the target is getting lost? (The fact that the error did not > happen *now* but some time ago, and that the current poll was OK.) Whether or not OpenOCD is running the hardware can "fail". poll() will detect such asynchronous failure(e.g. power dropout) and report an error and then subsequently clear this error. -- Øyvind Harboe Can Zylin Consulting help on your project? US toll free 1-866-980-3434 / International +47 51 63 25 00 http://www.zylin.com/zy1000.html ARM7 ARM9 ARM11 XScale Cortex JTAG debugger and flash programmer _______________________________________________ Openocd-development mailing list [email protected] https://lists.berlios.de/mailman/listinfo/openocd-development
