Skip to content
This repository has been archived by the owner on Sep 18, 2022. It is now read-only.

Commit

Permalink
serial: fix NULL pointer dereference
Browse files Browse the repository at this point in the history
If kzalloc() or alloc_tty_driver() fails, we call:
    put_tty_driver(normal = NULL).

Then:
    put_tty_driver -> tty_driver_kref_put -> kref_put(&NULL->kref, ...)

Signed-off-by: André Goddard Rosa <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
andre-rosa authored and gregkh committed Dec 11, 2009
1 parent 2a0785e commit 9e845ab
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions drivers/serial/serial_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2344,7 +2344,7 @@ static const struct tty_operations uart_ops = {
*/
int uart_register_driver(struct uart_driver *drv)
{
struct tty_driver *normal = NULL;
struct tty_driver *normal;
int i, retval;

BUG_ON(drv->state);
Expand All @@ -2354,13 +2354,12 @@ int uart_register_driver(struct uart_driver *drv)
* we have a large number of ports to handle.
*/
drv->state = kzalloc(sizeof(struct uart_state) * drv->nr, GFP_KERNEL);
retval = -ENOMEM;
if (!drv->state)
goto out;

normal = alloc_tty_driver(drv->nr);
normal = alloc_tty_driver(drv->nr);
if (!normal)
goto out;
goto out_kfree;

drv->tty_driver = normal;

Expand Down Expand Up @@ -2393,12 +2392,14 @@ int uart_register_driver(struct uart_driver *drv)
}

retval = tty_register_driver(normal);
out:
if (retval < 0) {
put_tty_driver(normal);
kfree(drv->state);
}
return retval;
if (retval >= 0)
return retval;

put_tty_driver(normal);
out_kfree:
kfree(drv->state);
out:
return -ENOMEM;
}

/**
Expand Down

0 comments on commit 9e845ab

Please sign in to comment.