patch-2.4.6 linux/drivers/usb/serial/omninet.c

Next file: linux/drivers/usb/serial/pl2303.c
Previous file: linux/drivers/usb/serial/mct_u232.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.5/linux/drivers/usb/serial/omninet.c linux/drivers/usb/serial/omninet.c
@@ -10,6 +10,9 @@
  *
  * Please report both successes and troubles to the author at omninet@kroah.com
  * 
+ * (05/30/2001) gkh
+ *	switched from using spinlock to a semaphore, which fixes lots of problems.
+ *
  * (04/08/2001) gb
  *	Identify version on module load.
  *
@@ -60,7 +63,7 @@
 /*
  * Version Information
  */
-#define DRIVER_VERSION "v1.0.0"
+#define DRIVER_VERSION "v1.1"
 #define DRIVER_AUTHOR "Anonymous"
 #define DRIVER_DESC "USB ZyXEL omni.net LCD PLUS Driver"
 
@@ -145,8 +148,7 @@
 	struct usb_serial	*serial;
 	struct usb_serial_port	*wport;
 	struct omninet_data	*od;
-	unsigned long		flags;
-	int			result;
+	int			result = 0;
 
 	if (port_paranoia_check (port, __FUNCTION__))
 		return -ENODEV;
@@ -157,7 +159,7 @@
 	if (!serial)
 		return -ENODEV;
 
-	spin_lock_irqsave (&port->port_lock, flags);
+	down (&port->sem);
 
 	MOD_INC_USE_COUNT;
 	++port->open_count;
@@ -170,7 +172,7 @@
 			err(__FUNCTION__"- kmalloc(%Zd) failed.", sizeof(struct omninet_data));
 			--port->open_count;
 			port->active = 0;
-			spin_unlock_irqrestore (&port->port_lock, flags);
+			up (&port->sem);
 			MOD_DEC_USE_COUNT;
 			return -ENOMEM;
 		}
@@ -189,9 +191,9 @@
 			err(__FUNCTION__ " - failed submitting read urb, error %d", result);
 	}
 
-	spin_unlock_irqrestore (&port->port_lock, flags);
+	up (&port->sem);
 
-	return (0);
+	return result;
 }
 
 static void omninet_close (struct usb_serial_port *port, struct file * filp)
@@ -199,7 +201,6 @@
 	struct usb_serial 	*serial;
 	struct usb_serial_port 	*wport;
 	struct omninet_data 	*od;
-	unsigned long		flags;
 
 	if (port_paranoia_check (port, __FUNCTION__))
 		return;
@@ -210,10 +211,9 @@
 	if (!serial)
 		return;
 
-	spin_lock_irqsave (&port->port_lock, flags);
+	down (&port->sem);
 
 	--port->open_count;
-	MOD_DEC_USE_COUNT;
 
 	if (port->open_count <= 0) {
 		od = (struct omninet_data *)port->private;
@@ -228,7 +228,8 @@
 			kfree(od);
 	}
 
-	spin_unlock_irqrestore (&port->port_lock, flags);
+	up (&port->sem);
+	MOD_DEC_USE_COUNT;
 }
 
 
@@ -296,7 +297,6 @@
 	struct omninet_data 	*od 	= (struct omninet_data   *) port->private;
 	struct omninet_header	*header = (struct omninet_header *) wport->write_urb->transfer_buffer;
 
-	unsigned long		flags;
 	int			result;
 
 //	dbg("omninet_write port %d", port->number);
@@ -310,12 +310,13 @@
 		return (0);
 	}
 
-	spin_lock_irqsave (&port->port_lock, flags);
-	
 	count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count;
 
 	if (from_user) {
-		copy_from_user(wport->write_urb->transfer_buffer + OMNINET_DATAOFFSET, buf, count);
+		if (copy_from_user(wport->write_urb->transfer_buffer + OMNINET_DATAOFFSET, buf, count) != 0) {
+			result = -EFAULT;
+			goto exit;
+		}
 	}
 	else {
 		memcpy (wport->write_urb->transfer_buffer + OMNINET_DATAOFFSET, buf, count);
@@ -333,16 +334,13 @@
 
 	wport->write_urb->dev = serial->dev;
 	result = usb_submit_urb(wport->write_urb);
-	if (result) {
+	if (result)
 		err(__FUNCTION__ " - failed submitting write urb, error %d", result);
-		spin_unlock_irqrestore (&port->port_lock, flags);
-		return 0;
-	}
-
-//	dbg("omninet_write returns %d", count);
+	else
+		result = count;
 
-	spin_unlock_irqrestore (&port->port_lock, flags);
-	return (count);
+exit:	
+	return result;
 }
 
 
@@ -406,8 +404,7 @@
 static int __init omninet_init (void)
 {
 	usb_serial_register (&zyxel_omninet_device);
-	info(DRIVER_VERSION " " DRIVER_AUTHOR);
-	info(DRIVER_DESC);
+	info(DRIVER_VERSION ":" DRIVER_DESC);
 	return 0;
 }
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)