Skip to contentSkip to conversation

staging: dgap: implement proper error handling in dgap_firmware_load()

PATCH In review Daeseok Youn 2 participants 3 messages May 26, 2014 – May 27, 2014 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 2/4 staging: dgap: implement proper error handling in dgap_firmware_load()

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 brd->nasync set to zero.

---
 drivers/staging/dgap/dgap.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)
drivers/staging/dgap/dgap.c +16 -5
index 60b7d70..db24f70 100644
@@ -954,19 +954,30 @@ 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:
+	/*
+	 * Clear nasync to zero for avoiding to call
+	 * some destroyer for tty's ports which are not
+	 * registered yet in dgap_tty_uninit().
+	 */
+	brd->nasync = 0;
+
+	dgap_tty_uninit(brd);
+	dgap_cleanup_board(brd);
+	return ret;
+
 }
 
 /*
Signature · 1 line
1.7.1
#1 lore raw
Quoted 38 lines · Daeseok Youn

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 brd->nasync set to zero.

---
 drivers/staging/dgap/dgap.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)
drivers/staging/dgap/dgap.c +5 -5
index 60b7d70..db24f70 100644
@@ -954,19 +954,30 @@ 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:

drivers/staging/dgap/dgap.c static int dgap_firmware_load(struct pci_dev *pdev, int card_type) · line 979

Quoted 10 lines
drivers/staging/dgap/dgap.c +10 -0
+	/*
+	 * Clear nasync to zero for avoiding to call
+	 * some destroyer for tty's ports which are not
+	 * registered yet in dgap_tty_uninit().
+	 */
+	brd->nasync = 0;
+
+	dgap_tty_uninit(brd);
+	dgap_cleanup_board(brd);
+	return ret;

Wow. This is nasty. We shouldn't have to call dgap_tty_uninit() when the init failed. Can't we clean this up instead of adding "brd->nasync = 0;" work arounds?

regards,
dan carpenter

#2 lore raw

Hi, Dan

2014-05-26 19:50 GMT+09:00 Dan Carpenter <[email protected]>:

Quoted 45 lines · Daeseok Youn
Quoted 44 lines

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 brd->nasync set to zero.

---
 drivers/staging/dgap/dgap.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)
drivers/staging/dgap/dgap.c +11 -5
index 60b7d70..db24f70 100644
@@ -954,19 +954,30 @@ 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:
+     /*
+      * Clear nasync to zero for avoiding to call
+      * some destroyer for tty's ports which are not
+      * registered yet in dgap_tty_uninit().
+      */
+     brd->nasync = 0;
Quoted 8 lines

drivers/staging/dgap/dgap.c static int dgap_firmware_load(struct pci_dev *pdev, int card_type) · line 979

Quoted 4 lines
drivers/staging/dgap/dgap.c +4 -0
+
+     dgap_tty_uninit(brd);
+     dgap_cleanup_board(brd);
+     return ret;

Wow. This is nasty. We shouldn't have to call dgap_tty_uninit() when the init failed. Can't we clean this up instead of adding "brd->nasync = 0;" work arounds?

I think dgap_tty_uninit() should be called when the init failed. It need to unregister
serial and printer driver and free them.
And I will try to clean this up without that workaround. Thanks for review.

regards,
Daeseok Youn

Quoted 4 lines

regards,
dan carpenter