On Mon, 6 Feb 2012, Johan Hovold wrote: > 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@xxxxxxxxx> > --- > include/linux/usb/serial.h | 15 +++++++++++++++ > 1 files changed, 15 insertions(+), 0 deletions(-) > > diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h > index 4267a9c..7094f93 100644 > --- a/include/linux/usb/serial.h > +++ b/include/linux/usb/serial.h > @@ -389,5 +389,20 @@ do { \ > printk(KERN_DEBUG "%s: " format "\n", __FILE__, ##arg); \ > } while (0) > > +/* > + * Macro for reporting errors in write path to avoid inifinite loop > + * when port is used as a console. > + */ > +#define dev_err_console(usport, fmt, ...) \ > +{ \ > + static bool __print_once; \ > + struct usb_serial_port *port = (usport); \ > + \ > + if (!port->port.console || !__print_once) { \ > + __print_once = true; \ > + dev_err(&port->dev, fmt, ##__VA_ARGS__); \ > + } \ > +} Macro bodies like this are customarily wrapped in "do ... while (0)". Otherwise a call such as dev_err_console(...); parses as two statements, not one, because of the final ';'. Although this doesn't matter the way you have used dev_err_console, it could cause problems in the future if somebody tries to write: if (...) dev_err_console(...); else ... Alan Stern -- 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