Commit 72d0f6fc authored by Daeseok Youn's avatar Daeseok Youn Committed by Greg Kroah-Hartman

staging: dgap: unwind on error in dgap_tty_register_ports()

- The dgap_tty_register_ports() needs to handle if the
tty_port_register_device() fails.
Signed-off-by: default avatarDaeseok Youn <daeseok.youn@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 551a9d73
...@@ -4143,6 +4143,7 @@ static int dgap_tty_register_ports(struct board_t *brd) ...@@ -4143,6 +4143,7 @@ static int dgap_tty_register_ports(struct board_t *brd)
{ {
struct channel_t *ch; struct channel_t *ch;
int i; int i;
int ret;
brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports), brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
GFP_KERNEL); GFP_KERNEL);
...@@ -4152,8 +4153,8 @@ static int dgap_tty_register_ports(struct board_t *brd) ...@@ -4152,8 +4153,8 @@ static int dgap_tty_register_ports(struct board_t *brd)
brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports), brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
GFP_KERNEL); GFP_KERNEL);
if (!brd->printer_ports) { if (!brd->printer_ports) {
kfree(brd->serial_ports); ret = -ENOMEM;
return -ENOMEM; goto free_serial_ports;
} }
for (i = 0; i < brd->nasync; i++) { for (i = 0; i < brd->nasync; i++) {
...@@ -4170,6 +4171,11 @@ static int dgap_tty_register_ports(struct board_t *brd) ...@@ -4170,6 +4171,11 @@ static int dgap_tty_register_ports(struct board_t *brd)
brd->serial_driver, brd->serial_driver,
brd->firstminor + i, NULL); brd->firstminor + i, NULL);
if (IS_ERR(classp)) {
ret = PTR_ERR(classp);
goto unregister_ttys;
}
dgap_create_tty_sysfs(&ch->ch_tun, classp); dgap_create_tty_sysfs(&ch->ch_tun, classp);
ch->ch_tun.un_sysfs = classp; ch->ch_tun.un_sysfs = classp;
...@@ -4177,12 +4183,46 @@ static int dgap_tty_register_ports(struct board_t *brd) ...@@ -4177,12 +4183,46 @@ static int dgap_tty_register_ports(struct board_t *brd)
brd->print_driver, brd->print_driver,
brd->firstminor + i, NULL); brd->firstminor + i, NULL);
if (IS_ERR(classp)) {
ret = PTR_ERR(classp);
goto unregister_ttys;
}
dgap_create_tty_sysfs(&ch->ch_pun, classp); dgap_create_tty_sysfs(&ch->ch_pun, classp);
ch->ch_pun.un_sysfs = classp; ch->ch_pun.un_sysfs = classp;
} }
dgap_create_ports_sysfiles(brd); dgap_create_ports_sysfiles(brd);
return 0; return 0;
unregister_ttys:
while (i >= 0) {
ch = brd->channels[i];
if (ch->ch_tun.un_sysfs) {
dgap_remove_tty_sysfs(ch->ch_tun.un_sysfs);
tty_unregister_device(brd->serial_driver, i);
}
if (ch->ch_pun.un_sysfs) {
dgap_remove_tty_sysfs(ch->ch_pun.un_sysfs);
tty_unregister_device(brd->print_driver, i);
}
i--;
}
for (i = 0; i < brd->nasync; i++) {
tty_port_destroy(&brd->serial_ports[i]);
tty_port_destroy(&brd->printer_ports[i]);
}
kfree(brd->printer_ports);
brd->printer_ports = NULL;
free_serial_ports:
kfree(brd->serial_ports);
brd->serial_ports = NULL;
return ret;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment