Re: [PATCH 3/7] staging: unisys: cleanup goto in create_visor_device()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 23, 2016 at 10:01:51AM -0500, Benjamin Romer wrote:
> Get rid of the rc = -1 initialization, and remove the goto
> mess entirely. Return a meaningful error on failure in the function, or
> the rc from a called function if it fails.
> 
> Signed-off-by: Benjamin Romer <benjamin.romer@xxxxxxxxxx>
> ---

For these kinds of things it's better to use gotos to unwind.  Error
handling should basically be mindless and mechanical.  Name the label
after the thing which is freed or what the label does.

err_unregister:
	device_unregister(&dev->device);
err_put:
	put_device(&dev->device);

	return rc;

When you're reviewing, you only have to care about the most recent
allocation.  After this point we need to call put_device().  After this
point we need to call unregister.  The "goto unregister" is pretty
obvious what it does so it means you don't have to scroll down.  Then
when you read to the bottom, it's pretty obvious that the labels do
what the name implies.

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux