Re: [PATCH 3/3] usb console,usb-serial: pass initial console baud on to first tty open

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Alan Cox wrote:
>> It looked like the API for the tty subsystem was gradually changing such
>> that the ldisc structure could ultimately get shared for use with the
>> console, but this work is not complete, so we are somewhere in between.
> 
> The mechanics of this are already there. A tty drive can manage its own
> termios structs, and the termios structs are pointers in the tty structure
> 
>> The question is what is an acceptable solution?
> 
> Take a look at usb_serial.c:serial_install. You can do the console state
> preservation there and cleanly.
> 


Thanks for the pointer Alan.  That solves the termios initialization
piece nicely.

In the usb git tree the serial_install() got removed, but I can see
the init_termios structure that gets setup in usb_serial_init().


The patch will look something like the code below, but we have to sort
out the patch tree with Alan Stern's changes to usb/serial/console.c.

Thanks,
Jason.


Signed-off-by: Jason Wessel <jason.wessel@xxxxxxxxxxxxx>

---
 drivers/usb/serial/console.c |   24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -65,7 +65,7 @@ static int usb_console_setup(struct cons
 	struct usb_serial_port *port;
 	int retval = 0;
 	struct tty_struct *tty = NULL;
-	struct ktermios *termios = NULL, dummy;
+	struct ktermios dummy;
 
 	dbg("%s", __func__);
 
@@ -136,14 +136,7 @@ static int usb_console_setup(struct cons
 				goto reset_open_count;
 			}
 			kref_init(&tty->kref);
-			termios = kzalloc(sizeof(*termios), GFP_KERNEL);
-			if (!termios) {
-				retval = -ENOMEM;
-				err("no more memory");
-				goto free_tty;
-			}
-			memset(&dummy, 0, sizeof(struct ktermios));
-			tty->termios = termios;
+			tty->termios = &usb_serial_tty_driver->init_termios;
 			tty_port_tty_set(&port->port, tty);
 		}
 
@@ -156,16 +149,15 @@ static int usb_console_setup(struct cons
 
 		if (retval) {
 			err("could not open USB console port");
-			goto free_termios;
+			goto clear_port_tty_set;
 		}
 
 		if (serial->type->set_termios) {
-			termios->c_cflag = cflag;
-			tty_termios_encode_baud_rate(termios, baud, baud);
+			tty->termios->c_cflag = cflag;
+			tty_termios_encode_baud_rate(tty->termios, baud, baud);
 			serial->type->set_termios(tty, port, &dummy);
 
 			tty_port_tty_set(&port->port, NULL);
-			kfree(termios);
 			kfree(tty);
 		}
 	}
@@ -180,13 +172,11 @@ static int usb_console_setup(struct cons
 
 out:
 	return retval;
-free_termios:
-	kfree(termios);
+clear_port_tty_set:
 	tty_port_tty_set(&port->port, NULL);
-free_tty:
 	kfree(tty);
 reset_open_count:
-	port->port.count = 0;
+	--port->port.count;
 	goto out;
 }
 
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux