mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@gmail.com>
To: <linux-kernel@vger.kernel.org>
Cc: Frank Seidel <fseidel@suse.de>
Subject: [RFC 3/13] Char: nozomi, fix fail paths
Date: Fri, 9 Nov 2007 18:44:51 -0500	[thread overview]
Message-ID: <97452711637819007.slaby@pripojeni.net> (raw)
In-Reply-To: <10551261882075921134.slaby@pripojeni.net>

nozomi, fix fail paths

Free resources on fail path in probe function properly (free_irq,
remove_sysfs_files, kfifo_free, kfree(dc->send_buf) and atomic_dec). Also
use kfifo_free instead of kfree on release function, because it leaked
fifo->buffer.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

---
commit 14e887763c076e45f4f768348361a37c10709902
tree 67854b6ec0a6460d857b37379a2f0772b7f5a9f8
parent 29335b619cc5ee27417d50982f029d440570f67c
author Jiri Slaby <jirislaby@gmail.com> Fri, 09 Nov 2007 23:08:52 +0100
committer Jiri Slaby <jirislaby@gmail.com> Fri, 09 Nov 2007 23:08:52 +0100

 drivers/char/nozomi.c |   47 ++++++++++++++++++++++++++++++-----------------
 1 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c
index 2e2cbc5..e33f21e 100644
--- a/drivers/char/nozomi.c
+++ b/drivers/char/nozomi.c
@@ -1549,7 +1549,7 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
 				      const struct pci_device_id *ent)
 {
 	resource_size_t start;
-	int ret = -EIO;
+	int ret = -ENOMEM;
 	struct nozomi *dc = NULL;
 	struct nozomi_devices *newdev = NULL;
 	struct nozomi_devices *first = NULL;
@@ -1563,13 +1563,12 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
 	dc = kzalloc(sizeof(struct nozomi), GFP_KERNEL);
 	if (unlikely(!dc)) {
 		dev_err(&pdev->dev, "Could not allocate memory\n");
-		return -ENOMEM;
+		goto err_free;
 	}
 	newdev = kzalloc(sizeof(struct nozomi_devices), GFP_KERNEL);
 	if (unlikely(!newdev)) {
 		dev_err(&pdev->dev, "Could not allocate memory\n");
-		kfree(dc);
-		return -ENOMEM;
+		goto err_free;
 	}
 
 	dc->pdev = pdev;
@@ -1581,9 +1580,7 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
 
 	if (pci_enable_device(dc->pdev)) {
 		dev_err(&pdev->dev, "Failed to enable PCI Device\n");
-		kfree(dc);
-		kfree(newdev);
-		return -ENODEV;
+		goto err_free;
 	}
 
 	start = pci_resource_start(dc->pdev, 0);
@@ -1604,17 +1601,18 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
 
 	nozomi_setup_private_data(dc);
 
-	if (pci_request_regions(dc->pdev, NOZOMI_NAME)) {
+	ret = pci_request_regions(dc->pdev, NOZOMI_NAME);
+	if (ret) {
 		dev_err(&pdev->dev, "I/O address 0x%04x already in use\n",
 			(int) /* nozomi_private.io_addr */ 0);
-		ret = -EIO;
-		goto err_disable_regions;
+		goto err_unmap;
 	}
 
 	dc->send_buf = kmalloc(SEND_BUF_MAX, GFP_KERNEL);
 	if (!dc->send_buf) {
 		dev_err(&pdev->dev, "Could not allocate send buffer?\n");
-		goto err_disable_regions;
+		ret = -ENOMEM;
+		goto err_free_sbuf;
 	}
 
 	/* Disable all interrupts */
@@ -1625,7 +1623,7 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
 			NOZOMI_NAME, newdev);
 	if (unlikely(ret)) {
 		dev_err(&pdev->dev, "can't request irq\n");
-		goto err_disable_regions;
+		goto err_free_sbuf;
 	}
 
 	DBG1("base_addr: %p", dc->base_addr);
@@ -1636,13 +1634,17 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
 	if (new_index < 0) {
 		dev_err(&pdev->dev, "already reached maximum card count.\n");
 		ret = -EIO;
-		goto err_disable_regions;
+		goto err_free_irq;
 	}
 
 	make_sysfs_files(dc);
 
 	if (atomic_read(&cards_found) == 1) {
-		ntty_tty_init(dc);
+		ret = ntty_tty_init(dc);
+		if (ret) {
+			dev_err(&pdev->dev, "can't alloc ntty\n");
+			goto err_sysfs;
+		}
 	} else {
 		first = list_first_entry(&my_devices, struct nozomi_devices,
 									list);
@@ -1669,15 +1671,25 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
 
 	return 0;
 
-err_disable_regions:
+err_sysfs:
+	remove_sysfs_files(dc);
+err_free_irq:
+	free_irq(pdev->irq, newdev);
+	for (i = PORT_MDM; i < MAX_PORT; i++)	/* allocated in isr, might be */
+		if (dc->port[i].fifo_ul)	/* filled yet */
+			kfifo_free(dc->port[i].fifo_ul);
+err_free_sbuf:
+	kfree(dc->send_buf);
 	pci_release_regions(pdev);
+err_unmap:
 	iounmap(dc->base_addr);
 	dc->base_addr = NULL;
-
 err_disable_device:
 	pci_disable_device(pdev);
+err_free:
 	kfree(dc);
 	kfree(newdev);
+	atomic_dec(&cards_found);
 	return ret;
 }
 
@@ -1751,7 +1763,8 @@ static void __devexit nozomi_card_exit(struct pci_dev *pdev)
 	free_irq(pdev->irq, deventry);
 
 	for (i = PORT_MDM; i < MAX_PORT; i++)
-		kfree(dc->port[i].fifo_ul);
+		if (dc->port[i].fifo_ul)
+			kfifo_free(dc->port[i].fifo_ul);
 
 	kfree(dc->send_buf);
 

  parent reply	other threads:[~2007-11-09 23:45 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-09 23:43 [RFC 1/13] Char: nozomi, remove unneded stuff Jiri Slaby
2007-11-09 23:44 ` [RFC 2/13] Char: nozomi, expand some functions Jiri Slaby
2007-11-10 15:41   ` Frank Seidel
2007-11-09 23:44 ` Jiri Slaby [this message]
2007-11-10 15:41   ` [RFC 3/13] Char: nozomi, fix fail paths Frank Seidel
2007-11-09 23:45 ` [RFC 4/13] Char: nozomi, tty index cleanup Jiri Slaby
2007-11-10 15:41   ` Frank Seidel
2007-11-10 15:50     ` Jiri Slaby
2007-11-09 23:46 ` [RFC 5/13] Char: nozomi, ioctls cleanup Jiri Slaby
2007-11-10 15:41   ` Frank Seidel
2007-11-09 23:46 ` [RFC 6/13] Char: nozomi, reorder and cleanup probe, remove Jiri Slaby
2007-11-10 15:42   ` Frank Seidel
2007-11-09 23:47 ` [RFC 7/13] Char: nozomi, remove struct irq Jiri Slaby
2007-11-10 15:42   ` Frank Seidel
2007-11-12 15:11   ` Frank Seidel
2007-11-09 23:48 ` [RFC 8/13] Char: nozomi, tty cleanup Jiri Slaby
2007-11-10 15:42   ` Frank Seidel
2007-11-12 18:43   ` Frank Seidel
2007-11-09 23:48 ` [RFC 9/13] Char: nozomi, lock cleanup Jiri Slaby
2007-11-10 15:42   ` Frank Seidel
2007-11-09 23:49 ` [RFC! 10/13] Char: nozomi, fix tty_flip_buffer_push Jiri Slaby
2007-11-10 15:43   ` Frank Seidel
2007-11-09 23:50 ` [RFC 11/13] Char: nozomi, remove unused includes Jiri Slaby
2007-11-10 15:43   ` Frank Seidel
2007-11-09 23:50 ` [RFC 12/13] Char: nozomi, remove void acc char2 char3 more mp mp.c mp.yy m1 nozomi2 proto rej slock1 casts Jiri Slaby
2007-11-10 15:43   ` Frank Seidel
2007-11-09 23:51 ` [RFC 13/13] Char: nozomi, cleanup read and write Jiri Slaby
2007-11-10 15:43   ` Frank Seidel
2007-11-10 16:15   ` Adrian Bunk
2007-11-10 22:04     ` Jiri Slaby
2007-11-11  2:37       ` Frank Seidel
2007-11-11 16:02         ` Frank Seidel
2007-11-12  7:54       ` Adrian Bunk
2007-11-12  9:43         ` Frank Seidel
2007-11-10 15:41 ` [RFC 1/13] Char: nozomi, remove unneded stuff Frank Seidel
2007-11-10 15:55   ` Jiri Slaby

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=97452711637819007.slaby@pripojeni.net \
    --to=jirislaby@gmail.com \
    --cc=fseidel@suse.de \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®