tty: hvcs: Don't NULL tty->driver_data until hvcs_cleanup()
PATCH 1/1 tty: hvcs: Don't NULL tty->driver_data until hvcs_cleanup()
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().
--- drivers/tty/hvc/hvcs.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/tty/hvc/hvcs.c +7 -7
@@ -1216,13 +1216,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 ) {
@@ -1237,6 +1230,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); }
Signature · 1 line
2.27.0
Quoted 11 lines · Tyrel Datwyler
The code currently NULLs
tty->driver_datainhvcs_close()with the intent of informing the next call tohvcs_open()that device needs to be reconfigured. However, whenhvcs_cleanup()is called we copy hvcsd fromtty->driver_datawhich was previoulsy NULLed byhvcs_close()and our call totty_port_put(&hvcsd->port)doesn't actually do anything since&hvcsd->portends up translating to NULL by chance. This has the side effect that whenhvcs_remove()is called we have one too many port references preventinghvcs_destuct_port()from ever being called. This also prevents us from reusing the/dev/hvcsXnode in a futurehvcs_probe()and we can eventually run out of/dev/hvcsXdevices.
Quoted 1 line
Fix this by waiting to NULL
tty->driver_datainhvcs_cleanup().
I just realized I neglected a Fixes tag.
-Tyrel
Quoted 39 lines
Signed-off-by Tyrel Datwyler <[email protected]>--- drivers/tty/hvc/hvcs.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)drivers/tty/hvc/hvcs.c +7
-7@@ -1216,13 +1216,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 ) {@@ -1237,6 +1230,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); }
Jiri Slaby
maintainerQuoted 11 lines · Tyrel Datwyler
The code currently NULLs
tty->driver_datainhvcs_close()with the intent of informing the next call tohvcs_open()that device needs to be reconfigured. However, whenhvcs_cleanup()is called we copy hvcsd fromtty->driver_datawhich was previoulsy NULLed byhvcs_close()and our call totty_port_put(&hvcsd->port)doesn't actually do anything since&hvcsd->portends up translating to NULL by chance. This has the side effect that whenhvcs_remove()is called we have one too many port references preventinghvcs_destuct_port()from ever being called. This also prevents us from reusing the/dev/hvcsXnode in a futurehvcs_probe()and we can eventually run out of/dev/hvcsXdevices.
Quoted 1 line
Fix this by waiting to NULL
tty->driver_datainhvcs_cleanup().
Without actually looking into the code, it looks like we need a fix similar to:
commit 24eb2377f977fe06d84fca558f891f95bc28a449
Author: Jiri Slaby <[email protected]> Date: Tue May 26 16:56:32 2020 +0200
tty: hvc_console, fix crashes on parallel open/close
here too?
Quoted 28 lines
Signed-off-by Tyrel Datwyler <[email protected]>--- drivers/tty/hvc/hvcs.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)drivers/tty/hvc/hvcs.c +0
-7@@ -1216,13 +1216,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 ) {@@ -1237,6 +1230,13 @@ static void hvcs_cleanup(struct tty_struct * tty) {struct hvcs_struct *hvcsd = tty->driver_data;
drivers/tty/hvc/hvcs.c static void hvcs_cleanup(struct tty_struct * tty) · line 1242
Quoted 10 lines
drivers/tty/hvc/hvcs.c +7
-0+/* +* 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); }
thanks,
Signature · 1 line
js