* [PATCH v3 0/3] USB: serial: kobil_sct: fix write path races
@ 2026-11-30 12:05 YuanZhe Liu
2026-11-30 12:05 ` [PATCH v3 1/3] USB: serial: kobil_sct: fix URB submitted while active YuanZhe Liu
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: YuanZhe Liu @ 2026-11-30 12:05 UTC (permalink / raw)
To: Johan Hovold
Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, stable, Bin Yu,
Cheng Wen
This series fixes the write path of the KOBIL USB serial driver.
Patch 1 waits for each interrupt-out chunk to complete instead of reusing
the URB while it is still active, and stops sending on errors.
Patch 2 serializes concurrent writers so that the transmit buffer cannot
be corrupted and the URB cannot be resubmitted by a second caller.
Patch 3 moves the chunked block transmission to a work item so the tty
write path no longer sleeps and the port private data cannot be freed
while the driver is waiting on a transfer.
---
v3:
- Restart the interrupt-in URB only when the whole block was sent.
- Add a patch to serialize concurrent writes.
- Add a patch to move the block transmission to a work item.
v2:
- Check urb->status and stop sending the block when the transfer fails
or the URB is killed.
- Only restart the interrupt-in URB once the block has been sent.
- Bail out if the port was disconnected while waiting.
YuanZhe Liu (3):
USB: serial: kobil_sct: fix URB submitted while active
USB: serial: kobil_sct: serialize concurrent writes
USB: serial: kobil_sct: move block transmission to a work queue
drivers/usb/serial/kobil_sct.c | 199 ++++++++++++++++++++++++++-------
1 file changed, 161 insertions(+), 38 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 1/3] USB: serial: kobil_sct: fix URB submitted while active
2026-11-30 12:05 [PATCH v3 0/3] USB: serial: kobil_sct: fix write path races YuanZhe Liu
@ 2026-11-30 12:05 ` YuanZhe Liu
2026-11-30 12:05 ` [PATCH v3 2/3] USB: serial: kobil_sct: serialize concurrent writes YuanZhe Liu
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: YuanZhe Liu @ 2026-11-30 12:05 UTC (permalink / raw)
To: Johan Hovold
Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, stable, Bin Yu,
Cheng Wen
kobil_write() splits a command block into interrupt-out URBs of at most
the endpoint packet size and submits the same port interrupt-out URB in
a loop, sleeping 24 ms between submissions. The completion handler is
empty, so nothing guarantees that the previous transfer has finished
before the URB is reused.
A device may delay or NAK a packet, in which case the URB stays active
and the next usb_submit_urb() call triggers a "URB submitted while
active" warning, after which the packet is silently dropped. The driver
also rewrites the transfer buffer and length of an URB that may still be
in flight.
Wait for the URB to complete before submitting the next chunk, stop
sending the block when the transfer fails or times out, and do not
restart the interrupt-in URB unless the block has been sent. Bail out
if the port was disconnected while waiting, since the private data may
already have been freed.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
drivers/usb/serial/kobil_sct.c | 44 +++++++++++++++++++++++++++++++---
1 file changed, 41 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index 4a622cf8e6ae..f1c3b53c264f 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -105,6 +105,7 @@ struct kobil_private {
int filled; /* index of the last char in buf */
int cur_pos; /* index of the next char to send in buf */
__u16 device_type;
+ struct completion write_done;
};
static int kobil_ctrl_send(struct usb_serial_port *port, u8 req, u16 val)
@@ -135,6 +136,7 @@ static int kobil_port_probe(struct usb_serial_port *port)
priv->filled = 0;
priv->cur_pos = 0;
priv->device_type = le16_to_cpu(serial->dev->descriptor.idProduct);
+ init_completion(&priv->write_done);
switch (priv->device_type) {
case KOBIL_ADAPTER_B_PRODUCT_ID:
@@ -264,6 +266,10 @@ static void kobil_read_int_callback(struct urb *urb)
static void kobil_write_int_callback(struct urb *urb)
{
+ struct usb_serial_port *port = urb->context;
+ struct kobil_private *priv = usb_get_serial_port_data(port);
+
+ complete(&priv->write_done);
}
@@ -301,6 +307,7 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
}
todo = priv->filled - priv->cur_pos;
+ result = 0;
while (todo > 0) {
/* max 8 byte in one urb (endpoint size) */
@@ -311,9 +318,39 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
port->interrupt_out_urb->transfer_buffer_length = length;
priv->cur_pos = priv->cur_pos + length;
+ reinit_completion(&priv->write_done);
result = usb_submit_urb(port->interrupt_out_urb,
GFP_ATOMIC);
- dev_dbg(&port->dev, "%s - Send write URB returns: %i\n", __func__, result);
+ if (result) {
+ dev_err(&port->dev,
+ "%s - failed to send write URB: %d\n",
+ __func__, result);
+ break;
+ }
+
+ /* Do not reuse the URB before the transfer has completed. */
+ if (!wait_for_completion_timeout(&priv->write_done,
+ msecs_to_jiffies(KOBIL_TIMEOUT))) {
+ usb_kill_urb(port->interrupt_out_urb);
+ result = -ETIMEDOUT;
+ break;
+ }
+
+ /*
+ * The port may have been disconnected while waiting, in
+ * which case the private data may already have been freed.
+ */
+ if (port->serial->disconnected)
+ return count;
+
+ result = port->interrupt_out_urb->status;
+ if (result) {
+ dev_dbg(&port->dev,
+ "%s - write URB status: %d\n",
+ __func__, result);
+ break;
+ }
+
todo = priv->filled - priv->cur_pos;
if (todo > 0)
@@ -324,8 +361,9 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
priv->cur_pos = 0;
/* start reading (except TWIN and KAAN SIM) */
- if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
- priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) {
+ if (!result &&
+ (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
+ priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID)) {
result = usb_submit_urb(port->interrupt_in_urb,
GFP_ATOMIC);
dev_dbg(&port->dev, "%s - Send read URB returns: %i\n", __func__, result);
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 2/3] USB: serial: kobil_sct: serialize concurrent writes
2026-11-30 12:05 [PATCH v3 0/3] USB: serial: kobil_sct: fix write path races YuanZhe Liu
2026-11-30 12:05 ` [PATCH v3 1/3] USB: serial: kobil_sct: fix URB submitted while active YuanZhe Liu
@ 2026-11-30 12:05 ` YuanZhe Liu
2026-11-30 12:05 ` [PATCH v3 3/3] USB: serial: kobil_sct: move block transmission to a work queue YuanZhe Liu
2026-11-30 12:17 ` [PATCH v3 0/3] USB: serial: kobil_sct: fix write path races Johan Hovold
3 siblings, 0 replies; 6+ messages in thread
From: YuanZhe Liu @ 2026-11-30 12:05 UTC (permalink / raw)
To: Johan Hovold
Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, stable, Bin Yu,
Cheng Wen
kobil_write() and kobil_write_room() access the shared transmit buffer
without locking. The tty layer can call the write method concurrently,
for example tty_send_xchar() from an ioctl holds only
tty->atomic_write_lock while echo processing from the receive path
holds only the n_tty output lock.
Two callers can therefore both enter the chunking loop, overwrite the
interrupt-out buffer and resubmit the same URB while it is still active.
Serialize access to the transmit buffer, make a second writer return
zero (and report no room) while a block is being sent, and wake up the
tty layer once it has been sent.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
drivers/usb/serial/kobil_sct.c | 49 +++++++++++++++++++++++++++++-----
1 file changed, 42 insertions(+), 7 deletions(-)
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index f1c3b53c264f..aa4170ba3676 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -106,6 +106,8 @@ struct kobil_private {
int cur_pos; /* index of the next char to send in buf */
__u16 device_type;
struct completion write_done;
+ spinlock_t lock; /* protects the transmit buffer state */
+ bool sending;
};
static int kobil_ctrl_send(struct usb_serial_port *port, u8 req, u16 val)
@@ -137,6 +139,7 @@ static int kobil_port_probe(struct usb_serial_port *port)
priv->cur_pos = 0;
priv->device_type = le16_to_cpu(serial->dev->descriptor.idProduct);
init_completion(&priv->write_done);
+ spin_lock_init(&priv->lock);
switch (priv->device_type) {
case KOBIL_ADAPTER_B_PRODUCT_ID:
@@ -277,7 +280,10 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
const unsigned char *buf, int count)
{
struct kobil_private *priv;
+ unsigned long flags;
int length, todo, result;
+ int offset;
+ bool complete;
if (count == 0) {
dev_dbg(&port->dev, "%s - write request of 0 bytes\n", __func__);
@@ -286,20 +292,36 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
priv = usb_get_serial_port_data(port);
+ spin_lock_irqsave(&priv->lock, flags);
+ if (priv->sending) {
+ spin_unlock_irqrestore(&priv->lock, flags);
+ return 0;
+ }
+
if (count > (KOBIL_BUF_LENGTH - priv->filled)) {
+ spin_unlock_irqrestore(&priv->lock, flags);
dev_dbg(&port->dev, "%s - Error: write request bigger than buffer size\n", __func__);
return -ENOMEM;
}
/* Copy data to buffer */
- memcpy(priv->buf + priv->filled, buf, count);
- usb_serial_debug_data(&port->dev, __func__, count, priv->buf + priv->filled);
- priv->filled = priv->filled + count;
+ offset = priv->filled;
+ memcpy(priv->buf + offset, buf, count);
+ priv->filled = offset + count;
/* only send complete block. TWIN, KAAN SIM and adapter K
use the same protocol. */
- if (((priv->device_type != KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 2) && (priv->filled >= (priv->buf[1] + 3))) ||
- ((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 3) && (priv->filled >= (priv->buf[2] + 4)))) {
+ complete = ((priv->device_type != KOBIL_ADAPTER_B_PRODUCT_ID) &&
+ (priv->filled > 2) && (priv->filled >= (priv->buf[1] + 3))) ||
+ ((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) &&
+ (priv->filled > 3) && (priv->filled >= (priv->buf[2] + 4)));
+ if (complete)
+ priv->sending = true;
+ spin_unlock_irqrestore(&priv->lock, flags);
+
+ usb_serial_debug_data(&port->dev, __func__, count, priv->buf + offset);
+
+ if (complete) {
/* stop reading (except TWIN and KAAN SIM) */
if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) {
@@ -357,8 +379,13 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
msleep(24);
}
+ spin_lock_irqsave(&priv->lock, flags);
priv->filled = 0;
priv->cur_pos = 0;
+ priv->sending = false;
+ spin_unlock_irqrestore(&priv->lock, flags);
+
+ tty_port_tty_wakeup(&port->port);
/* start reading (except TWIN and KAAN SIM) */
if (!result &&
@@ -375,8 +402,16 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
static unsigned int kobil_write_room(struct tty_struct *tty)
{
- /* FIXME */
- return 8;
+ struct usb_serial_port *port = tty->driver_data;
+ struct kobil_private *priv = usb_get_serial_port_data(port);
+ unsigned long flags;
+ unsigned int room;
+
+ spin_lock_irqsave(&priv->lock, flags);
+ room = priv->sending ? 0 : 8;
+ spin_unlock_irqrestore(&priv->lock, flags);
+
+ return room;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 3/3] USB: serial: kobil_sct: move block transmission to a work queue
2026-11-30 12:05 [PATCH v3 0/3] USB: serial: kobil_sct: fix write path races YuanZhe Liu
2026-11-30 12:05 ` [PATCH v3 1/3] USB: serial: kobil_sct: fix URB submitted while active YuanZhe Liu
2026-11-30 12:05 ` [PATCH v3 2/3] USB: serial: kobil_sct: serialize concurrent writes YuanZhe Liu
@ 2026-11-30 12:05 ` YuanZhe Liu
2026-11-30 12:17 ` [PATCH v3 0/3] USB: serial: kobil_sct: fix write path races Johan Hovold
3 siblings, 0 replies; 6+ messages in thread
From: YuanZhe Liu @ 2026-11-30 12:05 UTC (permalink / raw)
To: Johan Hovold
Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, stable, Bin Yu,
Cheng Wen
kobil_write() stops the interrupt-in URB, submits a block in chunks and
waits for every transfer to complete, so the write path sleeps. The
completion it waits on is embedded in the port private data, and the tty
layer may call the write method from atomic context (for example, line
disciplines such as N_GSM call tty->ops->write() under a spinlock).
Move the block transmission to a work item. The write path now only
copies data into the buffer and schedules the work, while the work item
stops the interrupt-in URB, sends the chunks at the existing pace,
handles transfer errors and restarts reading.
Cancel the work in close() and port_remove() so the private data cannot
be freed while the work item is still using it, and restart the
interrupt-in URB only when the whole block was sent.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
drivers/usb/serial/kobil_sct.c | 190 +++++++++++++++++++++------------
1 file changed, 120 insertions(+), 70 deletions(-)
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index aa4170ba3676..0b52ae7fa165 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -26,6 +26,7 @@
#include <linux/tty_flip.h>
#include <linux/module.h>
#include <linux/spinlock.h>
+#include <linux/workqueue.h>
#include <linux/usb.h>
#include <linux/usb/serial.h>
#include <linux/ioctl.h>
@@ -59,6 +60,7 @@ static int kobil_tiocmset(struct tty_struct *tty,
unsigned int set, unsigned int clear);
static void kobil_read_int_callback(struct urb *urb);
static void kobil_write_int_callback(struct urb *urb);
+static void kobil_write_work(struct work_struct *work);
static void kobil_set_termios(struct tty_struct *tty,
struct usb_serial_port *port,
const struct ktermios *old);
@@ -108,6 +110,9 @@ struct kobil_private {
struct completion write_done;
spinlock_t lock; /* protects the transmit buffer state */
bool sending;
+ bool closed;
+ struct work_struct write_work;
+ struct usb_serial_port *port;
};
static int kobil_ctrl_send(struct usb_serial_port *port, u8 req, u16 val)
@@ -140,6 +145,9 @@ static int kobil_port_probe(struct usb_serial_port *port)
priv->device_type = le16_to_cpu(serial->dev->descriptor.idProduct);
init_completion(&priv->write_done);
spin_lock_init(&priv->lock);
+ priv->closed = false;
+ priv->port = port;
+ INIT_WORK(&priv->write_work, kobil_write_work);
switch (priv->device_type) {
case KOBIL_ADAPTER_B_PRODUCT_ID:
@@ -166,6 +174,7 @@ static void kobil_port_remove(struct usb_serial_port *port)
struct kobil_private *priv;
priv = usb_get_serial_port_data(port);
+ cancel_work_sync(&priv->write_work);
kfree(priv);
}
@@ -183,11 +192,19 @@ static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port)
struct device *dev = &port->dev;
struct kobil_private *priv;
unsigned char *transfer_buffer;
+ unsigned long flags;
int transfer_buffer_length = 8;
int result;
priv = usb_get_serial_port_data(port);
+ spin_lock_irqsave(&priv->lock, flags);
+ priv->filled = 0;
+ priv->cur_pos = 0;
+ priv->sending = false;
+ priv->closed = false;
+ spin_unlock_irqrestore(&priv->lock, flags);
+
/* allocate memory for transfer buffer */
transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
if (!transfer_buffer)
@@ -237,9 +254,27 @@ static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port)
static void kobil_close(struct usb_serial_port *port)
{
+ struct kobil_private *priv = usb_get_serial_port_data(port);
+ unsigned long flags;
+
/* FIXME: Add rts/dtr methods */
+ spin_lock_irqsave(&priv->lock, flags);
+ priv->closed = true;
+ spin_unlock_irqrestore(&priv->lock, flags);
+
+ usb_kill_urb(port->interrupt_out_urb);
+ usb_kill_urb(port->interrupt_in_urb);
+
+ /* The work item may have resubmitted a URB before it saw closed. */
+ cancel_work_sync(&priv->write_work);
usb_kill_urb(port->interrupt_out_urb);
usb_kill_urb(port->interrupt_in_urb);
+
+ spin_lock_irqsave(&priv->lock, flags);
+ priv->filled = 0;
+ priv->cur_pos = 0;
+ priv->sending = false;
+ spin_unlock_irqrestore(&priv->lock, flags);
}
@@ -281,7 +316,6 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
{
struct kobil_private *priv;
unsigned long flags;
- int length, todo, result;
int offset;
bool complete;
@@ -315,91 +349,107 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
(priv->filled > 2) && (priv->filled >= (priv->buf[1] + 3))) ||
((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) &&
(priv->filled > 3) && (priv->filled >= (priv->buf[2] + 4)));
- if (complete)
+ if (complete && !priv->closed) {
priv->sending = true;
+ schedule_work(&priv->write_work);
+ }
spin_unlock_irqrestore(&priv->lock, flags);
usb_serial_debug_data(&port->dev, __func__, count, priv->buf + offset);
- if (complete) {
- /* stop reading (except TWIN and KAAN SIM) */
- if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
- priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) {
- usb_kill_urb(port->interrupt_in_urb);
+ return count;
+}
+
+static void kobil_write_work(struct work_struct *work)
+{
+ struct kobil_private *priv = container_of(work, struct kobil_private,
+ write_work);
+ struct usb_serial_port *port = priv->port;
+ unsigned long flags;
+ int length, todo, result;
+ bool closed;
+
+ /* stop reading (except TWIN and KAAN SIM) */
+ if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
+ priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) {
+ usb_kill_urb(port->interrupt_in_urb);
+ }
+
+ spin_lock_irqsave(&priv->lock, flags);
+ todo = priv->filled - priv->cur_pos;
+ spin_unlock_irqrestore(&priv->lock, flags);
+
+ result = 0;
+ while (todo > 0) {
+ if (READ_ONCE(priv->closed)) {
+ result = -ENODEV;
+ break;
}
- todo = priv->filled - priv->cur_pos;
- result = 0;
-
- while (todo > 0) {
- /* max 8 byte in one urb (endpoint size) */
- length = min(todo, port->interrupt_out_size);
- /* copy data to transfer buffer */
- memcpy(port->interrupt_out_buffer,
- priv->buf + priv->cur_pos, length);
- port->interrupt_out_urb->transfer_buffer_length = length;
-
- priv->cur_pos = priv->cur_pos + length;
- reinit_completion(&priv->write_done);
- result = usb_submit_urb(port->interrupt_out_urb,
- GFP_ATOMIC);
- if (result) {
- dev_err(&port->dev,
- "%s - failed to send write URB: %d\n",
- __func__, result);
- break;
- }
-
- /* Do not reuse the URB before the transfer has completed. */
- if (!wait_for_completion_timeout(&priv->write_done,
- msecs_to_jiffies(KOBIL_TIMEOUT))) {
- usb_kill_urb(port->interrupt_out_urb);
- result = -ETIMEDOUT;
- break;
- }
-
- /*
- * The port may have been disconnected while waiting, in
- * which case the private data may already have been freed.
- */
- if (port->serial->disconnected)
- return count;
-
- result = port->interrupt_out_urb->status;
- if (result) {
- dev_dbg(&port->dev,
- "%s - write URB status: %d\n",
- __func__, result);
- break;
- }
-
- todo = priv->filled - priv->cur_pos;
-
- if (todo > 0)
- msleep(24);
+ /* max 8 byte in one urb (endpoint size) */
+ length = min(todo, port->interrupt_out_size);
+ /* copy data to transfer buffer */
+ memcpy(port->interrupt_out_buffer,
+ priv->buf + priv->cur_pos, length);
+ port->interrupt_out_urb->transfer_buffer_length = length;
+
+ priv->cur_pos = priv->cur_pos + length;
+ reinit_completion(&priv->write_done);
+ result = usb_submit_urb(port->interrupt_out_urb, GFP_KERNEL);
+ if (result) {
+ dev_err(&port->dev,
+ "%s - failed to send write URB: %d\n",
+ __func__, result);
+ break;
}
- spin_lock_irqsave(&priv->lock, flags);
- priv->filled = 0;
- priv->cur_pos = 0;
- priv->sending = false;
- spin_unlock_irqrestore(&priv->lock, flags);
+ /* Do not reuse the URB before the transfer has completed. */
+ if (!wait_for_completion_timeout(&priv->write_done,
+ msecs_to_jiffies(KOBIL_TIMEOUT))) {
+ usb_kill_urb(port->interrupt_out_urb);
+ result = -ETIMEDOUT;
+ break;
+ }
- tty_port_tty_wakeup(&port->port);
+ if (port->serial->disconnected) {
+ result = -ENODEV;
+ break;
+ }
- /* start reading (except TWIN and KAAN SIM) */
- if (!result &&
- (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
- priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID)) {
- result = usb_submit_urb(port->interrupt_in_urb,
- GFP_ATOMIC);
- dev_dbg(&port->dev, "%s - Send read URB returns: %i\n", __func__, result);
+ result = port->interrupt_out_urb->status;
+ if (result) {
+ dev_dbg(&port->dev,
+ "%s - write URB status: %d\n",
+ __func__, result);
+ break;
}
+
+ todo = priv->filled - priv->cur_pos;
+
+ if (todo > 0)
+ msleep(24);
}
- return count;
+
+ spin_lock_irqsave(&priv->lock, flags);
+ priv->filled = 0;
+ priv->cur_pos = 0;
+ priv->sending = false;
+ closed = priv->closed;
+ spin_unlock_irqrestore(&priv->lock, flags);
+
+ /* start reading (except TWIN and KAAN SIM) */
+ if (!result && !closed &&
+ (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
+ priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID)) {
+ result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
+ dev_dbg(&port->dev, "%s - Send read URB returns: %i\n", __func__, result);
+ }
+
+ tty_port_tty_wakeup(&port->port);
}
+
static unsigned int kobil_write_room(struct tty_struct *tty)
{
struct usb_serial_port *port = tty->driver_data;
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3 0/3] USB: serial: kobil_sct: fix write path races
2026-11-30 12:05 [PATCH v3 0/3] USB: serial: kobil_sct: fix write path races YuanZhe Liu
` (2 preceding siblings ...)
2026-11-30 12:05 ` [PATCH v3 3/3] USB: serial: kobil_sct: move block transmission to a work queue YuanZhe Liu
@ 2026-11-30 12:17 ` Johan Hovold
2026-11-30 12:29 ` YuanZhe Liu
3 siblings, 1 reply; 6+ messages in thread
From: Johan Hovold @ 2026-11-30 12:17 UTC (permalink / raw)
To: YuanZhe Liu
Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, stable, Bin Yu,
Cheng Wen
On Mon, Nov 30, 2026 at 08:05:45PM +0800, YuanZhe Liu wrote:
> This series fixes the write path of the KOBIL USB serial driver.
>
> Patch 1 waits for each interrupt-out chunk to complete instead of reusing
> the URB while it is still active, and stops sending on errors.
>
> Patch 2 serializes concurrent writers so that the transmit buffer cannot
> be corrupted and the URB cannot be resubmitted by a second caller.
>
> Patch 3 moves the chunked block transmission to a work item so the tty
> write path no longer sleeps and the port private data cannot be freed
> while the driver is waiting on a transfer.
>
> ---
> v3:
> - Restart the interrupt-in URB only when the whole block was sent.
> - Add a patch to serialize concurrent writes.
> - Add a patch to move the block transmission to a work item.
>
> v2:
> - Check urb->status and stop sending the block when the transfer fails
> or the URB is killed.
> - Only restart the interrupt-in URB once the block has been sent.
> - Bail out if the port was disconnected while waiting.
Please stop this. You have been submitting a new revision every hour for
something which appears to have been all LLM generated and not tested at
all.
Make sure to mention when you submit patches how an issue was found and
how it has been tested.
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 0/3] USB: serial: kobil_sct: fix write path races
2026-11-30 12:17 ` [PATCH v3 0/3] USB: serial: kobil_sct: fix write path races Johan Hovold
@ 2026-11-30 12:29 ` YuanZhe Liu
0 siblings, 0 replies; 6+ messages in thread
From: YuanZhe Liu @ 2026-11-30 12:29 UTC (permalink / raw)
To: Johan Hovold
Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, stable, Bin Yu,
Cheng Wen
Hi Johan,
I'll stop. No more revisions; I'll leave v3 as the last one.
You're right about the provenance and testing. The warning was found
with a USB fuzzing setup that drives the port through an emulated
device capable of delaying or failing transfers; kobil_write()
resubmitted the interrupt-out URB while it was still active there. The
series is compile-tested only: checkpatch is clean, it applies with git
am on v7.3.5, and kobil_sct.o builds with
CONFIG_USB_SERIAL_KOBIL_SCT=y. I have no KOBIL hardware, so none of the
behavioral changes have been run on a real device.
You're also right that the analysis and patch text were prepared with an
LLM assistant; I reviewed the result, but clearly did not slow down
enough.
I will not send anything further unless you ask. If you would rather
drop the series, just say so and I'll leave it alone. Future submissions
will state up front how the problem was found and how it was tested.
Thanks,
YuanZhe
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-30 12:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 12:05 [PATCH v3 0/3] USB: serial: kobil_sct: fix write path races YuanZhe Liu
2026-11-30 12:05 ` [PATCH v3 1/3] USB: serial: kobil_sct: fix URB submitted while active YuanZhe Liu
2026-11-30 12:05 ` [PATCH v3 2/3] USB: serial: kobil_sct: serialize concurrent writes YuanZhe Liu
2026-11-30 12:05 ` [PATCH v3 3/3] USB: serial: kobil_sct: move block transmission to a work queue YuanZhe Liu
2026-11-30 12:17 ` [PATCH v3 0/3] USB: serial: kobil_sct: fix write path races Johan Hovold
2026-11-30 12:29 ` YuanZhe Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox