[V9,1/4] USB: serial: f81232: fix interrupt worker not stop
diff mbox series

Message ID 1556587352-19500-1-git-send-email-hpeter+linux_kernel@gmail.com
State New
Headers show
Series
  • [V9,1/4] USB: serial: f81232: fix interrupt worker not stop
Related show

Commit Message

Ji-Ze Hong (Peter Hong) April 30, 2019, 1:22 a.m. UTC
The F81232 will use interrupt worker to handle MSR change.
This patch will fix the issue that interrupt work should stop
in close() and suspend().

Cc: Johan Hovold <johan@kernel.org>
Signed-off-by: Ji-Ze Hong (Peter Hong) <hpeter+linux_kernel@gmail.com>
---
v9:
	1: change the sequence from patch index from 2 to 1.
	2: using tty_port_initialized() to determinate port open state.

v8:
	1: no change

v7:
	1: first introduce to this series patch.

 drivers/usb/serial/f81232.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

Comments

Johan Hovold May 3, 2019, 6:53 a.m. UTC | #1
On Tue, Apr 30, 2019 at 09:22:29AM +0800, Ji-Ze Hong (Peter Hong) wrote:
> The F81232 will use interrupt worker to handle MSR change.
> This patch will fix the issue that interrupt work should stop
> in close() and suspend().
>
> Cc: Johan Hovold <johan@kernel.org>
> Signed-off-by: Ji-Ze Hong (Peter Hong) <hpeter+linux_kernel@gmail.com>

> +static int f81232_resume(struct usb_serial *serial)
> +{
> +	struct usb_serial_port *port = serial->port[0];
> +	int result;
> +
> +	if (tty_port_initialized(&port->port)) {
> +		result = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO);
> +		if (result) {
> +			dev_err(&port->dev, "submit interrupt urb failed: %d",
> +					result);

I added the missing '\n' to the error message.

> +			return result;
> +		}
> +	}
> +
> +	return usb_serial_generic_resume(serial);
> +}

This also fixes the issue with interrupt events not being received
after a suspend cycle, so I added that to the commit message.

Johan

Patch
diff mbox series

diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c
index 0dcdcb4b2cde..d43ec999bc5e 100644
--- a/drivers/usb/serial/f81232.c
+++ b/drivers/usb/serial/f81232.c
@@ -556,9 +556,12 @@  static int f81232_open(struct tty_struct *tty, struct usb_serial_port *port)
 
 static void f81232_close(struct usb_serial_port *port)
 {
+	struct f81232_private *port_priv = usb_get_serial_port_data(port);
+
 	f81232_port_disable(port);
 	usb_serial_generic_close(port);
 	usb_kill_urb(port->interrupt_in_urb);
+	flush_work(&port_priv->interrupt_work);
 }
 
 static void f81232_dtr_rts(struct usb_serial_port *port, int on)
@@ -632,6 +635,40 @@  static int f81232_port_remove(struct usb_serial_port *port)
 	return 0;
 }
 
+static int f81232_suspend(struct usb_serial *serial, pm_message_t message)
+{
+	struct usb_serial_port *port = serial->port[0];
+	struct f81232_private *port_priv = usb_get_serial_port_data(port);
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i)
+		usb_kill_urb(port->read_urbs[i]);
+
+	usb_kill_urb(port->interrupt_in_urb);
+
+	if (port_priv)
+		flush_work(&port_priv->interrupt_work);
+
+	return 0;
+}
+
+static int f81232_resume(struct usb_serial *serial)
+{
+	struct usb_serial_port *port = serial->port[0];
+	int result;
+
+	if (tty_port_initialized(&port->port)) {
+		result = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO);
+		if (result) {
+			dev_err(&port->dev, "submit interrupt urb failed: %d",
+					result);
+			return result;
+		}
+	}
+
+	return usb_serial_generic_resume(serial);
+}
+
 static struct usb_serial_driver f81232_device = {
 	.driver = {
 		.owner =	THIS_MODULE,
@@ -655,6 +692,8 @@  static struct usb_serial_driver f81232_device = {
 	.read_int_callback =	f81232_read_int_callback,
 	.port_probe =		f81232_port_probe,
 	.port_remove =		f81232_port_remove,
+	.suspend =		f81232_suspend,
+	.resume =		f81232_resume,
 };
 
 static struct usb_serial_driver * const serial_drivers[] = {