diff options
Diffstat (limited to 'drivers/usb/serial/usb-serial.c')
-rw-r--r-- | drivers/usb/serial/usb-serial.c | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 69230f01056a..97355a15bbea 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -1059,6 +1059,12 @@ int usb_serial_probe(struct usb_interface *interface, | |||
1059 | serial->attached = 1; | 1059 | serial->attached = 1; |
1060 | } | 1060 | } |
1061 | 1061 | ||
1062 | /* Avoid race with tty_open and serial_install by setting the | ||
1063 | * disconnected flag and not clearing it until all ports have been | ||
1064 | * registered. | ||
1065 | */ | ||
1066 | serial->disconnected = 1; | ||
1067 | |||
1062 | if (get_free_serial(serial, num_ports, &minor) == NULL) { | 1068 | if (get_free_serial(serial, num_ports, &minor) == NULL) { |
1063 | dev_err(&interface->dev, "No more free serial devices\n"); | 1069 | dev_err(&interface->dev, "No more free serial devices\n"); |
1064 | goto probe_error; | 1070 | goto probe_error; |
@@ -1070,19 +1076,16 @@ int usb_serial_probe(struct usb_interface *interface, | |||
1070 | port = serial->port[i]; | 1076 | port = serial->port[i]; |
1071 | dev_set_name(&port->dev, "ttyUSB%d", port->number); | 1077 | dev_set_name(&port->dev, "ttyUSB%d", port->number); |
1072 | dbg ("%s - registering %s", __func__, dev_name(&port->dev)); | 1078 | dbg ("%s - registering %s", __func__, dev_name(&port->dev)); |
1073 | port->dev_state = PORT_REGISTERING; | ||
1074 | device_enable_async_suspend(&port->dev); | 1079 | device_enable_async_suspend(&port->dev); |
1075 | 1080 | ||
1076 | retval = device_add(&port->dev); | 1081 | retval = device_add(&port->dev); |
1077 | if (retval) { | 1082 | if (retval) |
1078 | dev_err(&port->dev, "Error registering port device, " | 1083 | dev_err(&port->dev, "Error registering port device, " |
1079 | "continuing\n"); | 1084 | "continuing\n"); |
1080 | port->dev_state = PORT_UNREGISTERED; | ||
1081 | } else { | ||
1082 | port->dev_state = PORT_REGISTERED; | ||
1083 | } | ||
1084 | } | 1085 | } |
1085 | 1086 | ||
1087 | serial->disconnected = 0; | ||
1088 | |||
1086 | usb_serial_console_init(debug, minor); | 1089 | usb_serial_console_init(debug, minor); |
1087 | 1090 | ||
1088 | exit: | 1091 | exit: |
@@ -1124,22 +1127,8 @@ void usb_serial_disconnect(struct usb_interface *interface) | |||
1124 | } | 1127 | } |
1125 | kill_traffic(port); | 1128 | kill_traffic(port); |
1126 | cancel_work_sync(&port->work); | 1129 | cancel_work_sync(&port->work); |
1127 | if (port->dev_state == PORT_REGISTERED) { | 1130 | if (device_is_registered(&port->dev)) |
1128 | |||
1129 | /* Make sure the port is bound so that the | ||
1130 | * driver's port_remove method is called. | ||
1131 | */ | ||
1132 | if (!port->dev.driver) { | ||
1133 | int rc; | ||
1134 | |||
1135 | port->dev.driver = | ||
1136 | &serial->type->driver; | ||
1137 | rc = device_bind_driver(&port->dev); | ||
1138 | } | ||
1139 | port->dev_state = PORT_UNREGISTERING; | ||
1140 | device_del(&port->dev); | 1131 | device_del(&port->dev); |
1141 | port->dev_state = PORT_UNREGISTERED; | ||
1142 | } | ||
1143 | } | 1132 | } |
1144 | } | 1133 | } |
1145 | serial->type->disconnect(serial); | 1134 | serial->type->disconnect(serial); |