netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Denis Joseph Barrow <D.Barow@option.com>
To: Linux USB kernel mailing list <linux-usb@vger.kernel.org>,
	Linux netdev Mailing list <netdev@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH] hso_serial_open hso_serial_close fixups
Date: Thu, 09 Oct 2008 13:22:59 +0200	[thread overview]
Message-ID: <48EDE993.10705@option.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2080 bytes --]

Hi all,
After my discussion with Alan Cox this should make hot disconnection of
the hso device more stable.

Disconnection still sometimes crashes the kernel when a modem port is connected
over ppp because the large patch for the hso mutex stuff hasn't yet been accepted.
i.e. unplugging a modem while using a ppp connection is in use is much more stable for our
internally maintained driver.



Moved serial_open_count in hso_serial_open to
prevent crashes owing to the serial structure being made NULL
when hso_serial_close is called even though hso_serial_open
returned -ENODEV, Alan Cox pointed out this happens,
also put in sanity check in hso_serial_close
to check for a valid serial structure which should prevent
the most reproducable crash in the driver when the hso device
is disconnected while in use.
Signed-off-by: Denis Joseph Barrow <D.Barow@option.com>
---
Index: linux-2.6.27-rc9/drivers/net/usb/hso.c
===================================================================
--- linux-2.6.27-rc9.orig/drivers/net/usb/hso.c	2008-10-09 12:40:41.000000000 +0200
+++ linux-2.6.27-rc9/drivers/net/usb/hso.c	2008-10-09 12:46:50.000000000 +0200
@@ -1053,6 +1053,11 @@
 	}
 
 	mutex_lock(&serial->parent->mutex);
+	/* check for port already opened, if not set the termios */
+	/* The serial->open count needs to be here as hso_serial_close
+	 *  will be called even if hso_serial_open returns -ENODEV.
+	 */
+	serial->open_count++;
 	result = usb_autopm_get_interface(serial->parent->interface);
 	if (result < 0)
 		goto err_out;
@@ -1064,8 +1069,6 @@
 	tty->driver_data = serial;
 	serial->tty = tty;
 
-	/* check for port allready opened, if not set the termios */
-	serial->open_count++;
 	if (serial->open_count == 1) {
 		tty->low_latency = 1;
 		serial->flags = 0;
@@ -1098,6 +1101,10 @@
 	u8 usb_gone;
 
 	D1("Closing serial port");
+	if (serial == NULL || serial->magic != HSO_SERIAL_MAGIC) {
+		D1("invalid serial structure bailing out. ");
+		return;
+	}
 
 	mutex_lock(&serial->parent->mutex);
 	usb_gone = serial->parent->usb_gone;

-- 
best regards,
D.J. Barrow

[-- Attachment #2: hso_close_fix.patch --]
[-- Type: text/x-diff, Size: 1653 bytes --]

Moved serial_open_count in hso_serial_open to
prevent crashes owing to the serial structure being made NULL
when hso_serial_close is called even though hso_serial_open
returned -ENODEV, Alan Cox pointed out this happens,
also put in sanity check in hso_serial_close
to check for a valid serial structure which should prevent
the most reproducable crash in the driver when the hso device
is disconnected while in use.
Signed-off-by: Denis Joseph Barrow <D.Barow@option.com>
---
Index: linux-2.6.27-rc9/drivers/net/usb/hso.c
===================================================================
--- linux-2.6.27-rc9.orig/drivers/net/usb/hso.c	2008-10-09 12:40:41.000000000 +0200
+++ linux-2.6.27-rc9/drivers/net/usb/hso.c	2008-10-09 12:46:50.000000000 +0200
@@ -1053,6 +1053,11 @@
 	}
 
 	mutex_lock(&serial->parent->mutex);
+	/* check for port already opened, if not set the termios */
+	/* The serial->open count needs to be here as hso_serial_close
+	 *  will be called even if hso_serial_open returns -ENODEV.
+	 */
+	serial->open_count++;
 	result = usb_autopm_get_interface(serial->parent->interface);
 	if (result < 0)
 		goto err_out;
@@ -1064,8 +1069,6 @@
 	tty->driver_data = serial;
 	serial->tty = tty;
 
-	/* check for port allready opened, if not set the termios */
-	serial->open_count++;
 	if (serial->open_count == 1) {
 		tty->low_latency = 1;
 		serial->flags = 0;
@@ -1098,6 +1101,10 @@
 	u8 usb_gone;
 
 	D1("Closing serial port");
+	if (serial == NULL || serial->magic != HSO_SERIAL_MAGIC) {
+		D1("invalid serial structure bailing out. ");
+		return;
+	}
 
 	mutex_lock(&serial->parent->mutex);
 	usb_gone = serial->parent->usb_gone;

                 reply	other threads:[~2008-10-09 11:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48EDE993.10705@option.com \
    --to=d.barow@option.com \
    --cc=gregkh@suse.de \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).