Skip to content

Commit

Permalink
tty: hvcs: Don't NULL tty->driver_data until hvcs_cleanup()
Browse files Browse the repository at this point in the history
[ Upstream commit 63ffcbdad738e3d1c857027789a2273df3337624 ]

The code currently NULLs tty->driver_data in hvcs_close() with the
intent of informing the next call to hvcs_open() that device needs to be
reconfigured. However, when hvcs_cleanup() is called we copy hvcsd from
tty->driver_data which was previoulsy NULLed by hvcs_close() and our
call to tty_port_put(&hvcsd->port) doesn't actually do anything since
&hvcsd->port ends up translating to NULL by chance. This has the side
effect that when hvcs_remove() is called we have one too many port
references preventing hvcs_destuct_port() from ever being called. This
also prevents us from reusing the /dev/hvcsX node in a future
hvcs_probe() and we can eventually run out of /dev/hvcsX devices.

Fix this by waiting to NULL tty->driver_data in hvcs_cleanup().

Fixes: 27bf7c4 ("TTY: hvcs, add tty install")
Signed-off-by: Tyrel Datwyler <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
tyreld authored and somestupidgirl committed Jan 25, 2025
1 parent d17aa7e commit 347cb91
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions drivers/tty/hvc/hvcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1232,13 +1232,6 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)

tty_wait_until_sent(tty, HVCS_CLOSE_WAIT);

/*
* This line is important because it tells hvcs_open that this
* device needs to be re-configured the next time hvcs_open is
* called.
*/
tty->driver_data = NULL;

free_irq(irq, hvcsd);
return;
} else if (hvcsd->port.count < 0) {
Expand All @@ -1254,6 +1247,13 @@ static void hvcs_cleanup(struct tty_struct * tty)
{
struct hvcs_struct *hvcsd = tty->driver_data;

/*
* This line is important because it tells hvcs_open that this
* device needs to be re-configured the next time hvcs_open is
* called.
*/
tty->driver_data = NULL;

tty_port_put(&hvcsd->port);
}

Expand Down

0 comments on commit 347cb91

Please sign in to comment.