FYI, the new kernel newbie column is out
Robert P. J. Day
rpjday-L09J2beyid0N/H6P543EQg at public.gmane.org
Wed Jul 8 16:20:12 UTC 2009
On Wed, 8 Jul 2009, D. Hugh Redelmeier wrote:
> | 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 */
BTW, if you want to see the perfect example of this sort of coding,
look at, say, the tail end of drivers/usb/gadget/dummy_hcd.c. that
really is the kernel-approved way of doing things.
rday
--
========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA
Linux Consulting, Training and Annoying Kernel Pedantry.
Web page: http://crashcourse.ca
Linked In: http://www.linkedin.com/in/rpjday
Twitter: http://twitter.com/rpjday
========================================================================
--
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