ChangeSet 1.924.3.2, 2002/11/30 00:02:08-08:00, greg@kroah.com

[PATCH] USB serial: cleaned up the rest of the __MOD_INC and __MOD_DEC calls to use the new module API


diff -Nru a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
--- a/drivers/usb/serial/usb-serial.c	Sun Dec  1 23:06:29 2002
+++ b/drivers/usb/serial/usb-serial.c	Sun Dec  1 23:06:29 2002
@@ -469,11 +469,10 @@
 	 
 	/* lock this module before we call it,
 	   this may, which means we must bail out, safe because we are called with BKL held */
-	if (serial->type->owner)
-		if (!try_module_get(serial->type->owner)) {
-			retval = -ENODEV;
-			goto bailout;
-		}
+	if (!try_module_get(serial->type->owner)) {
+		retval = -ENODEV;
+		goto bailout;
+	}
 
 	++port->open_count;
 	if (port->open_count == 1) {
@@ -485,8 +484,7 @@
 			retval = usb_serial_generic_open(port, filp);
 		if (retval) {
 			port->open_count = 0;
-			if (serial->type->owner)
-				__MOD_DEC_USE_COUNT(serial->type->owner);
+			module_put(serial->type->owner);
 		}
 	}
 bailout:
@@ -513,8 +511,7 @@
 		port->open_count = 0;
 	}
 
-	if (port->serial->type->owner)
-		__MOD_DEC_USE_COUNT(port->serial->type->owner);
+	module_put(port->serial->type->owner);
 }
 
 static void serial_close(struct tty_struct *tty, struct file * filp)
@@ -904,11 +901,13 @@
 
 	/* if this device type has a probe function, call it */
 	if (type->probe) {
-		if (type->owner)
-			__MOD_INC_USE_COUNT(type->owner);
+		if (!try_module_get(type->owner)) {
+			err ("module get failed, exiting");
+			kfree (serial);
+			return -EIO;
+		}
 		retval = type->probe (serial);
-		if (type->owner)
-			__MOD_DEC_USE_COUNT(type->owner);
+		module_put(type->owner);
 
 		if (retval < 0) {
 			dbg ("sub driver rejected device");
@@ -1001,11 +1000,13 @@
 	if (!num_ports) {
 		/* if this device type has a calc_num_ports function, call it */
 		if (type->calc_num_ports) {
-			if (type->owner)
-				__MOD_INC_USE_COUNT(type->owner);
+			if (!try_module_get(type->owner)) {
+				err ("module get failed, exiting");
+				kfree (serial);
+				return -EIO;
+			}
 			num_ports = type->calc_num_ports (serial);
-			if (type->owner)
-				__MOD_DEC_USE_COUNT(type->owner);
+			module_put(type->owner);
 		}
 		if (!num_ports)
 			num_ports = type->num_ports;
@@ -1115,11 +1116,12 @@
 
 	/* if this device type has an attach function, call it */
 	if (type->attach) {
-		if (type->owner)
-			__MOD_INC_USE_COUNT(type->owner);
+		if (!try_module_get(type->owner)) {
+			err ("module get failed, exiting");
+			goto probe_error;
+		}
 		retval = type->attach (serial);
-		if (type->owner)
-			__MOD_DEC_USE_COUNT(type->owner);
+		module_put(type->owner);
 		if (retval < 0)
 			goto probe_error;
 		if (retval > 0) {
