All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: David Miller <davem@davemloft.net>
Cc: jgarzik@pobox.com, netdev@vger.kernel.org,
	m.kozlowski@tuxland.pl, akpm@osdl.org,
	torvalds@linux-foundation.org
Subject: Re: buggy IFB driver change
Date: Tue, 30 Jan 2007 16:24:40 -0800	[thread overview]
Message-ID: <1170203080.31330.26.camel@localhost> (raw)
In-Reply-To: <20070130.141240.97296236.davem@davemloft.net>

On Tue, 2007-01-30 at 14:12 -0800, David Miller wrote:
> > > Therefore we must decrement "i" twice before the first
> > > free during the cleanup.  One to "undo" the for() loop
> > > increment, and one to "skip" the ifb_init_one() case which
> > > failed.

Perhaps putting the error unwind inside the for loop
is simpler and more intelligible.

diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index ca2b21f..0b24c31 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -264,19 +264,20 @@ static void ifb_free_one(int index)
 
 static int __init ifb_init_module(void)
 {
-	int i, err = 0;
+	int i, err;
 	ifbs = kmalloc(numifbs * sizeof(void *), GFP_KERNEL);
 	if (!ifbs)
 		return -ENOMEM;
-	for (i = 0; i < numifbs && !err; i++)
+	for (i = 0; i < numifbs; i++) {
 		err = ifb_init_one(i);
-	if (err) {
-		i--;
-		while (--i >= 0)
-			ifb_free_one(i);
+		if (err) {
+			while (i > 0)
+				ifb_free_one(--i);
+			return err;
+		}
 	}
 
-	return err;
+	return 0;
 }
 
 static void __exit ifb_cleanup_module(void)



  reply	other threads:[~2007-01-31  1:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-30 21:12 buggy IFB driver change David Miller
2007-01-30 21:52 ` Jeff Garzik
2007-01-30 22:12   ` David Miller
2007-01-31  0:24     ` Joe Perches [this message]
2007-01-30 22:13   ` Linus Torvalds
2007-01-30 22:21     ` David Miller

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=1170203080.31330.26.camel@localhost \
    --to=joe@perches.com \
    --cc=akpm@osdl.org \
    --cc=davem@davemloft.net \
    --cc=jgarzik@pobox.com \
    --cc=m.kozlowski@tuxland.pl \
    --cc=netdev@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.