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

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

 



On Wed, Feb 27, 2019 at 08:48:57AM +0100, Michał Mirosław wrote:
> Prevent OBEX serial port from ever becoming a console.

Why?

>  /* management of individual TTY ports */
> -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



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

  Powered by Linux