On Wed, Nov 27, 2002 at 10:42:35PM +0100, Oliver Neukum wrote:
> Hi,
>
> the serial subdrivers may be unloading while we open.
> This patch against 2.5 guards against that.
Thanks, applied. I couldn't apply your bk patch due to missing
changesets though :(
I also applied this followup patch, based on cleaning up the module
calls in this file. If you see any problems in it, please let me know.
thanks,
greg k-h
diff -Nru a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
--- a/drivers/usb/serial/usb-serial.c Fri Nov 29 23:54:13 2002
+++ b/drivers/usb/serial/usb-serial.c Fri Nov 29 23:54:13 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) {
-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T
handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel