Skip to contentSkip to conversation

usb: gadget: u_serial: make OBEX port not a console

PATCH Superseded Greg Kroah-Hartman 1 participant 1 message Feb 27, 2019 USB

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Greg Kroah-Hartman

author maintainer
#0 lore raw

PATCH 3/5 usb: gadget: u_serial: make OBEX port not a console

Quoted 1 line · Michał Mirosław

Prevent OBEX serial port from ever becoming a console.

Why?

Review

Quoted 3 lines

/* management of individual TTY ports */

(quoted diff) +1 -1
-int gserial_alloc_line(unsigned char *port_line);
+int gserial_alloc_line(unsigned char *port_line, bool maybe_console);

Boolean flags in function calls are a major pain over time.

There is no way to know, when you see this function being called, what "true" or "false" means, so you need to go look up the function header here (as I had to do in this patch), to get a clue as to what is going on.

It is MUCH better to just have a new function:
gserial_alloc_line_no_console()
and leave gserial_alloc_line() alone, or, just have two functions:
gserial_alloc_line_no_console() gserial_alloc_line_console()
which resolve internally to the same function:

static int __gserial_alloc_line(unsigned char *port_line, bool maybe_console)

{
	...
}

int gserial_alloc_line_no_console(unsigned char *port_line)

{
	return __gserial_alloc_line(port_line, false);
}

int gserial_alloc_line_console(unsigned char *port_line)

{
	return __gserial_alloc_line(port_line, true);
}

Trust me, when you have to go fix this code up in 5 years, you will thank me for having to force you to write the code this way :)

thanks,

greg k-h