Commit 9140fcd6 authored by Daeseok Youn's avatar Daeseok Youn Committed by Greg Kroah-Hartman

staging: dgap: implement error handling in dgap_tty_register()

- alloc_tty_driver() is deprecated so it is changed to
tty_alloc_driver()
- Pointers which are allocated by alloc_tty_driver() and kzalloc()
can be NULL so it need to check NULL for them.
- If one of those is failed, it need to add proper handler for
avoiding memory leak.
- If both of drivers are registered normally, and
then set TRUE to dgap_major_serial{print}_registered. If one
of drivers is failed to register, leave a default value as
FALSE.
Signed-off-by: default avatarDaeseok Youn <daeseok.youn@gmail.com>
Reviewed-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 02d9b1eb
...@@ -1210,9 +1210,11 @@ static int dgap_ms_sleep(ulong ms) ...@@ -1210,9 +1210,11 @@ static int dgap_ms_sleep(ulong ms)
*/ */
static int dgap_tty_register(struct board_t *brd) static int dgap_tty_register(struct board_t *brd)
{ {
int rc = 0; int rc;
brd->serial_driver = alloc_tty_driver(MAXPORTS); brd->serial_driver = tty_alloc_driver(MAXPORTS, 0);
if (IS_ERR(brd->serial_driver))
return PTR_ERR(brd->serial_driver);
snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_", snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_",
brd->boardnum); brd->boardnum);
...@@ -1231,8 +1233,10 @@ static int dgap_tty_register(struct board_t *brd) ...@@ -1231,8 +1233,10 @@ static int dgap_tty_register(struct board_t *brd)
/* The kernel wants space to store pointers to tty_structs */ /* The kernel wants space to store pointers to tty_structs */
brd->serial_driver->ttys = brd->serial_driver->ttys =
kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL); kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
if (!brd->serial_driver->ttys) if (!brd->serial_driver->ttys) {
return -ENOMEM; rc = -ENOMEM;
goto free_serial_drv;
}
/* /*
* Entry points for driver. Called by the kernel from * Entry points for driver. Called by the kernel from
...@@ -1245,7 +1249,11 @@ static int dgap_tty_register(struct board_t *brd) ...@@ -1245,7 +1249,11 @@ static int dgap_tty_register(struct board_t *brd)
* again, separately so we don't get the LD confused about what major * again, separately so we don't get the LD confused about what major
* we are when we get into the dgap_tty_open() routine. * we are when we get into the dgap_tty_open() routine.
*/ */
brd->print_driver = alloc_tty_driver(MAXPORTS); brd->print_driver = tty_alloc_driver(MAXPORTS, 0);
if (IS_ERR(brd->print_driver)) {
rc = PTR_ERR(brd->print_driver);
goto free_serial_drv;
}
snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_", snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_",
brd->boardnum); brd->boardnum);
...@@ -1264,8 +1272,10 @@ static int dgap_tty_register(struct board_t *brd) ...@@ -1264,8 +1272,10 @@ static int dgap_tty_register(struct board_t *brd)
/* The kernel wants space to store pointers to tty_structs */ /* The kernel wants space to store pointers to tty_structs */
brd->print_driver->ttys = brd->print_driver->ttys =
kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL); kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
if (!brd->print_driver->ttys) if (!brd->print_driver->ttys) {
return -ENOMEM; rc = -ENOMEM;
goto free_print_drv;
}
/* /*
* Entry points for driver. Called by the kernel from * Entry points for driver. Called by the kernel from
...@@ -1276,19 +1286,30 @@ static int dgap_tty_register(struct board_t *brd) ...@@ -1276,19 +1286,30 @@ static int dgap_tty_register(struct board_t *brd)
/* Register tty devices */ /* Register tty devices */
rc = tty_register_driver(brd->serial_driver); rc = tty_register_driver(brd->serial_driver);
if (rc < 0) if (rc < 0)
return rc; goto free_print_drv;
brd->dgap_major_serial_registered = TRUE;
dgap_boards_by_major[brd->serial_driver->major] = brd;
brd->dgap_serial_major = brd->serial_driver->major;
/* Register Transparent Print devices */ /* Register Transparent Print devices */
rc = tty_register_driver(brd->print_driver); rc = tty_register_driver(brd->print_driver);
if (rc < 0) if (rc < 0)
return rc; goto unregister_serial_drv;
brd->dgap_major_serial_registered = TRUE;
dgap_boards_by_major[brd->serial_driver->major] = brd;
brd->dgap_serial_major = brd->serial_driver->major;
brd->dgap_major_transparent_print_registered = TRUE; brd->dgap_major_transparent_print_registered = TRUE;
dgap_boards_by_major[brd->print_driver->major] = brd; dgap_boards_by_major[brd->print_driver->major] = brd;
brd->dgap_transparent_print_major = brd->print_driver->major; brd->dgap_transparent_print_major = brd->print_driver->major;
return 0;
unregister_serial_drv:
tty_unregister_driver(brd->serial_driver);
free_print_drv:
put_tty_driver(brd->print_driver);
free_serial_drv:
put_tty_driver(brd->serial_driver);
return rc; return rc;
} }
......
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