FYI, the new kernel newbie column is out

D. Hugh Redelmeier hugh-pmF8o41NoarQT0dZR+AlfA at public.gmane.org
Wed Jul 8 16:09:43 UTC 2009


| From: Robert P. J. Day <rpjday-L09J2beyid0N/H6P543EQg at public.gmane.org>

|   http://cli.gs/0LUN27

     int err;
     /* registration takes a pointer and a name */
     err = register_this(ptr1, "skull");
     if (err) goto fail_this;
     err = register_that(ptr2, "skull");
     if (err) goto fail_that;
     err = register_those(ptr3, "skull");
     if (err) goto fail_those;
     return 0; /* success */

      fail_those: unregister_that(ptr2, "skull");
     fail_that: unregister_this(ptr1, "skull");
     fail_this: return err; /* propagate the error */

I think that the code would be clearer if written this way:

     int err;
     /* registration takes a pointer and a name */
     err = register_this(ptr1, "skull");
     if (!err) {
	 err = register_that(ptr2, "skull");
	 if (!err) {
	     err = register_those(ptr3, "skull");
	     if (!err)
		return 0; /* success */

	     unregister_that(ptr2, "skull");
	 }
	 unregister_this(ptr1, "skull");
     }
     return err; /* propagate the error */
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list