...--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -300,6 +300,48 @@ int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
+unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags)
+{
+ unsigned char bits;
+
+ switch (cflag & CSIZE) {
+ case CS5:
+ bits = 5;
+ break;
+ case CS6:
+ bits = 6;
+ break;
+ case CS7:
+ bits = 7;
+ break;
+ case CS8:
+ default:
+ bits = 8;
+ break;
+ }
+
+ if (!account_flags)
+ return bits;
+
+ if (cflag & CSTOPB)
+ bits++;
+ if (cflag & PARENB)
+ bits++;
+
+ return bits + 2;
+}
+EXPORT_SYMBOL_GPL(tty_get_byte_size);
This should really be two functions rather than passing a bool argument.
I think naming them
tty_get_word_size()
and
tty_get_frame_size()
would be much more clear than than "byte size" + flag.
I realise that the serial-driver interface only uses a cflag argument,
but I think we should consider passing a pointer to the termios
structure instead.