Alan Ott wrote:
> 3. The code to check for it just adds a lot of bloat without much
> measurable benefit.
As a very general note, if - in any C program, not just the kernel
- you have too many error checks for comfort, you may want to
consider keeping a cumulative error status (e.g., in this case,
struct mrf24j40), and just check that. Similar to ferror in stdio.
Something like
static int my_check_and_clear_rc(struct foo *foo)
{
int rc;
rc = foo->rc;
foo->rc = 0;
return rc;
}
static int my_operation(struct foo *foo, int arg)
{
int rc;
/* don't make it worse - optional */
if (foo->rc)
return foo->rc;
rc = really_do_my_operation(foo, arg);
if (rc < 0 && !foo->rc)
foo->rc = rc;
return foo->rc ? foo->rc : rc;
}
Then the phalanx of tedious checks shrinks to
/* make sure foo->rc is initialized to 0 */
my_operation(foo, 1);
my_operation(foo, 2);
...
my_operation(foo, 1000);
rc = my_check_and_clear_rc(foo);
if (rc) {
complain("something terribly wrong");
...
}
...
You can easily extend this to also record line numbers, file
names, and such, if necessary. Add atomic/locking as needed.
- Werner
------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
_______________________________________________
Linux-zigbee-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel