diff mbox series

[V3] usb: mos7840: Fix hangup after suspend

Message ID 20240611172311.2498-1-d.smirnov@inbox.lv (mailing list archive)
State New, archived
Headers show
Series [V3] usb: mos7840: Fix hangup after suspend | expand

Commit Message

Dmitry Smirnov June 11, 2024, 5:23 p.m. UTC
This patch addresses a kernel hang issue with the mos7840 driver when
PC resuming from a suspend with a device connected to the serial port.

This patch introduces two new functions: mos7840_suspend() and mos7840_resume().

Tested with Delock 87414 USB 2.0 to 4x serial adapter.

Signed-off-by: Dmitry Smirnov <d.smirnov@inbox.lv>
---
V3: Addressed review comments from previous submits

 drivers/usb/serial/mos7840.c | 51 ++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)


base-commit: c3f38fa61af77b49866b006939479069cd451173

Comments

Greg KH June 12, 2024, 7:56 a.m. UTC | #1
On Tue, Jun 11, 2024 at 08:23:11PM +0300, Dmitry Smirnov wrote:
> This patch addresses a kernel hang issue with the mos7840 driver when
> PC resuming from a suspend with a device connected to the serial port.
> 
> This patch introduces two new functions: mos7840_suspend() and mos7840_resume().
> 
> Tested with Delock 87414 USB 2.0 to 4x serial adapter.
> 
> Signed-off-by: Dmitry Smirnov <d.smirnov@inbox.lv>
> ---
> V3: Addressed review comments from previous submits
> 
>  drivers/usb/serial/mos7840.c | 51 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 51 insertions(+)
> 
> diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
> index 8b0308d84270..3e5f761f4925 100644
> --- a/drivers/usb/serial/mos7840.c
> +++ b/drivers/usb/serial/mos7840.c
> @@ -1737,6 +1737,55 @@ static void mos7840_port_remove(struct usb_serial_port *port)
>  	kfree(mos7840_port);
>  }
>  
> +static int mos7840_suspend(struct usb_serial *serial, pm_message_t message)
> +{
> +	struct moschip_port *mos7840_port;
> +	struct usb_serial_port *port;
> +	int i;
> +
> +	dev_dbg(&serial->interface->dev, "mos7840_suspend\n");

ftrace is your friend, there is no need for debug lines like this
anymore.

> +
> +	for (i = 0; i < serial->num_ports; ++i) {
> +		port = serial->port[i];
> +		if (!tty_port_initialized(&port->port))
> +			continue;
> +
> +		mos7840_port = usb_get_serial_port_data(port);
> +
> +		usb_kill_urb(mos7840_port->read_urb);
> +		mos7840_port->read_urb_busy = false;
> +	}
> +	return 0;
> +}
> +
> +static int mos7840_resume(struct usb_serial *serial)
> +{
> +	struct moschip_port *mos7840_port;
> +	struct usb_serial_port *port;
> +	int res;
> +	int i;
> +
> +	dev_dbg(&serial->interface->dev, "mos7840_resume\n");

Same here, not needed.

thanks,

greg k-h
Greg KH June 12, 2024, 12:24 p.m. UTC | #2
Please don't top-post or send html email (the html emails are rejected
from the lists...)

On Wed, Jun 12, 2024 at 03:00:38PM +0300, Dmitry Smirnov wrote:
> Do I need to resubmit as V4 after the fix, or just can attach a new version to
> this thread?

You always need to send a new version, otherwise how can we apply it?

thanks,

greg k-h
Dmitry Smirnov June 12, 2024, 1:19 p.m. UTC | #3
> You always need to send a new version, otherwise how can we apply it?
Than I'll prepare the fix and send it as [PATCH V4] in new thread.

---
Dmitry
diff mbox series

Patch

diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 8b0308d84270..3e5f761f4925 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -1737,6 +1737,55 @@  static void mos7840_port_remove(struct usb_serial_port *port)
 	kfree(mos7840_port);
 }
 
+static int mos7840_suspend(struct usb_serial *serial, pm_message_t message)
+{
+	struct moschip_port *mos7840_port;
+	struct usb_serial_port *port;
+	int i;
+
+	dev_dbg(&serial->interface->dev, "mos7840_suspend\n");
+
+	for (i = 0; i < serial->num_ports; ++i) {
+		port = serial->port[i];
+		if (!tty_port_initialized(&port->port))
+			continue;
+
+		mos7840_port = usb_get_serial_port_data(port);
+
+		usb_kill_urb(mos7840_port->read_urb);
+		mos7840_port->read_urb_busy = false;
+	}
+	return 0;
+}
+
+static int mos7840_resume(struct usb_serial *serial)
+{
+	struct moschip_port *mos7840_port;
+	struct usb_serial_port *port;
+	int res;
+	int i;
+
+	dev_dbg(&serial->interface->dev, "mos7840_resume\n");
+
+	for (i = 0; i < serial->num_ports; ++i) {
+		port = serial->port[i];
+		if (!tty_port_initialized(&port->port))
+			continue;
+
+		mos7840_port = usb_get_serial_port_data(port);
+
+		if (port->bulk_in_size) {
+			res = usb_submit_urb(mos7840_port->read_urb, GFP_NOIO);
+			if (res) {
+				usb_kill_urb(mos7840_port->read_urb);
+				mos7840_port->read_urb_busy = false;
+			}
+		}
+	}
+
+	return 0;
+}
+
 static struct usb_serial_driver moschip7840_4port_device = {
 	.driver = {
 		   .owner = THIS_MODULE,
@@ -1764,6 +1813,8 @@  static struct usb_serial_driver moschip7840_4port_device = {
 	.port_probe = mos7840_port_probe,
 	.port_remove = mos7840_port_remove,
 	.read_bulk_callback = mos7840_bulk_in_callback,
+	.suspend = mos7840_suspend,
+	.resume = mos7840_resume,
 };
 
 static struct usb_serial_driver * const serial_drivers[] = {