From: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
To: Jaroslav Kysela <perex@suse.cz>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>, linux-kernel@vger.kernel.org
Subject: [PATCH] dgrs.c: kmalloc release on failure
Date: Thu, 11 Jan 2001 12:21:39 -0200 [thread overview]
Message-ID: <20010111122139.D5473@conectiva.com.br> (raw)
In-Reply-To: <01011109382601.29363@depoffice.localdomain> <E14Gj32-0002ND-00@the-village.bc.nu> <20010111110921.F32099@conectiva.com.br>
In-Reply-To: <20010111110921.F32099@conectiva.com.br>; from acme@conectiva.com.br on Thu, Jan 11, 2001 at 11:09:21AM -0200
Hi,
Please consider applying.
- Arnaldo
--- linux-2.4.0-ac6/drivers/net/hp100.c Tue Dec 19 11:25:41 2000
+++ linux-2.4.0-ac6.acme/drivers/net/hp100.c Thu Jan 11 11:52:34 2001
@@ -45,6 +45,8 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
+** 1.57b -> 1.57c - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
+** - release resources on failure in init_module
**
** 1.57 -> 1.57b - Jean II
** - fix spinlocks, SMP is now working !
@@ -3024,7 +3026,25 @@
MODULE_PARM(hp100_name, "1-5c" __MODULE_STRING(IFNAMSIZ));
/* List of devices */
-static struct net_device *hp100_devlist[5] = { NULL, NULL, NULL, NULL, NULL };
+static struct net_device *hp100_devlist[5];
+
+static void release_dev(int i)
+{
+ struct net_device *d = hp100_devlist[i];
+ struct hp100_private *p = (struct hp100_private *)d->priv;
+
+ unregister_netdev(d);
+ release_region(d->base_addr, HP100_REGION_SIZE);
+
+ if (p->mode == 1) /* busmaster */
+ kfree(p->page_vaddr);
+ if (p->mem_ptr_virt)
+ iounmap(p->mem_ptr_virt);
+ kfree(d->priv);
+ d->priv = NULL;
+ kfree(d);
+ hp100_devlist[i] = NULL;
+}
/*
* Note: if you have more than five 100vg cards in your pc, feel free to
@@ -3051,6 +3071,8 @@
{
/* Create device and set basics args */
hp100_devlist[i] = kmalloc(sizeof(struct net_device), GFP_KERNEL);
+ if (!hp100_devlist[i])
+ goto fail;
memset(hp100_devlist[i], 0x00, sizeof(struct net_device));
#if LINUX_VERSION_CODE >= 0x020362 /* 2.3.99-pre7 */
memcpy(hp100_devlist[i]->name, hp100_name[i], IFNAMSIZ); /* Copy name */
@@ -3073,6 +3095,13 @@
} /* Loop over all devices */
return cards > 0 ? 0 : -ENODEV;
+ fail:
+ while (cards && --i)
+ if (hp100_devlist[i]) {
+ release_dev(i);
+ --cards;
+ }
+ return -ENOMEM;
}
void cleanup_module( void )
@@ -3082,18 +3111,7 @@
/* TODO: Check if all skb's are released/freed. */
for(i = 0; i < 5; i++)
if(hp100_devlist[i] != (struct net_device *) NULL)
- {
- unregister_netdev( hp100_devlist[i] );
- release_region( hp100_devlist[i]->base_addr, HP100_REGION_SIZE );
- if( ((struct hp100_private *)hp100_devlist[i]->priv)->mode==1 ) /* busmaster */
- kfree( ((struct hp100_private *)hp100_devlist[i]->priv)->page_vaddr );
- if ( ((struct hp100_private *)hp100_devlist[i]->priv) -> mem_ptr_virt )
- iounmap( ((struct hp100_private *)hp100_devlist[i]->priv) -> mem_ptr_virt );
- kfree( hp100_devlist[i]->priv );
- hp100_devlist[i]->priv = NULL;
- kfree(hp100_devlist[i]);
- hp100_devlist[i] = (struct net_device *) NULL;
- }
+ release_dev(i);
}
#endif /* MODULE */
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2001-01-11 16:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-01-11 13:33 IDE DMA problems on 2.4.0 with vt82c686a driver James Brents
2001-01-11 14:38 ` dep
2001-01-11 14:49 ` Alan Cox
2001-01-11 13:09 ` [PATCH] dgrs.c: kmalloc release on failure Arnaldo Carvalho de Melo
2001-01-11 14:21 ` Arnaldo Carvalho de Melo [this message]
2001-01-12 4:19 ` IDE DMA problems on 2.4.0 with vt82c686a driver John O'Donnell
2001-01-12 5:23 ` Andre Hedrick
2001-01-12 8:05 ` Vojtech Pavlik
2001-01-11 14:41 ` Mark Hahn
2001-01-12 8:12 ` Vojtech Pavlik
2001-01-11 15:12 ` Doug McNaught
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=20010111122139.D5473@conectiva.com.br \
--to=acme@conectiva.com.br \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@suse.cz \
/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).