mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Al Viro <viro@ftp.linux.org.uk>
To: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Jesper Juhl <jesper.juhl@gmail.com>,
	Ben Dooks <ben-linux@fluff.org>,
	"Randy.Dunlap" <rdunlap@xenotime.net>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] release_resource() check for NULL resource
Date: Mon, 3 Oct 2005 14:42:41 +0100	[thread overview]
Message-ID: <20051003134241.GV7992@ftp.linux.org.uk> (raw)
In-Reply-To: <84144f020510030543q10ff4fd2g138de4d06eddc440@mail.gmail.com>

On Mon, Oct 03, 2005 at 03:43:50PM +0300, Pekka Enberg wrote:
> On 10/3/05, Russell King <rmk+lkml@arm.linux.org.uk> wrote:
> > It makes sense for kfree() to ignore NULL pointers, but does it really
> > make sense for *_unregister() to do so too?  Surely you want to only
> > unregister things which you know have previously been registered?
> 
> Usually yes but it makes releasing partial initialization much simpler
> because you can  reuse the normal release counterpart. For example,
> 
> static int driver_init(void)
> {
>      dev->resource1 = request_region(...);
>      if (!dev->resource1)
>              goto failed;
> 
>      dev->resource2 = request_region(...);
>      if (!dev->resource2)
>              goto failed;
> 
>      return 0;
> 
> failed:
>      driver_release(dev);
>      return -1;
> }
> 
> static void driver_release(struct device * dev)
> {
>      release_resource(dev->resource1);
>      release_resource(dev->resource2);
>      kfree(dev);
> }
> 
> Many drivers have the release function copy-pasted to init with lots
> of goto labels exactly because release_region, iounmap, and friends
> aren't NULL safe.

Bullshit.  I have waded through many, *many* initialization sequences
like that.  "Lots of goto labels" is _less_ prone to breakage when
properly done; your variant begs for trouble upon the driver changes.

Note that "lots of goto" is actually a cleaner control structure than
what you propose - the amount of instances of offending statement is
far from being the only metrics.  The only things to verify with it are
	* releasing is done in the opposite order to claiming
	* you always exit to the releasing the last thing you've claimed.
Both are easy to maintain when you change the code _and_ do not break
when you need to introduce something like "keep the number of objects";
I've seen too many cases when release had done the things that can _not_
be made idempotent and still had been used in that manner.  With obvious
breakage resulting from it.

And such breakage is easily introduced when changing the code - it's more
common than forgetting to propagate change between release and failure
exits in initialization.

  parent reply	other threads:[~2005-10-03 13:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-02 17:03 Ben Dooks
2005-10-02 17:39 ` Randy.Dunlap
2005-10-03  9:48   ` Ben Dooks
2005-10-03  9:59     ` Jesper Juhl
2005-10-03 10:04       ` Russell King
2005-10-03 12:43         ` Pekka Enberg
2005-10-03 12:49           ` Russell King
2005-10-03 12:54             ` Pekka J Enberg
2005-10-03 13:00               ` Russell King
2005-10-03 13:12                 ` Pekka J Enberg
2005-10-03 13:42                   ` Russell King
2005-10-03 13:42           ` Al Viro [this message]
2005-10-03 14:57             ` Pekka Enberg
2005-10-04  2:15         ` Randy.Dunlap
     [not found]   ` <5dc44ec70510031959w1f4adfcbh395535ade34a357d@mail.gmail.com>
2005-10-04  3:00     ` Diego de Estrada
2005-10-04  3:28     ` Randy.Dunlap
     [not found] <4TfvY-8ix-27@gated-at.bofh.it>
     [not found] ` <4Tg8u-Bn-15@gated-at.bofh.it>
     [not found]   ` <4Tv7u-5Hd-15@gated-at.bofh.it>
     [not found]     ` <4TvB0-6wD-3@gated-at.bofh.it>
     [not found]       ` <4TvB7-6wD-5@gated-at.bofh.it>
     [not found]         ` <4TxWv-1xD-37@gated-at.bofh.it>
2005-10-04 22:31           ` Bodo Eggert
2005-10-05  9:06             ` Russell King

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=20051003134241.GV7992@ftp.linux.org.uk \
    --to=viro@ftp.linux.org.uk \
    --cc=ben-linux@fluff.org \
    --cc=jesper.juhl@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penberg@cs.helsinki.fi \
    --cc=rdunlap@xenotime.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

Powered by JetHome