Skip to contentSkip to conversation

xhci: dbgtty: fix device unregister

PATCH In review Łukasz Bartosik 4 participants 9 messages Nov 19, 2025 – Nov 26, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xhci: dbgtty: fix device unregister

From: Łukasz Bartosik <[email protected]>

When DbC is disconnected then xhci_dbc_tty_unregister_device() is called. However if there is any user space process blocked on write to DbC terminal device then it will never be signalled and thus stay blocked indifinitely.

This fix adds a tty_vhangup() call in xhci_dbc_tty_unregister_device(). The tty_vhangup() wakes up any blocked writers and causes subsequent write attempts to DbC terminal device to fail.

Fixes dfba2174dc42 ("usb: xhci: Add DbC support in xHCI driver")

---
Changes in v2:
- Replaced tty_hangup() with tty_vhangup()

---
 drivers/usb/host/xhci-dbgtty.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/usb/host/xhci-dbgtty.c +6 -0
index d894081d8d15..ad86f315c26d 100644
@@ -535,6 +535,12 @@ static void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc)
 
 	if (!port->registered)
 		return;
+	/*
+	 * Hang up the TTY. This wakes up any blocked
+	 * writers and causes subsequent writes to fail.
+	 */
+	tty_vhangup(port->port.tty);
+
 	tty_unregister_device(dbc_tty_driver, port->minor);
 	xhci_dbc_tty_exit_port(port);
 	port->registered = false;
Signature · 1 line
2.52.0.rc1.455.g30608eb744-goog
#1 lore raw

Hmm, CCing TTY MAINTAINERS entry would not hurt.

Quoted 6 lines · Łukasz Bartosik

From: Łukasz Bartosik <[email protected]>

When DbC is disconnected then xhci_dbc_tty_unregister_device() is called. However if there is any user space process blocked on write to DbC terminal device then it will never be signalled and thus stay blocked indifinitely.

indefinitely

Quoted 10 lines

This fix adds a tty_vhangup() call in xhci_dbc_tty_unregister_device(). The tty_vhangup() wakes up any blocked writers and causes subsequent write attempts to DbC terminal device to fail.

Fixes dfba2174dc42 ("usb: xhci: Add DbC support in xHCI driver")

---
Changes in v2:
- Replaced tty_hangup() with tty_vhangup()

Why exactly?

drivers/usb/host/xhci-dbgtty.c static void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc) · line 542

Quoted 11 lines
drivers/usb/host/xhci-dbgtty.c +5 -0
@@ -535,6 +535,12 @@ static void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc)
 
  	if (!port->registered)
  		return;
+	/*
+	 * Hang up the TTY. This wakes up any blocked
+	 * writers and causes subsequent writes to fail.
+	 */
+	tty_vhangup(port->port.tty);

This is wrong IMO:
1) what if there is no tty currently open? Ie. tty is NULL.
2) you schedule a tty hangup work and destroy the port right after:

drivers/usb/host/xhci-dbgtty.c static void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc) · line 546

Quoted 3 lines
drivers/usb/host/xhci-dbgtty.c +0 -0
  	tty_unregister_device(dbc_tty_driver, port->minor);
  	xhci_dbc_tty_exit_port(port);
  	port->registered = false;

You should to elaborate how this is supposed to work?

thanks,

Signature · 2 lines
js
suse labs
#2 lore raw
Quoted 16 lines · Jiri Slaby

Hmm, CCing TTY MAINTAINERS entry would not hurt.

Quoted 6 lines · Łukasz Bartosik

From: Łukasz Bartosik <[email protected]>

When DbC is disconnected then xhci_dbc_tty_unregister_device() is called. However if there is any user space process blocked on write to DbC terminal device then it will never be signalled and thus stay blocked indifinitely.

indefinitely

Quoted 4 lines

This fix adds a tty_vhangup() call in xhci_dbc_tty_unregister_device(). The tty_vhangup() wakes up any blocked writers and causes subsequent write attempts to DbC terminal device to fail.

Quoted 8 lines
Quoted 6 lines
Fixes dfba2174dc42 ("usb: xhci: Add DbC support in xHCI driver")

---
Changes in v2:
- Replaced tty_hangup() with tty_vhangup()

Why exactly?

I recommended using tty_vhangup(), well actually tty_port_tty_vhangup() to solve issue '2' you pointed out.
To me it looks like tty_vhangup() is synchronous so it won't schedule hangup work and should be safe to call right before we destroy the port.

Quoted 14 lines

drivers/usb/host/xhci-dbgtty.c static void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc) · line 541

Quoted 11 lines
drivers/usb/host/xhci-dbgtty.c +5 -0
@@ -535,6 +535,12 @@ static void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc)
       if (!port->registered)
           return;
+    /*
+     * Hang up the TTY. This wakes up any blocked
+     * writers and causes subsequent writes to fail.
+     */
+    tty_vhangup(port->port.tty);

This is wrong IMO:
1) what if there is no tty currently open? Ie. tty is NULL.

v1 had the NULL check, I stated that tty_port_tty_vhangup() does the check for us so no need for it here.

https://lore.kernel.org/linux-usb/[email protected]/

looks like v2 removed the check but used tty_vhangup() instead of tty_port_tty_vhangup()

Quoted 5 lines

2) you schedule a tty hangup work and destroy the port right after:

drivers/usb/host/xhci-dbgtty.c static void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc) · line 546

Quoted 3 lines
drivers/usb/host/xhci-dbgtty.c +0 -0
       tty_unregister_device(dbc_tty_driver, port->minor);
       xhci_dbc_tty_exit_port(port);
       port->registered = false;

You should to elaborate how this is supposed to work?

Does tty_port_tty_vhangup() work here? it
1. checks if tty is NULL
2. is synchronous and should be safe to call before tty_unregister_device()

tty internals are still a bit of mystery to me

Thanks
Mathias

#3 lore raw
Quoted 24 lines · Mathias Nyman
Quoted 23 lines · Jiri Slaby

Hmm, CCing TTY MAINTAINERS entry would not hurt.

Quoted 6 lines · Łukasz Bartosik

From: Łukasz Bartosik <[email protected]>

When DbC is disconnected then xhci_dbc_tty_unregister_device() is called. However if there is any user space process blocked on write to DbC terminal device then it will never be signalled and thus stay blocked indifinitely.

indefinitely

Quoted 10 lines

This fix adds a tty_vhangup() call in xhci_dbc_tty_unregister_device(). The tty_vhangup() wakes up any blocked writers and causes subsequent write attempts to DbC terminal device to fail.

Fixes dfba2174dc42 ("usb: xhci: Add DbC support in xHCI driver")

---
Changes in v2:
- Replaced tty_hangup() with tty_vhangup()

Quoted 6 lines
Quoted 1 line

Why exactly?

I recommended using tty_vhangup(), well actually tty_port_tty_vhangup() to solve issue '2' you pointed out.
To me it looks like tty_vhangup() is synchronous so it won't schedule hangup work and should be safe to call right before we destroy the port.

Oops, right, my cscope DB was old and lead me to tty_hangup() instead (that schedules).

Quoted 9 lines
Quoted 5 lines

2) you schedule a tty hangup work and destroy the port right after:

Quoted 3 lines

      tty_unregister_device(dbc_tty_driver, port->minor); xhci_dbc_tty_exit_port(port); port->registered = false;

You should to elaborate how this is supposed to work?

Does tty_port_tty_vhangup() work here? it
1. checks if tty is NULL
2. is synchronous and should be safe to call before tty_unregister_device()

Yes, this works for me.

thanks,

Signature · 2 lines
js
suse labs
#4 lore raw
Quoted 5 lines · Jiri Slaby
Quoted 3 lines · Mathias Nyman
Quoted 2 lines · Jiri Slaby

Hmm, CCing TTY MAINTAINERS entry would not hurt.

Fair point. I will keep it in mind in the future.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines · Łukasz Bartosik
Quoted 6 lines

From: Łukasz Bartosik <[email protected]>

When DbC is disconnected then xhci_dbc_tty_unregister_device() is called. However if there is any user space process blocked on write to DbC terminal device then it will never be signalled and thus stay blocked indifinitely.

indefinitely

Thanks for spotting this.

Quoted 27 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

This fix adds a tty_vhangup() call in xhci_dbc_tty_unregister_device(). The tty_vhangup() wakes up any blocked writers and causes subsequent write attempts to DbC terminal device to fail.

Fixes dfba2174dc42 ("usb: xhci: Add DbC support in xHCI driver")

---
Changes in v2:
- Replaced tty_hangup() with tty_vhangup()

Quoted 8 lines
Quoted 1 line

Why exactly?

I recommended using tty_vhangup(), well actually tty_port_tty_vhangup() to solve
issue '2' you pointed out.
To me it looks like tty_vhangup() is synchronous so it won't schedule hangup work
and should be safe to call right before we destroy the port.

Oops, right, my cscope DB was old and lead me to tty_hangup() instead (that schedules).

Quoted 4 lines
Quoted 4 lines

2) you schedule a tty hangup work and destroy the port right after:

Quoted 3 lines
      tty_unregister_device(dbc_tty_driver, port->minor);
      xhci_dbc_tty_exit_port(port);
      port->registered = false;
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

You should to elaborate how this is supposed to work?

Does tty_port_tty_vhangup() work here? it
1. checks if tty is NULL
2. is synchronous and should be safe to call before tty_unregister_device()

Yes, this works for me.

Greg should I send v3 with typo fix indifinitely -> indefinitely and elaborate on
the tty_hangup() -> tty_vhangup() replacement in changes ?

Thank you,
Łukasz

Quoted 4 lines

thanks,
--
js
suse labs

#5 lore raw
Quoted 55 lines · Łukasz Bartosik
Quoted 5 lines · Jiri Slaby
Quoted 3 lines · Mathias Nyman
Quoted 2 lines · Jiri Slaby

Hmm, CCing TTY MAINTAINERS entry would not hurt.

Fair point. I will keep it in mind in the future.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines · Łukasz Bartosik
Quoted 6 lines

From: Łukasz Bartosik <[email protected]>

When DbC is disconnected then xhci_dbc_tty_unregister_device() is called. However if there is any user space process blocked on write to DbC terminal device then it will never be signalled and thus stay blocked indifinitely.

indefinitely

Thanks for spotting this.

Quoted 33 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

This fix adds a tty_vhangup() call in xhci_dbc_tty_unregister_device(). The tty_vhangup() wakes up any blocked writers and causes subsequent write attempts to DbC terminal device to fail.

Fixes dfba2174dc42 ("usb: xhci: Add DbC support in xHCI driver")

---
Changes in v2:
- Replaced tty_hangup() with tty_vhangup()

Quoted 8 lines
Quoted 1 line

Why exactly?

I recommended using tty_vhangup(), well actually tty_port_tty_vhangup() to solve
issue '2' you pointed out.
To me it looks like tty_vhangup() is synchronous so it won't schedule hangup work
and should be safe to call right before we destroy the port.

Oops, right, my cscope DB was old and lead me to tty_hangup() instead (that schedules).

Quoted 9 lines
Quoted 5 lines

2) you schedule a tty hangup work and destroy the port right after:

Quoted 3 lines
      tty_unregister_device(dbc_tty_driver, port->minor);
      xhci_dbc_tty_exit_port(port);
      port->registered = false;

You should to elaborate how this is supposed to work?

Does tty_port_tty_vhangup() work here? it
1. checks if tty is NULL
2. is synchronous and should be safe to call before tty_unregister_device()

Quoted 6 lines
Quoted 2 lines

Yes, this works for me.

Greg should I send v3 with typo fix indifinitely -> indefinitely and elaborate on
the tty_hangup() -> tty_vhangup() replacement in changes ?

As this is already in my tree, a fixup on top of that would be good.

thanks,

greg k-h

#6 lore raw
Quoted 57 lines · Greg Kroah-Hartman
Quoted 55 lines · Łukasz Bartosik
Quoted 5 lines · Jiri Slaby
Quoted 3 lines · Mathias Nyman
Quoted 2 lines · Jiri Slaby

Hmm, CCing TTY MAINTAINERS entry would not hurt.

Fair point. I will keep it in mind in the future.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines · Łukasz Bartosik
Quoted 6 lines

From: Łukasz Bartosik <[email protected]>

When DbC is disconnected then xhci_dbc_tty_unregister_device() is called. However if there is any user space process blocked on write to DbC terminal device then it will never be signalled and thus stay blocked indifinitely.

indefinitely

Thanks for spotting this.

Quoted 33 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

This fix adds a tty_vhangup() call in xhci_dbc_tty_unregister_device(). The tty_vhangup() wakes up any blocked writers and causes subsequent write attempts to DbC terminal device to fail.

Fixes dfba2174dc42 ("usb: xhci: Add DbC support in xHCI driver")

---
Changes in v2:
- Replaced tty_hangup() with tty_vhangup()

Quoted 8 lines
Quoted 1 line

Why exactly?

I recommended using tty_vhangup(), well actually tty_port_tty_vhangup() to solve
issue '2' you pointed out.
To me it looks like tty_vhangup() is synchronous so it won't schedule hangup work
and should be safe to call right before we destroy the port.

Oops, right, my cscope DB was old and lead me to tty_hangup() instead (that schedules).

Quoted 9 lines
Quoted 5 lines

2) you schedule a tty hangup work and destroy the port right after:

Quoted 3 lines
      tty_unregister_device(dbc_tty_driver, port->minor);
      xhci_dbc_tty_exit_port(port);
      port->registered = false;

You should to elaborate how this is supposed to work?

Does tty_port_tty_vhangup() work here? it
1. checks if tty is NULL
2. is synchronous and should be safe to call before tty_unregister_device()

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Yes, this works for me.

Greg should I send v3 with typo fix indifinitely -> indefinitely and elaborate on
the tty_hangup() -> tty_vhangup() replacement in changes ?

As this is already in my tree, a fixup on top of that would be good.

I sent a fixup. I created it on top of your usb-linus branch. Please let me know if you expect it to be created differently.

Thank you,
Łukasz

Quoted 3 lines

thanks,

greg k-h

#7 lore raw
Quoted 1 line · Łukasz Bartosik

I sent a fixup.

I don't see it on the stable or usb lists, nor in my inbox. Where did you send it to?

thanks,

Signature · 2 lines
js
suse labs