Skip to content

Commit c10746d

Browse files
Paul Fulghumgregkh
authored andcommitted
[PATCH] USB: console: fix cr/lf issues
Append Carriage-Returns after Line-Feeds, analogous to the serial driver. From: Paul Fulghum <[email protected]> Signed-off-by: Guennadi Liakhovetski <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 01cced2 commit c10746d

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

drivers/usb/serial/console.c

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,38 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun
213213

214214
if (!port->open_count) {
215215
dbg ("%s - port not opened", __FUNCTION__);
216-
goto exit;
216+
return;
217217
}
218218

219-
/* pass on to the driver specific version of this function if it is available */
220-
if (serial->type->write)
221-
retval = serial->type->write(port, buf, count);
222-
else
223-
retval = usb_serial_generic_write(port, buf, count);
224-
225-
exit:
226-
dbg("%s - return value (if we had one): %d", __FUNCTION__, retval);
219+
while (count) {
220+
unsigned int i;
221+
unsigned int lf;
222+
/* search for LF so we can insert CR if necessary */
223+
for (i=0, lf=0 ; i < count ; i++) {
224+
if (*(buf + i) == 10) {
225+
lf = 1;
226+
i++;
227+
break;
228+
}
229+
}
230+
/* pass on to the driver specific version of this function if it is available */
231+
if (serial->type->write)
232+
retval = serial->type->write(port, buf, i);
233+
else
234+
retval = usb_serial_generic_write(port, buf, i);
235+
dbg("%s - return value : %d", __FUNCTION__, retval);
236+
if (lf) {
237+
/* append CR after LF */
238+
unsigned char cr = 13;
239+
if (serial->type->write)
240+
retval = serial->type->write(port, &cr, 1);
241+
else
242+
retval = usb_serial_generic_write(port, &cr, 1);
243+
dbg("%s - return value : %d", __FUNCTION__, retval);
244+
}
245+
buf += i;
246+
count -= i;
247+
}
227248
}
228249

229250
static struct console usbcons = {

0 commit comments

Comments
 (0)