浏览代码

TTY: unify tty_init_dev fail path handling

Change it so that we call the deinit functions at one place at the end
of the function (by gotos). And while at it use some sane label names.

This is a preparation for the deinitialization of tty in the next
patch.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Jiri Slaby 14 年之前
父节点
当前提交
d554350375
共有 1 个文件被更改,包括 12 次插入11 次删除
  1. 12 11
      drivers/tty/tty_io.c

+ 12 - 11
drivers/tty/tty_io.c

@@ -1391,16 +1391,15 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
 		return ERR_PTR(-ENODEV);
 		return ERR_PTR(-ENODEV);
 
 
 	tty = alloc_tty_struct();
 	tty = alloc_tty_struct();
-	if (!tty)
-		goto fail_no_mem;
+	if (!tty) {
+		retval = -ENOMEM;
+		goto err_module_put;
+	}
 	initialize_tty_struct(tty, driver, idx);
 	initialize_tty_struct(tty, driver, idx);
 
 
 	retval = tty_driver_install_tty(driver, tty);
 	retval = tty_driver_install_tty(driver, tty);
-	if (retval < 0) {
-		free_tty_struct(tty);
-		module_put(driver->owner);
-		return ERR_PTR(retval);
-	}
+	if (retval < 0)
+		goto err_free_tty;
 
 
 	/*
 	/*
 	 * Structures all installed ... call the ldisc open routines.
 	 * Structures all installed ... call the ldisc open routines.
@@ -1409,15 +1408,17 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
 	 */
 	 */
 	retval = tty_ldisc_setup(tty, tty->link);
 	retval = tty_ldisc_setup(tty, tty->link);
 	if (retval)
 	if (retval)
-		goto release_mem_out;
+		goto err_release_tty;
 	return tty;
 	return tty;
 
 
-fail_no_mem:
+err_free_tty:
+	free_tty_struct(tty);
+err_module_put:
 	module_put(driver->owner);
 	module_put(driver->owner);
-	return ERR_PTR(-ENOMEM);
+	return ERR_PTR(retval);
 
 
 	/* call the tty release_tty routine to clean out this slot */
 	/* call the tty release_tty routine to clean out this slot */
-release_mem_out:
+err_release_tty:
 	if (printk_ratelimit())
 	if (printk_ratelimit())
 		printk(KERN_INFO "tty_init_dev: ldisc open failed, "
 		printk(KERN_INFO "tty_init_dev: ldisc open failed, "
 				 "clearing slot %d\n", idx);
 				 "clearing slot %d\n", idx);