Skip to contentSkip to conversation

hso patch to fix a -EIO from opening a hso serial device

PATCH In review Denis Joseph Barrow 4 participants 5 messages Jan 14, 2009 – Jan 15, 2009 2 messages not in the archive

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

PATCH 1/2 hso patch to fix a -EIO from opening a hso serial device

Hi All,
This is an important patch the linux-2.6.29-rc1 driver with itworks much better than it did.

I'm about 80% sure this patch is correct
but it needs Alan Cox'es blessing as it modifies code he added.

This patch fixes -EIO caused when serial port opened more than once.

---

drivers/net/usb/hso.c +2 -2
Index: linux-2.6/drivers/net/usb/hso.c
===================================================================
@@ -1354,13 +1354,14 @@
 	/* do the actual close */
 	serial->open_count--;
 	kref_put(&serial->parent->ref, hso_serial_ref_free);
+	if (serial->tty == tty)
+		tty_kref_put(tty);
 	if (serial->open_count <= 0) {
 		serial->open_count = 0;
 		spin_lock_irq(&serial->serial_lock);
 		if (serial->tty == tty) {
 			serial->tty->driver_data = NULL;
 			serial->tty = NULL;
-			tty_kref_put(tty);
 		}
 		spin_unlock_irq(&serial->serial_lock);
 		if (!usb_gone)
@@ -1368,7 +1369,6 @@
 		tasklet_kill(&serial->unthrottle_tasklet);
 		cancel_work_sync(&serial->retry_unthrottle_workqueue);
 	}
-
 	if (!usb_gone)
 		usb_autopm_put_interface(serial->parent->interface);
 
Signature · 13 lines
best regards,
D.J. Barrow

Linux Kernel Developer
Option NV, Gaston Geenslaan 14, 3001 Leuven, Belgium
 
T: +32 16 311 621
F: +32 16 207 164
[email protected]
www.option.com

Disclaimer:
http://www.option.com/company/disclaimer.shtml

This patch fixes -EIO caused when serial port opened more than once.

---

drivers/net/usb/hso.c +2 -1
Index: linux-2.6/drivers/net/usb/hso.c
===================================================================
@@ -1354,13 +1354,14 @@
 	/* do the actual close */
 	serial->open_count--;
 	kref_put(&serial->parent->ref, hso_serial_ref_free);
+	if (serial->tty == tty)
+		tty_kref_put(tty);
 	if (serial->open_count <= 0) {
 		serial->open_count = 0;
 		spin_lock_irq(&serial->serial_lock);
 		if (serial->tty == tty) {
 			serial->tty->driver_data = NULL;
 			serial->tty = NULL;
-			tty_kref_put(tty);
 		}
 		spin_unlock_irq(&serial->serial_lock);
 		if (!usb_gone)
@@ -1368,7 +1369,6 @@
 		tasklet_kill(&serial->unthrottle_tasklet);
 		cancel_work_sync(&serial->retry_unthrottle_workqueue);
 	}

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 3 lines · On Wed, 14 Jan 2009 12:22:31 +0100 Denis Joseph Barrow…

Hi All,
This is an important patch the linux-2.6.29-rc1 driver with itworks much better than it did.

How about this.

tty: Fix a kref leak in the HSO driver on re-open

From: Alan Cox <[email protected]>

---

 drivers/net/usb/hso.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/net/usb/hso.c +1 -0
index c4918b8..9df04dd 100644
@@ -1297,6 +1297,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
 	/* setup */
 	spin_lock_irq(&serial->serial_lock);
 	tty->driver_data = serial;
+	tty_kref_put(serial->tty);
 	serial->tty = tty_kref_get(tty);
 	spin_unlock_irq(&serial->serial_lock);
 

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20090114113828.7b9f59ca-qBU/[email protected]

#4 lore raw

Hi Alan,
Your fix works too I suspect better than mine & since you've a better idea of what you are doing with tty layer than I do we'll stick with
your fix.

Do you want me to switch off the low latency stuff in the driver?

I also need to investigate the tty_kref_put & tty_kref_get & when it was added to the kernel so I can fix stuff for our internal driver

Quoted 32 lines · Alan Cox
Quoted 3 lines · On Wed, 14 Jan 2009 12:22:31 +0100 Denis Joseph Barrow…

Hi All,
This is an important patch the linux-2.6.29-rc1 driver with itworks much better than it did.

How about this.

tty: Fix a kref leak in the HSO driver on re-open

From: Alan Cox <[email protected]>

---

 drivers/net/usb/hso.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/net/usb/hso.c +1 -0
index c4918b8..9df04dd 100644
@@ -1297,6 +1297,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
 	/* setup */
 	spin_lock_irq(&serial->serial_lock);
 	tty->driver_data = serial;
+	tty_kref_put(serial->tty);
 	serial->tty = tty_kref_get(tty);
 	spin_unlock_irq(&serial->serial_lock);
 
Signature · 17 lines
best regards,
D.J. Barrow

Linux Kernel Developer
Option NV, Gaston Geenslaan 14, 3001 Leuven, Belgium
 
T: +32 16 311 621
F: +32 16 207 164
[email protected]
www.option.com

Disclaimer:
http://www.option.com/company/disclaimer.shtml
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw
Quoted 3 lines

Your fix works too I suspect better than mine & since you've a better idea of what you are doing with tty layer than I do we'll stick with
your fix.

Ok.

Quoted 2 lines

Do you want me to switch off the low latency stuff in the driver?

Lets leave it for now - it can get sorted properly when everything is stable - no rush.

Quoted 3 lines

I also need to investigate the tty_kref_put & tty_kref_get & when it was added to the kernel so I can fix stuff for our internal driver

About 2.6.27/28 and while it closes some small race conditions on exit its not essential so probably not worth worrying about for older kernels

maintainer
#6 lore raw
In reply to Alan Cox

From: Alan Cox <[email protected]>
Date: Wed, 14 Jan 2009 11:38:28 +0000

Quoted 7 lines
Quoted 3 lines · On Wed, 14 Jan 2009 12:22:31 +0100 Denis Joseph Barrow <[email protected]>…

Hi All,
This is an important patch the linux-2.6.29-rc1 driver with itworks much better than it did.

Quoted 5 lines

How about this.

tty: Fix a kref leak in the HSO driver on re-open

From: Alan Cox <[email protected]>

Alan, if you could take this and the spinlock fix Danis also posted (it's around a tty call: http://patchwork.ozlabs.org/patch/18412/), and get them merged upstream, I'd appreciate it.