On 28/01/16 13:06, Thomas Miletich wrote:
@Michael: somewhat OT, but there seems to be an unreachable call
intel_destroy_ring ( intel, &intel->rx );

in intel_open()

Yes, that's the error recovery code to undo the effects of intel_create_ring(...->rx). My usual pattern for error handling is:


  if ( ( rc = try_thing_one() ) != 0 )
     goto err_thing_one;

  ...

  if ( ( rc = try_thing_two() ) != 0 )
     goto err_thing_two;

  ...
  ...

  return 0;

  ...

  undo_thing_two();
 err_thing_two:

  ...

  undo_thing_one();
 err_thing_one:

  ...

  return rc

This means that the error recovery code is always present when the code is first written. In future, when try_thing_three() is added to the function, the developer doesn't need to remember to add the logically unrelated undo_thing_two().

The error recovery code for the latest possible error in the function will always be unreachable with this design pattern.

Michael
_______________________________________________
ipxe-devel mailing list
ipxe-devel@lists.ipxe.org
https://lists.ipxe.org/mailman/listinfo.cgi/ipxe-devel

Reply via email to