hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/usb/serial/usb-serial.c
....@@ -10,7 +10,7 @@
1010 * This driver was originally based on the ACM driver by Armin Fuerst (which was
1111 * based on a driver by Brad Keryan)
1212 *
13
- * See Documentation/usb/usb-serial.txt for more information on using this
13
+ * See Documentation/usb/usb-serial.rst for more information on using this
1414 * driver
1515 */
1616
....@@ -164,9 +164,9 @@
164164 * @driver: the driver (USB in our case)
165165 * @tty: the tty being created
166166 *
167
- * Create the termios objects for this tty. We use the default
167
+ * Initialise the termios structure for this tty. We use the default
168168 * USB serial settings but permit them to be overridden by
169
- * serial->type->init_termios.
169
+ * serial->type->init_termios on first open.
170170 *
171171 * This is the first place a new tty gets used. Hence this is where we
172172 * acquire references to the usb_serial structure and the driver module,
....@@ -178,6 +178,7 @@
178178 int idx = tty->index;
179179 struct usb_serial *serial;
180180 struct usb_serial_port *port;
181
+ bool init_termios;
181182 int retval = -ENODEV;
182183
183184 port = usb_serial_port_get_by_minor(idx);
....@@ -192,14 +193,16 @@
192193 if (retval)
193194 goto error_get_interface;
194195
196
+ init_termios = (driver->termios[idx] == NULL);
197
+
195198 retval = tty_standard_install(driver, tty);
196199 if (retval)
197200 goto error_init_termios;
198201
199202 mutex_unlock(&serial->disc_mutex);
200203
201
- /* allow the driver to update the settings */
202
- if (serial->type->init_termios)
204
+ /* allow the driver to update the initial settings */
205
+ if (init_termios && serial->type->init_termios)
203206 serial->type->init_termios(tty);
204207
205208 tty->driver_data = port;
....@@ -251,7 +254,7 @@
251254 *
252255 * Shut down a USB serial port. Serialized against activate by the
253256 * tport mutex and kept to matching open/close pairs
254
- * of calls by the initialized flag.
257
+ * of calls by the tty-port initialized flag.
255258 *
256259 * Not called if tty is console.
257260 */
....@@ -285,7 +288,7 @@
285288
286289 /**
287290 * serial_cleanup - free resources post close/hangup
288
- * @port: port to free up
291
+ * @tty: tty to clean up
289292 *
290293 * Do the resource freeing and refcount dropping for the port.
291294 * Avoid freeing the console.
....@@ -391,6 +394,24 @@
391394
392395 if (port->serial->type->unthrottle)
393396 port->serial->type->unthrottle(tty);
397
+}
398
+
399
+static int serial_get_serial(struct tty_struct *tty, struct serial_struct *ss)
400
+{
401
+ struct usb_serial_port *port = tty->driver_data;
402
+
403
+ if (port->serial->type->get_serial)
404
+ return port->serial->type->get_serial(tty, ss);
405
+ return -ENOTTY;
406
+}
407
+
408
+static int serial_set_serial(struct tty_struct *tty, struct serial_struct *ss)
409
+{
410
+ struct usb_serial_port *port = tty->driver_data;
411
+
412
+ if (port->serial->type->set_serial)
413
+ return port->serial->type->set_serial(tty, ss);
414
+ return -ENOTTY;
394415 }
395416
396417 static int serial_ioctl(struct tty_struct *tty,
....@@ -1174,6 +1195,8 @@
11741195 .tiocmget = serial_tiocmget,
11751196 .tiocmset = serial_tiocmset,
11761197 .get_icount = serial_get_icount,
1198
+ .set_serial = serial_set_serial,
1199
+ .get_serial = serial_get_serial,
11771200 .cleanup = serial_cleanup,
11781201 .install = serial_install,
11791202 .proc_show = serial_proc_show,