Skip to content

Commit

Permalink
tty: serial: max3100: Fix error case
Browse files Browse the repository at this point in the history
We don't want to free a random address if the entry is wrong, cover
this and WARN if it ever happens.

Signed-off-by: Alan Cox <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Alan Cox authored and gregkh committed Sep 17, 2012
1 parent d83114e commit 41fda9c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions drivers/tty/serial/max3100.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,14 +827,16 @@ static int __devexit max3100_remove(struct spi_device *spi)

/* find out the index for the chip we are removing */
for (i = 0; i < MAX_MAX3100; i++)
if (max3100s[i] == s)
if (max3100s[i] == s) {
dev_dbg(&spi->dev, "%s: removing port %d\n", __func__, i);
uart_remove_one_port(&max3100_uart_driver, &max3100s[i]->port);
kfree(max3100s[i]);
max3100s[i] = NULL;
break;
}

dev_dbg(&spi->dev, "%s: removing port %d\n", __func__, i);
uart_remove_one_port(&max3100_uart_driver, &max3100s[i]->port);
kfree(max3100s[i]);
max3100s[i] = NULL;

WARN_ON(i == MAX_MAX3100);

/* check if this is the last chip we have */
for (i = 0; i < MAX_MAX3100; i++)
if (max3100s[i]) {
Expand Down

0 comments on commit 41fda9c

Please sign in to comment.