Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: serial: add macro for console error reporting

Add macro which prints an error message only once if port is used a
console.

Reporting errors in a write path when port is used as a console could
otherwise result in an infinite loop.

Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Johan Hovold and committed by
Greg Kroah-Hartman
e688355b d35e70d5

+15
+15
include/linux/usb/serial.h
··· 389 389 printk(KERN_DEBUG "%s: " format "\n", __FILE__, ##arg); \ 390 390 } while (0) 391 391 392 + /* 393 + * Macro for reporting errors in write path to avoid inifinite loop 394 + * when port is used as a console. 395 + */ 396 + #define dev_err_console(usport, fmt, ...) \ 397 + do { \ 398 + static bool __print_once; \ 399 + struct usb_serial_port *__port = (usport); \ 400 + \ 401 + if (!__port->port.console || !__print_once) { \ 402 + __print_once = true; \ 403 + dev_err(&__port->dev, fmt, ##__VA_ARGS__); \ 404 + } \ 405 + } while (0) 406 + 392 407 #endif /* __LINUX_USB_SERIAL_H */ 393 408