linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: DaeSeok Youn <daeseok.youn@gmail.com>
Cc: devel <devel@driverdev.osuosl.org>,
	Lidza Louina <lidza.louina@gmail.com>,
	driverdev-devel@linuxdriverproject.org,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Greg KH <gregkh@linuxfoundation.org>,
	Mark Hounschell <markh@compro.net>
Subject: Re: [PATCH V2] staging: dgap: implement proper error handling in dgap_firmware_load()
Date: Wed, 28 May 2014 10:02:33 +0300	[thread overview]
Message-ID: <20140528070233.GP17724@mwanda> (raw)
In-Reply-To: <CAHb8M2AceJeFv-KonF+bAFJ-+xssFxx5ytEKhMNZ1c3xm2jvZA@mail.gmail.com>

We are talking about different things I think.  What I'm saying is that
there is the normal way to do error handling in the kernel.  That's with
a series of labels like this:

	...
	return 0;

err_free_ttys:
	free_ttys();
err_free_channels:
	free_channels();
err_free_brd:
	free_brd();

	return ret;

In this code there are no if statements unless absolutely needed because
of an matching if statement in the allocation code.  The label names
describe what happens at the label.  It is in reverse order from the way
the variables were allocated.

The other thing is that at the end of dgap_tty_register() we have
unwinding like this.

  1304  unregister_serial_drv:
  1305          tty_unregister_driver(brd->serial_driver);
  1306  free_print_drv:
  1307          put_tty_driver(brd->print_driver);
  1308  free_serial_drv:
  1309          put_tty_driver(brd->serial_driver);

We can add a tty_unregister_driver(brd->print_driver) and create a
dgap_tty_unregister().

static void dgap_tty_unregister(struct board_t *brd)
{
	tty_unregister_driver(brd->print_driver);
	tty_unregister_driver(brd->serial_driver);
	put_tty_driver(brd->print_driver);
	put_tty_driver(brd->serial_driver);
}

Very simple and nice.

If you have one label it makes the code too complicated and it causes
bugs.  We call them "one err bugs" because there is one error label.

In your patch it has:
+       dgap_tty_uninit(brd, false);

But it should only be "false" if dgap_tty_init() failed.  If
dgap_tty_register_ports() fails then it should be "true".  Another
problem is that as you say, the earlier function are allocating
resources like dgap_tty_register() but only the last two function calls
have a "goto err_cleanup;" so the error handling is incomplete.

To be honest, I think once dgap the code is cleaned up this error
handling will be easy to write.  We shouldn't have things like:
brd->dgap_major_serial_registered = TRUE; because we will know which
order things were registered and unregister them in the reverse order.

regards,
dan carpenter


  reply	other threads:[~2014-05-28  7:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-27  7:09 [PATCH V2] staging: dgap: implement proper error handling in dgap_firmware_load() Daeseok Youn
2014-05-27 10:20 ` Dan Carpenter
2014-05-27 23:36   ` DaeSeok Youn
2014-05-28  7:02     ` Dan Carpenter [this message]
2014-05-28  9:29       ` DaeSeok Youn
2014-05-28 10:11         ` Dan Carpenter
2014-05-29  0:17           ` DaeSeok Youn
2014-05-29  6:40             ` Dan Carpenter
2014-05-29 20:59               ` Greg KH
     [not found]         ` <1203682594.1176349.1401271946432.JavaMail.root@mx2.compro.net>
2014-05-28 14:14           ` Mark Hounschell
2014-05-28 14:26             ` Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140528070233.GP17724@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=daeseok.youn@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=lidza.louina@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markh@compro.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).