linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daeseok Youn <daeseok.youn@gmail.com>
To: lidza.louina@gmail.com, gregkh@linuxfoundation.org
Cc: markh@compro.net, driverdev-devel@linuxdriverproject.org,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	dan.carpenter@oracle.com
Subject: [PATCH V2] staging: dgap: implement proper error handling in dgap_firmware_load()
Date: Tue, 27 May 2014 16:09:37 +0900	[thread overview]
Message-ID: <20140527070937.GA21621@devel.8.8.4.4> (raw)

When dgap_tty_init() and dgap_tty_register_ports() are failed,
these are needed to free some memory properly.

It can be handled by calling dgap_tty_uninit() and dgap_cleanup_board().
But tty's ports are not registered yet when these function are failed,
so it need to switch with boolean value whether tty's ports are
registered.

Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>
---
V2: remove "brd->nasync = 0" for avoiding to call some destroyer
for unregistering tty's ports.

I'm not sure about add a parameter in dgap_tty_uninit() for checking
whether tty's ports are registered.
please review this. And if I am wrong, let me know.

 drivers/staging/dgap/dgap.c |   34 +++++++++++++++++++++++-----------
 1 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 65d651e..03a3a4b 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -124,7 +124,7 @@ static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
 
 static int dgap_tty_register(struct board_t *brd);
 static int dgap_tty_init(struct board_t *);
-static void dgap_tty_uninit(struct board_t *);
+static void dgap_tty_uninit(struct board_t *, bool);
 static void dgap_carrier(struct channel_t *ch);
 static void dgap_input(struct channel_t *ch);
 
@@ -620,7 +620,7 @@ static void dgap_cleanup_module(void)
 
 	for (i = 0; i < dgap_numboards; ++i) {
 		dgap_remove_ports_sysfiles(dgap_board[i]);
-		dgap_tty_uninit(dgap_board[i]);
+		dgap_tty_uninit(dgap_board[i], true);
 		dgap_cleanup_board(dgap_board[i]);
 	}
 
@@ -954,19 +954,23 @@ static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
 	 * Do tty device initialization.
 	 */
 	ret = dgap_tty_init(brd);
-	if (ret < 0) {
-		dgap_tty_uninit(brd);
-		return ret;
-	}
+	if (ret < 0)
+		goto err_cleanup;
 
 	ret = dgap_tty_register_ports(brd);
 	if (ret)
-		return ret;
+		goto err_cleanup;
 
 	brd->state = BOARD_READY;
 	brd->dpastatus = BD_RUNNING;
 
 	return 0;
+
+err_cleanup:
+	dgap_tty_uninit(brd, false);
+	dgap_cleanup_board(brd);
+	return ret;
+
 }
 
 /*
@@ -1488,19 +1492,20 @@ static int dgap_tty_init(struct board_t *brd)
  * Uninitialize the TTY portion of this driver.  Free all memory and
  * resources.
  */
-static void dgap_tty_uninit(struct board_t *brd)
+static void dgap_tty_uninit(struct board_t *brd, bool ports_registered)
 {
 	struct device *dev;
-	int i;
+	int i = 0;
 
 	if (brd->dgap_major_serial_registered) {
 		dgap_boards_by_major[brd->serial_driver->major] = NULL;
 		brd->dgap_serial_major = 0;
-		for (i = 0; i < brd->nasync; i++) {
+		while (ports_registered && i < brd->nasync) {
 			tty_port_destroy(&brd->serial_ports[i]);
 			dev = brd->channels[i]->ch_tun.un_sysfs;
 			dgap_remove_tty_sysfs(dev);
 			tty_unregister_device(brd->serial_driver, i);
+			i++;
 		}
 		tty_unregister_driver(brd->serial_driver);
 		put_tty_driver(brd->serial_driver);
@@ -1508,14 +1513,21 @@ static void dgap_tty_uninit(struct board_t *brd)
 		brd->dgap_major_serial_registered = FALSE;
 	}
 
+	/*
+	 * Clear index of tty's port for unregistering
+	 * ports of printer driver
+	 */
+	i = 0;
+
 	if (brd->dgap_major_transparent_print_registered) {
 		dgap_boards_by_major[brd->print_driver->major] = NULL;
 		brd->dgap_transparent_print_major = 0;
-		for (i = 0; i < brd->nasync; i++) {
+		while (ports_registered && i < brd->nasync) {
 			tty_port_destroy(&brd->printer_ports[i]);
 			dev = brd->channels[i]->ch_pun.un_sysfs;
 			dgap_remove_tty_sysfs(dev);
 			tty_unregister_device(brd->print_driver, i);
+			i++;
 		}
 		tty_unregister_driver(brd->print_driver);
 		put_tty_driver(brd->print_driver);
-- 
1.7.1


             reply	other threads:[~2014-05-27  7:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-27  7:09 Daeseok Youn [this message]
2014-05-27 10:20 ` [PATCH V2] staging: dgap: implement proper error handling in dgap_firmware_load() Dan Carpenter
2014-05-27 23:36   ` DaeSeok Youn
2014-05-28  7:02     ` Dan Carpenter
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=20140527070937.GA21621@devel.8.8.4.4 \
    --to=daeseok.youn@gmail.com \
    --cc=dan.carpenter@oracle.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).