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

Configure Feed

Select the types of activity you want to include in your feed.

termios: uninline conversion helpers

default go into drivers/tty/tty_ioctl.c, unusual - into
arch/*/kernel/termios.c (only alpha and sparc have those).

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Link: https://lore.kernel.org/r/YxDmeUBHo0s/Ew8b@ZenIV
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Al Viro and committed by
Greg Kroah-Hartman
1d5d6682 408e532e

+294 -501
+6 -71
arch/alpha/include/asm/termios.h
··· 12 12 */ 13 13 #define INIT_C_CC "\004\000\000\177\027\025\022\000\003\034\032\000\021\023\026\025\001\000" 14 14 15 - /* 16 - * Translate a "termio" structure into a "termios". Ugh. 17 - */ 18 - 19 - #define user_termio_to_kernel_termios(a_termios, u_termio) \ 20 - ({ \ 21 - struct ktermios *k_termios = (a_termios); \ 22 - struct termio k_termio; \ 23 - int canon, ret; \ 24 - \ 25 - ret = copy_from_user(&k_termio, u_termio, sizeof(k_termio)); \ 26 - if (!ret) { \ 27 - /* Overwrite only the low bits. */ \ 28 - *(unsigned short *)&k_termios->c_iflag = k_termio.c_iflag; \ 29 - *(unsigned short *)&k_termios->c_oflag = k_termio.c_oflag; \ 30 - *(unsigned short *)&k_termios->c_cflag = k_termio.c_cflag; \ 31 - *(unsigned short *)&k_termios->c_lflag = k_termio.c_lflag; \ 32 - canon = k_termio.c_lflag & ICANON; \ 33 - \ 34 - k_termios->c_cc[VINTR] = k_termio.c_cc[_VINTR]; \ 35 - k_termios->c_cc[VQUIT] = k_termio.c_cc[_VQUIT]; \ 36 - k_termios->c_cc[VERASE] = k_termio.c_cc[_VERASE]; \ 37 - k_termios->c_cc[VKILL] = k_termio.c_cc[_VKILL]; \ 38 - k_termios->c_cc[VEOL2] = k_termio.c_cc[_VEOL2]; \ 39 - k_termios->c_cc[VSWTC] = k_termio.c_cc[_VSWTC]; \ 40 - k_termios->c_cc[canon ? VEOF : VMIN] = k_termio.c_cc[_VEOF]; \ 41 - k_termios->c_cc[canon ? VEOL : VTIME] = k_termio.c_cc[_VEOL]; \ 42 - } \ 43 - ret; \ 44 - }) 45 - 46 - /* 47 - * Translate a "termios" structure into a "termio". Ugh. 48 - * 49 - * Note the "fun" _VMIN overloading. 50 - */ 51 - #define kernel_termios_to_user_termio(u_termio, a_termios) \ 52 - ({ \ 53 - struct ktermios *k_termios = (a_termios); \ 54 - struct termio k_termio; \ 55 - int canon; \ 56 - \ 57 - k_termio.c_iflag = k_termios->c_iflag; \ 58 - k_termio.c_oflag = k_termios->c_oflag; \ 59 - k_termio.c_cflag = k_termios->c_cflag; \ 60 - canon = (k_termio.c_lflag = k_termios->c_lflag) & ICANON; \ 61 - \ 62 - k_termio.c_line = k_termios->c_line; \ 63 - k_termio.c_cc[_VINTR] = k_termios->c_cc[VINTR]; \ 64 - k_termio.c_cc[_VQUIT] = k_termios->c_cc[VQUIT]; \ 65 - k_termio.c_cc[_VERASE] = k_termios->c_cc[VERASE]; \ 66 - k_termio.c_cc[_VKILL] = k_termios->c_cc[VKILL]; \ 67 - k_termio.c_cc[_VEOF] = k_termios->c_cc[canon ? VEOF : VMIN]; \ 68 - k_termio.c_cc[_VEOL] = k_termios->c_cc[canon ? VEOL : VTIME]; \ 69 - k_termio.c_cc[_VEOL2] = k_termios->c_cc[VEOL2]; \ 70 - k_termio.c_cc[_VSWTC] = k_termios->c_cc[VSWTC]; \ 71 - \ 72 - copy_to_user(u_termio, &k_termio, sizeof(k_termio)); \ 73 - }) 74 - 75 - #define user_termios_to_kernel_termios(k, u) \ 76 - copy_from_user(k, u, sizeof(struct termios2)) 77 - 78 - #define kernel_termios_to_user_termios(u, k) \ 79 - copy_to_user(u, k, sizeof(struct termios2)) 80 - 81 - #define user_termios_to_kernel_termios_1(k, u) \ 82 - copy_from_user(k, u, sizeof(struct termios)) 83 - 84 - #define kernel_termios_to_user_termios_1(u, k) \ 85 - copy_to_user(u, k, sizeof(struct termios)) 15 + int user_termio_to_kernel_termios(struct ktermios *, struct termio __user *); 16 + int kernel_termios_to_user_termio(struct termio __user *, struct ktermios *); 17 + int user_termios_to_kernel_termios(struct ktermios *, struct termios2 __user *); 18 + int kernel_termios_to_user_termios(struct termios2 __user *, struct ktermios *); 19 + int user_termios_to_kernel_termios_1(struct ktermios *, struct termios __user *); 20 + int kernel_termios_to_user_termios_1(struct termios __user *, struct ktermios *); 86 21 87 22 #endif /* _ALPHA_TERMIOS_H */
+1 -1
arch/alpha/kernel/Makefile
··· 9 9 10 10 obj-y := entry.o traps.o process.o osf_sys.o irq.o \ 11 11 irq_alpha.o signal.o setup.o ptrace.o time.o \ 12 - systbls.o err_common.o io.o bugs.o 12 + systbls.o err_common.o io.o bugs.o termios.o 13 13 14 14 obj-$(CONFIG_VGA_HOSE) += console.o 15 15 obj-$(CONFIG_SMP) += smp.o
+57
arch/alpha/kernel/termios.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/uaccess.h> 3 + #include <linux/termios.h> 4 + 5 + int user_termio_to_kernel_termios(struct ktermios *termios, 6 + struct termio __user *termio) 7 + { 8 + struct termio v; 9 + bool canon; 10 + 11 + if (copy_from_user(&v, termio, sizeof(struct termio))) 12 + return -EFAULT; 13 + 14 + termios->c_iflag = (0xffff0000 & termios->c_iflag) | v.c_iflag; 15 + termios->c_oflag = (0xffff0000 & termios->c_oflag) | v.c_oflag; 16 + termios->c_cflag = (0xffff0000 & termios->c_cflag) | v.c_cflag; 17 + termios->c_lflag = (0xffff0000 & termios->c_lflag) | v.c_lflag; 18 + termios->c_line = (0xffff0000 & termios->c_lflag) | v.c_line; 19 + 20 + canon = v.c_lflag & ICANON; 21 + termios->c_cc[VINTR] = v.c_cc[_VINTR]; 22 + termios->c_cc[VQUIT] = v.c_cc[_VQUIT]; 23 + termios->c_cc[VERASE] = v.c_cc[_VERASE]; 24 + termios->c_cc[VKILL] = v.c_cc[_VKILL]; 25 + termios->c_cc[VEOL2] = v.c_cc[_VEOL2]; 26 + termios->c_cc[VSWTC] = v.c_cc[_VSWTC]; 27 + termios->c_cc[canon ? VEOF : VMIN] = v.c_cc[_VEOF]; 28 + termios->c_cc[canon ? VEOL : VTIME] = v.c_cc[_VEOL]; 29 + 30 + return 0; 31 + } 32 + 33 + int kernel_termios_to_user_termio(struct termio __user *termio, 34 + struct ktermios *termios) 35 + { 36 + struct termio v; 37 + bool canon; 38 + 39 + memset(&v, 0, sizeof(struct termio)); 40 + v.c_iflag = termios->c_iflag; 41 + v.c_oflag = termios->c_oflag; 42 + v.c_cflag = termios->c_cflag; 43 + v.c_lflag = termios->c_lflag; 44 + v.c_line = termios->c_line; 45 + 46 + canon = v.c_lflag & ICANON; 47 + v.c_cc[_VINTR] = termios->c_cc[VINTR]; 48 + v.c_cc[_VQUIT] = termios->c_cc[VQUIT]; 49 + v.c_cc[_VERASE] = termios->c_cc[VERASE]; 50 + v.c_cc[_VKILL] = termios->c_cc[VKILL]; 51 + v.c_cc[_VEOF] = termios->c_cc[canon ? VEOF : VMIN]; 52 + v.c_cc[_VEOL] = termios->c_cc[canon ? VEOL : VTIME]; 53 + v.c_cc[_VEOL2] = termios->c_cc[VEOL2]; 54 + v.c_cc[_VSWTC] = termios->c_cc[VSWTC]; 55 + 56 + return copy_to_user(termio, &v, sizeof(struct termio)); 57 + }
+6 -35
arch/ia64/include/asm/termios.h
··· 19 19 */ 20 20 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0" 21 21 22 - /* 23 - * Translate a "termio" structure into a "termios". Ugh. 24 - */ 25 - #define SET_LOW_TERMIOS_BITS(termios, termio, x) { \ 26 - unsigned short __tmp; \ 27 - get_user(__tmp,&(termio)->x); \ 28 - *(unsigned short *) &(termios)->x = __tmp; \ 29 - } 30 - 31 - #define user_termio_to_kernel_termios(termios, termio) \ 32 - ({ \ 33 - SET_LOW_TERMIOS_BITS(termios, termio, c_iflag); \ 34 - SET_LOW_TERMIOS_BITS(termios, termio, c_oflag); \ 35 - SET_LOW_TERMIOS_BITS(termios, termio, c_cflag); \ 36 - SET_LOW_TERMIOS_BITS(termios, termio, c_lflag); \ 37 - copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \ 38 - }) 39 - 40 - /* 41 - * Translate a "termios" structure into a "termio". Ugh. 42 - */ 43 - #define kernel_termios_to_user_termio(termio, termios) \ 44 - ({ \ 45 - put_user((termios)->c_iflag, &(termio)->c_iflag); \ 46 - put_user((termios)->c_oflag, &(termio)->c_oflag); \ 47 - put_user((termios)->c_cflag, &(termio)->c_cflag); \ 48 - put_user((termios)->c_lflag, &(termio)->c_lflag); \ 49 - put_user((termios)->c_line, &(termio)->c_line); \ 50 - copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \ 51 - }) 52 - 53 - #define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios2)) 54 - #define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios2)) 55 - #define user_termios_to_kernel_termios_1(k, u) copy_from_user(k, u, sizeof(struct termios)) 56 - #define kernel_termios_to_user_termios_1(u, k) copy_to_user(u, k, sizeof(struct termios)) 22 + int user_termio_to_kernel_termios(struct ktermios *, struct termio __user *); 23 + int kernel_termios_to_user_termio(struct termio __user *, struct ktermios *); 24 + int user_termios_to_kernel_termios(struct ktermios *, struct termios2 __user *); 25 + int kernel_termios_to_user_termios(struct termios2 __user *, struct ktermios *); 26 + int user_termios_to_kernel_termios_1(struct ktermios *, struct termios __user *); 27 + int kernel_termios_to_user_termios_1(struct termios __user *, struct ktermios *); 57 28 58 29 #endif /* _ASM_IA64_TERMIOS_H */
+6 -78
arch/mips/include/asm/termios.h
··· 23 23 24 24 #include <linux/string.h> 25 25 26 - /* 27 - * Translate a "termio" structure into a "termios". Ugh. 28 - */ 29 - static inline int user_termio_to_kernel_termios(struct ktermios *termios, 30 - struct termio __user *termio) 31 - { 32 - unsigned short iflag, oflag, cflag, lflag; 33 - unsigned int err; 34 - 35 - if (!access_ok(termio, sizeof(struct termio))) 36 - return -EFAULT; 37 - 38 - err = __get_user(iflag, &termio->c_iflag); 39 - termios->c_iflag = (termios->c_iflag & 0xffff0000) | iflag; 40 - err |=__get_user(oflag, &termio->c_oflag); 41 - termios->c_oflag = (termios->c_oflag & 0xffff0000) | oflag; 42 - err |=__get_user(cflag, &termio->c_cflag); 43 - termios->c_cflag = (termios->c_cflag & 0xffff0000) | cflag; 44 - err |=__get_user(lflag, &termio->c_lflag); 45 - termios->c_lflag = (termios->c_lflag & 0xffff0000) | lflag; 46 - err |=__get_user(termios->c_line, &termio->c_line); 47 - if (err) 48 - return -EFAULT; 49 - 50 - if (__copy_from_user(termios->c_cc, termio->c_cc, NCC)) 51 - return -EFAULT; 52 - 53 - return 0; 54 - } 55 - 56 - /* 57 - * Translate a "termios" structure into a "termio". Ugh. 58 - */ 59 - static inline int kernel_termios_to_user_termio(struct termio __user *termio, 60 - struct ktermios *termios) 61 - { 62 - int err; 63 - 64 - if (!access_ok(termio, sizeof(struct termio))) 65 - return -EFAULT; 66 - 67 - err = __put_user(termios->c_iflag, &termio->c_iflag); 68 - err |= __put_user(termios->c_oflag, &termio->c_oflag); 69 - err |= __put_user(termios->c_cflag, &termio->c_cflag); 70 - err |= __put_user(termios->c_lflag, &termio->c_lflag); 71 - err |= __put_user(termios->c_line, &termio->c_line); 72 - if (err) 73 - return -EFAULT; 74 - 75 - if (__copy_to_user(termio->c_cc, termios->c_cc, NCC)) 76 - return -EFAULT; 77 - 78 - return 0; 79 - } 80 - 81 - static inline int user_termios_to_kernel_termios(struct ktermios __user *k, 82 - struct termios2 *u) 83 - { 84 - return copy_from_user(k, u, sizeof(struct termios2)) ? -EFAULT : 0; 85 - } 86 - 87 - static inline int kernel_termios_to_user_termios(struct termios2 __user *u, 88 - struct ktermios *k) 89 - { 90 - return copy_to_user(u, k, sizeof(struct termios2)) ? -EFAULT : 0; 91 - } 92 - 93 - static inline int user_termios_to_kernel_termios_1(struct ktermios *k, 94 - struct termios __user *u) 95 - { 96 - return copy_from_user(k, u, sizeof(struct termios)) ? -EFAULT : 0; 97 - } 98 - 99 - static inline int kernel_termios_to_user_termios_1(struct termios __user *u, 100 - struct ktermios *k) 101 - { 102 - return copy_to_user(u, k, sizeof(struct termios)) ? -EFAULT : 0; 103 - } 26 + int user_termio_to_kernel_termios(struct ktermios *, struct termio __user *); 27 + int kernel_termios_to_user_termio(struct termio __user *, struct ktermios *); 28 + int user_termios_to_kernel_termios(struct ktermios *, struct termios2 __user *); 29 + int kernel_termios_to_user_termios(struct termios2 __user *, struct ktermios *); 30 + int user_termios_to_kernel_termios_1(struct ktermios *, struct termios __user *); 31 + int kernel_termios_to_user_termios_1(struct termios __user *, struct ktermios *); 104 32 105 33 #endif /* _ASM_TERMIOS_H */
+6 -35
arch/parisc/include/asm/termios.h
··· 13 13 */ 14 14 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0" 15 15 16 - /* 17 - * Translate a "termio" structure into a "termios". Ugh. 18 - */ 19 - #define SET_LOW_TERMIOS_BITS(termios, termio, x) { \ 20 - unsigned short __tmp; \ 21 - get_user(__tmp,&(termio)->x); \ 22 - *(unsigned short *) &(termios)->x = __tmp; \ 23 - } 24 - 25 - #define user_termio_to_kernel_termios(termios, termio) \ 26 - ({ \ 27 - SET_LOW_TERMIOS_BITS(termios, termio, c_iflag); \ 28 - SET_LOW_TERMIOS_BITS(termios, termio, c_oflag); \ 29 - SET_LOW_TERMIOS_BITS(termios, termio, c_cflag); \ 30 - SET_LOW_TERMIOS_BITS(termios, termio, c_lflag); \ 31 - copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \ 32 - }) 33 - 34 - /* 35 - * Translate a "termios" structure into a "termio". Ugh. 36 - */ 37 - #define kernel_termios_to_user_termio(termio, termios) \ 38 - ({ \ 39 - put_user((termios)->c_iflag, &(termio)->c_iflag); \ 40 - put_user((termios)->c_oflag, &(termio)->c_oflag); \ 41 - put_user((termios)->c_cflag, &(termio)->c_cflag); \ 42 - put_user((termios)->c_lflag, &(termio)->c_lflag); \ 43 - put_user((termios)->c_line, &(termio)->c_line); \ 44 - copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \ 45 - }) 46 - 47 - #define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios2)) 48 - #define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios2)) 49 - #define user_termios_to_kernel_termios_1(k, u) copy_from_user(k, u, sizeof(struct termios)) 50 - #define kernel_termios_to_user_termios_1(u, k) copy_to_user(u, k, sizeof(struct termios)) 16 + int user_termio_to_kernel_termios(struct ktermios *, struct termio __user *); 17 + int kernel_termios_to_user_termio(struct termio __user *, struct ktermios *); 18 + int user_termios_to_kernel_termios(struct ktermios *, struct termios2 __user *); 19 + int kernel_termios_to_user_termios(struct termios2 __user *, struct ktermios *); 20 + int user_termios_to_kernel_termios_1(struct ktermios *, struct termios __user *); 21 + int kernel_termios_to_user_termios_1(struct termios __user *, struct ktermios *); 51 22 52 23 #endif /* _PARISC_TERMIOS_H */
+6 -130
arch/sparc/include/asm/termios.h
··· 5 5 #include <uapi/asm/termios.h> 6 6 7 7 8 - /* 9 - * c_cc characters in the termio structure. Oh, how I love being 10 - * backwardly compatible. Notice that character 4 and 5 are 11 - * interpreted differently depending on whether ICANON is set in 12 - * c_lflag. If it's set, they are used as _VEOF and _VEOL, otherwise 13 - * as _VMIN and V_TIME. This is for compatibility with OSF/1 (which 14 - * is compatible with sysV)... 15 - */ 16 - #define _VMIN 4 17 - #define _VTIME 5 18 - 19 8 /* intr=^C quit=^\ erase=del kill=^U 20 9 eof=^D eol=\0 eol2=\0 sxtc=\0 21 10 start=^Q stop=^S susp=^Z dsusp=^Y ··· 13 24 */ 14 25 #define INIT_C_CC "\003\034\177\025\004\000\000\000\021\023\032\031\022\025\027\026\001" 15 26 16 - /* 17 - * Translate a "termio" structure into a "termios". Ugh. 18 - */ 19 - #define user_termio_to_kernel_termios(termios, termio) \ 20 - ({ \ 21 - unsigned short tmp; \ 22 - int err; \ 23 - err = get_user(tmp, &(termio)->c_iflag); \ 24 - (termios)->c_iflag = (0xffff0000 & ((termios)->c_iflag)) | tmp; \ 25 - err |= get_user(tmp, &(termio)->c_oflag); \ 26 - (termios)->c_oflag = (0xffff0000 & ((termios)->c_oflag)) | tmp; \ 27 - err |= get_user(tmp, &(termio)->c_cflag); \ 28 - (termios)->c_cflag = (0xffff0000 & ((termios)->c_cflag)) | tmp; \ 29 - err |= get_user(tmp, &(termio)->c_lflag); \ 30 - (termios)->c_lflag = (0xffff0000 & ((termios)->c_lflag)) | tmp; \ 31 - err |= copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \ 32 - err; \ 33 - }) 34 - 35 - /* 36 - * Translate a "termios" structure into a "termio". Ugh. 37 - * 38 - * Note the "fun" _VMIN overloading. 39 - */ 40 - #define kernel_termios_to_user_termio(termio, termios) \ 41 - ({ \ 42 - int err; \ 43 - err = put_user((termios)->c_iflag, &(termio)->c_iflag); \ 44 - err |= put_user((termios)->c_oflag, &(termio)->c_oflag); \ 45 - err |= put_user((termios)->c_cflag, &(termio)->c_cflag); \ 46 - err |= put_user((termios)->c_lflag, &(termio)->c_lflag); \ 47 - err |= put_user((termios)->c_line, &(termio)->c_line); \ 48 - err |= copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \ 49 - if (!((termios)->c_lflag & ICANON)) { \ 50 - err |= put_user((termios)->c_cc[VMIN], &(termio)->c_cc[_VMIN]); \ 51 - err |= put_user((termios)->c_cc[VTIME], &(termio)->c_cc[_VTIME]); \ 52 - } \ 53 - err; \ 54 - }) 55 - 56 - #define user_termios_to_kernel_termios(k, u) \ 57 - ({ \ 58 - int err; \ 59 - err = get_user((k)->c_iflag, &(u)->c_iflag); \ 60 - err |= get_user((k)->c_oflag, &(u)->c_oflag); \ 61 - err |= get_user((k)->c_cflag, &(u)->c_cflag); \ 62 - err |= get_user((k)->c_lflag, &(u)->c_lflag); \ 63 - err |= get_user((k)->c_line, &(u)->c_line); \ 64 - err |= copy_from_user((k)->c_cc, (u)->c_cc, NCCS); \ 65 - if ((k)->c_lflag & ICANON) { \ 66 - err |= get_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \ 67 - err |= get_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \ 68 - } else { \ 69 - err |= get_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \ 70 - err |= get_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \ 71 - } \ 72 - err |= get_user((k)->c_ispeed, &(u)->c_ispeed); \ 73 - err |= get_user((k)->c_ospeed, &(u)->c_ospeed); \ 74 - err; \ 75 - }) 76 - 77 - #define kernel_termios_to_user_termios(u, k) \ 78 - ({ \ 79 - int err; \ 80 - err = put_user((k)->c_iflag, &(u)->c_iflag); \ 81 - err |= put_user((k)->c_oflag, &(u)->c_oflag); \ 82 - err |= put_user((k)->c_cflag, &(u)->c_cflag); \ 83 - err |= put_user((k)->c_lflag, &(u)->c_lflag); \ 84 - err |= put_user((k)->c_line, &(u)->c_line); \ 85 - err |= copy_to_user((u)->c_cc, (k)->c_cc, NCCS); \ 86 - if (!((k)->c_lflag & ICANON)) { \ 87 - err |= put_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \ 88 - err |= put_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \ 89 - } else { \ 90 - err |= put_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \ 91 - err |= put_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \ 92 - } \ 93 - err |= put_user((k)->c_ispeed, &(u)->c_ispeed); \ 94 - err |= put_user((k)->c_ospeed, &(u)->c_ospeed); \ 95 - err; \ 96 - }) 97 - 98 - #define user_termios_to_kernel_termios_1(k, u) \ 99 - ({ \ 100 - int err; \ 101 - err = get_user((k)->c_iflag, &(u)->c_iflag); \ 102 - err |= get_user((k)->c_oflag, &(u)->c_oflag); \ 103 - err |= get_user((k)->c_cflag, &(u)->c_cflag); \ 104 - err |= get_user((k)->c_lflag, &(u)->c_lflag); \ 105 - err |= get_user((k)->c_line, &(u)->c_line); \ 106 - err |= copy_from_user((k)->c_cc, (u)->c_cc, NCCS); \ 107 - if ((k)->c_lflag & ICANON) { \ 108 - err |= get_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \ 109 - err |= get_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \ 110 - } else { \ 111 - err |= get_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \ 112 - err |= get_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \ 113 - } \ 114 - err; \ 115 - }) 116 - 117 - #define kernel_termios_to_user_termios_1(u, k) \ 118 - ({ \ 119 - int err; \ 120 - err = put_user((k)->c_iflag, &(u)->c_iflag); \ 121 - err |= put_user((k)->c_oflag, &(u)->c_oflag); \ 122 - err |= put_user((k)->c_cflag, &(u)->c_cflag); \ 123 - err |= put_user((k)->c_lflag, &(u)->c_lflag); \ 124 - err |= put_user((k)->c_line, &(u)->c_line); \ 125 - err |= copy_to_user((u)->c_cc, (k)->c_cc, NCCS); \ 126 - if (!((k)->c_lflag & ICANON)) { \ 127 - err |= put_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \ 128 - err |= put_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \ 129 - } else { \ 130 - err |= put_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \ 131 - err |= put_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \ 132 - } \ 133 - err; \ 134 - }) 27 + int user_termio_to_kernel_termios(struct ktermios *, struct termio __user *); 28 + int kernel_termios_to_user_termio(struct termio __user *, struct ktermios *); 29 + int user_termios_to_kernel_termios(struct ktermios *, struct termios2 __user *); 30 + int kernel_termios_to_user_termios(struct termios2 __user *, struct ktermios *); 31 + int user_termios_to_kernel_termios_1(struct ktermios *, struct termios __user *); 32 + int kernel_termios_to_user_termios_1(struct termios __user *, struct ktermios *); 135 33 136 34 #endif /* _SPARC_TERMIOS_H */
+3 -1
arch/sparc/kernel/Makefile
··· 87 87 obj-y += auxio_$(BITS).o 88 88 obj-$(CONFIG_SUN_PM) += apc.o pmc.o 89 89 90 + obj-y += termios.o 91 + 90 92 obj-$(CONFIG_MODULES) += module.o 91 93 obj-$(CONFIG_MODULES) += sparc_ksyms.o 92 94 obj-$(CONFIG_SPARC_LED) += led.o 93 95 obj-$(CONFIG_KGDB) += kgdb_$(BITS).o 94 - 95 96 96 97 obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o 97 98 obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o ··· 104 103 obj-$(CONFIG_SPARC64_PCI) += pci_psycho.o pci_sabre.o pci_schizo.o 105 104 obj-$(CONFIG_SPARC64_PCI) += pci_sun4v.o pci_sun4v_asm.o pci_fire.o 106 105 obj-$(CONFIG_SPARC64_PCI_MSI) += pci_msi.o 106 + 107 107 108 108 obj-$(CONFIG_COMPAT) += sys32.o sys_sparc32.o signal32.o 109 109
+115
arch/sparc/kernel/termios.c
··· 1 + #include <linux/uaccess.h> 2 + #include <linux/termios.h> 3 + 4 + /* 5 + * c_cc characters in the termio structure. Oh, how I love being 6 + * backwardly compatible. Notice that character 4 and 5 are 7 + * interpreted differently depending on whether ICANON is set in 8 + * c_lflag. If it's set, they are used as _VEOF and _VEOL, otherwise 9 + * as _VMIN and V_TIME. This is for compatibility with OSF/1 (which 10 + * is compatible with sysV)... 11 + */ 12 + #define _VMIN 4 13 + #define _VTIME 5 14 + 15 + int kernel_termios_to_user_termio(struct termio __user *termio, 16 + struct ktermios *termios) 17 + { 18 + struct termio v; 19 + memset(&v, 0, sizeof(struct termio)); 20 + v.c_iflag = termios->c_iflag; 21 + v.c_oflag = termios->c_oflag; 22 + v.c_cflag = termios->c_cflag; 23 + v.c_lflag = termios->c_lflag; 24 + v.c_line = termios->c_line; 25 + memcpy(v.c_cc, termios->c_cc, NCC); 26 + if (!(v.c_lflag & ICANON)) { 27 + v.c_cc[_VMIN] = termios->c_cc[VMIN]; 28 + v.c_cc[_VTIME] = termios->c_cc[VTIME]; 29 + } 30 + return copy_to_user(termio, &v, sizeof(struct termio)); 31 + } 32 + 33 + int user_termios_to_kernel_termios(struct ktermios *k, 34 + struct termios2 __user *u) 35 + { 36 + int err; 37 + err = get_user(k->c_iflag, &u->c_iflag); 38 + err |= get_user(k->c_oflag, &u->c_oflag); 39 + err |= get_user(k->c_cflag, &u->c_cflag); 40 + err |= get_user(k->c_lflag, &u->c_lflag); 41 + err |= get_user(k->c_line, &u->c_line); 42 + err |= copy_from_user(k->c_cc, u->c_cc, NCCS); 43 + if (k->c_lflag & ICANON) { 44 + err |= get_user(k->c_cc[VEOF], &u->c_cc[VEOF]); 45 + err |= get_user(k->c_cc[VEOL], &u->c_cc[VEOL]); 46 + } else { 47 + err |= get_user(k->c_cc[VMIN], &u->c_cc[_VMIN]); 48 + err |= get_user(k->c_cc[VTIME], &u->c_cc[_VTIME]); 49 + } 50 + err |= get_user(k->c_ispeed, &u->c_ispeed); 51 + err |= get_user(k->c_ospeed, &u->c_ospeed); 52 + return err; 53 + } 54 + 55 + int kernel_termios_to_user_termios(struct termios2 __user *u, 56 + struct ktermios *k) 57 + { 58 + int err; 59 + err = put_user(k->c_iflag, &u->c_iflag); 60 + err |= put_user(k->c_oflag, &u->c_oflag); 61 + err |= put_user(k->c_cflag, &u->c_cflag); 62 + err |= put_user(k->c_lflag, &u->c_lflag); 63 + err |= put_user(k->c_line, &u->c_line); 64 + err |= copy_to_user(u->c_cc, k->c_cc, NCCS); 65 + if (!(k->c_lflag & ICANON)) { 66 + err |= put_user(k->c_cc[VMIN], &u->c_cc[_VMIN]); 67 + err |= put_user(k->c_cc[VTIME], &u->c_cc[_VTIME]); 68 + } else { 69 + err |= put_user(k->c_cc[VEOF], &u->c_cc[VEOF]); 70 + err |= put_user(k->c_cc[VEOL], &u->c_cc[VEOL]); 71 + } 72 + err |= put_user(k->c_ispeed, &u->c_ispeed); 73 + err |= put_user(k->c_ospeed, &u->c_ospeed); 74 + return err; 75 + } 76 + 77 + int user_termios_to_kernel_termios_1(struct ktermios *k, 78 + struct termios __user *u) 79 + { 80 + int err; 81 + err = get_user(k->c_iflag, &u->c_iflag); 82 + err |= get_user(k->c_oflag, &u->c_oflag); 83 + err |= get_user(k->c_cflag, &u->c_cflag); 84 + err |= get_user(k->c_lflag, &u->c_lflag); 85 + err |= get_user(k->c_line, &u->c_line); 86 + err |= copy_from_user(k->c_cc, u->c_cc, NCCS); 87 + if (k->c_lflag & ICANON) { 88 + err |= get_user(k->c_cc[VEOF], &u->c_cc[VEOF]); 89 + err |= get_user(k->c_cc[VEOL], &u->c_cc[VEOL]); 90 + } else { 91 + err |= get_user(k->c_cc[VMIN], &u->c_cc[_VMIN]); 92 + err |= get_user(k->c_cc[VTIME], &u->c_cc[_VTIME]); 93 + } 94 + return err; 95 + } 96 + 97 + int kernel_termios_to_user_termios_1(struct termios __user *u, 98 + struct ktermios *k) 99 + { 100 + int err; 101 + err = put_user(k->c_iflag, &u->c_iflag); 102 + err |= put_user(k->c_oflag, &u->c_oflag); 103 + err |= put_user(k->c_cflag, &u->c_cflag); 104 + err |= put_user(k->c_lflag, &u->c_lflag); 105 + err |= put_user(k->c_line, &u->c_line); 106 + err |= copy_to_user(u->c_cc, k->c_cc, NCCS); 107 + if (!(k->c_lflag & ICANON)) { 108 + err |= put_user(k->c_cc[VMIN], &u->c_cc[_VMIN]); 109 + err |= put_user(k->c_cc[VTIME], &u->c_cc[_VTIME]); 110 + } else { 111 + err |= put_user(k->c_cc[VEOF], &u->c_cc[VEOF]); 112 + err |= put_user(k->c_cc[VEOL], &u->c_cc[VEOL]); 113 + } 114 + return err; 115 + }
+74
drivers/tty/tty_ioctl.c
··· 374 374 } 375 375 EXPORT_SYMBOL_GPL(tty_set_termios); 376 376 377 + 378 + /* 379 + * Translate a "termio" structure into a "termios". Ugh. 380 + */ 381 + __weak int user_termio_to_kernel_termios(struct ktermios *termios, 382 + struct termio __user *termio) 383 + { 384 + struct termio v; 385 + 386 + if (copy_from_user(&v, termio, sizeof(struct termio))) 387 + return -EFAULT; 388 + 389 + termios->c_iflag = (0xffff0000 & termios->c_iflag) | v.c_iflag; 390 + termios->c_oflag = (0xffff0000 & termios->c_oflag) | v.c_oflag; 391 + termios->c_cflag = (0xffff0000 & termios->c_cflag) | v.c_cflag; 392 + termios->c_lflag = (0xffff0000 & termios->c_lflag) | v.c_lflag; 393 + termios->c_line = (0xffff0000 & termios->c_lflag) | v.c_line; 394 + memcpy(termios->c_cc, v.c_cc, NCC); 395 + return 0; 396 + } 397 + 398 + /* 399 + * Translate a "termios" structure into a "termio". Ugh. 400 + */ 401 + __weak int kernel_termios_to_user_termio(struct termio __user *termio, 402 + struct ktermios *termios) 403 + { 404 + struct termio v; 405 + memset(&v, 0, sizeof(struct termio)); 406 + v.c_iflag = termios->c_iflag; 407 + v.c_oflag = termios->c_oflag; 408 + v.c_cflag = termios->c_cflag; 409 + v.c_lflag = termios->c_lflag; 410 + v.c_line = termios->c_line; 411 + memcpy(v.c_cc, termios->c_cc, NCC); 412 + return copy_to_user(termio, &v, sizeof(struct termio)); 413 + } 414 + 415 + #ifdef TCGETS2 416 + __weak int user_termios_to_kernel_termios(struct ktermios *k, 417 + struct termios2 __user *u) 418 + { 419 + return copy_from_user(k, u, sizeof(struct termios2)); 420 + } 421 + __weak int kernel_termios_to_user_termios(struct termios2 __user *u, 422 + struct ktermios *k) 423 + { 424 + return copy_to_user(u, k, sizeof(struct termios2)); 425 + } 426 + __weak int user_termios_to_kernel_termios_1(struct ktermios *k, 427 + struct termios __user *u) 428 + { 429 + return copy_from_user(k, u, sizeof(struct termios)); 430 + } 431 + __weak int kernel_termios_to_user_termios_1(struct termios __user *u, 432 + struct ktermios *k) 433 + { 434 + return copy_to_user(u, k, sizeof(struct termios)); 435 + } 436 + 437 + #else 438 + 439 + __weak int user_termios_to_kernel_termios(struct ktermios *k, 440 + struct termios __user *u) 441 + { 442 + return copy_from_user(k, u, sizeof(struct termios)); 443 + } 444 + __weak int kernel_termios_to_user_termios(struct termios __user *u, 445 + struct ktermios *k) 446 + { 447 + return copy_to_user(u, k, sizeof(struct termios)); 448 + } 449 + #endif /* TCGETS2 */ 450 + 377 451 /** 378 452 * set_termios - set termios values for a tty 379 453 * @tty: terminal device
+6 -63
include/asm-generic/termios-base.h
··· 9 9 10 10 #ifndef __ARCH_TERMIO_GETPUT 11 11 12 - /* 13 - * Translate a "termio" structure into a "termios". Ugh. 14 - */ 15 - static inline int user_termio_to_kernel_termios(struct ktermios *termios, 16 - struct termio __user *termio) 17 - { 18 - unsigned short tmp; 19 - 20 - if (get_user(tmp, &termio->c_iflag) < 0) 21 - goto fault; 22 - termios->c_iflag = (0xffff0000 & termios->c_iflag) | tmp; 23 - 24 - if (get_user(tmp, &termio->c_oflag) < 0) 25 - goto fault; 26 - termios->c_oflag = (0xffff0000 & termios->c_oflag) | tmp; 27 - 28 - if (get_user(tmp, &termio->c_cflag) < 0) 29 - goto fault; 30 - termios->c_cflag = (0xffff0000 & termios->c_cflag) | tmp; 31 - 32 - if (get_user(tmp, &termio->c_lflag) < 0) 33 - goto fault; 34 - termios->c_lflag = (0xffff0000 & termios->c_lflag) | tmp; 35 - 36 - if (get_user(termios->c_line, &termio->c_line) < 0) 37 - goto fault; 38 - 39 - if (copy_from_user(termios->c_cc, termio->c_cc, NCC) != 0) 40 - goto fault; 41 - 42 - return 0; 43 - 44 - fault: 45 - return -EFAULT; 46 - } 47 - 48 - /* 49 - * Translate a "termios" structure into a "termio". Ugh. 50 - */ 51 - static inline int kernel_termios_to_user_termio(struct termio __user *termio, 52 - struct ktermios *termios) 53 - { 54 - if (put_user(termios->c_iflag, &termio->c_iflag) < 0 || 55 - put_user(termios->c_oflag, &termio->c_oflag) < 0 || 56 - put_user(termios->c_cflag, &termio->c_cflag) < 0 || 57 - put_user(termios->c_lflag, &termio->c_lflag) < 0 || 58 - put_user(termios->c_line, &termio->c_line) < 0 || 59 - copy_to_user(termio->c_cc, termios->c_cc, NCC) != 0) 60 - return -EFAULT; 61 - 62 - return 0; 63 - } 64 - 65 - #ifndef user_termios_to_kernel_termios 66 - #define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios)) 67 - #endif 68 - 69 - #ifndef kernel_termios_to_user_termios 70 - #define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios)) 71 - #endif 72 - 73 - #define user_termios_to_kernel_termios_1(k, u) copy_from_user(k, u, sizeof(struct termios)) 74 - #define kernel_termios_to_user_termios_1(u, k) copy_to_user(u, k, sizeof(struct termios)) 12 + int user_termio_to_kernel_termios(struct ktermios *, struct termio __user *); 13 + int kernel_termios_to_user_termio(struct termio __user *, struct ktermios *); 14 + int user_termios_to_kernel_termios(struct ktermios *, struct termios2 __user *); 15 + int kernel_termios_to_user_termios(struct termios2 __user *, struct ktermios *); 16 + int user_termios_to_kernel_termios_1(struct ktermios *, struct termios __user *); 17 + int kernel_termios_to_user_termios_1(struct termios __user *, struct ktermios *); 75 18 76 19 #endif /* __ARCH_TERMIO_GETPUT */ 77 20
+8 -87
include/asm-generic/termios.h
··· 14 14 */ 15 15 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0" 16 16 17 - /* 18 - * Translate a "termio" structure into a "termios". Ugh. 19 - */ 20 - static inline int user_termio_to_kernel_termios(struct ktermios *termios, 21 - const struct termio __user *termio) 22 - { 23 - unsigned short tmp; 24 - 25 - if (get_user(tmp, &termio->c_iflag) < 0) 26 - goto fault; 27 - termios->c_iflag = (0xffff0000 & termios->c_iflag) | tmp; 28 - 29 - if (get_user(tmp, &termio->c_oflag) < 0) 30 - goto fault; 31 - termios->c_oflag = (0xffff0000 & termios->c_oflag) | tmp; 32 - 33 - if (get_user(tmp, &termio->c_cflag) < 0) 34 - goto fault; 35 - termios->c_cflag = (0xffff0000 & termios->c_cflag) | tmp; 36 - 37 - if (get_user(tmp, &termio->c_lflag) < 0) 38 - goto fault; 39 - termios->c_lflag = (0xffff0000 & termios->c_lflag) | tmp; 40 - 41 - if (get_user(termios->c_line, &termio->c_line) < 0) 42 - goto fault; 43 - 44 - if (copy_from_user(termios->c_cc, termio->c_cc, NCC) != 0) 45 - goto fault; 46 - 47 - return 0; 48 - 49 - fault: 50 - return -EFAULT; 51 - } 52 - 53 - /* 54 - * Translate a "termios" structure into a "termio". Ugh. 55 - */ 56 - static inline int kernel_termios_to_user_termio(struct termio __user *termio, 57 - struct ktermios *termios) 58 - { 59 - if (put_user(termios->c_iflag, &termio->c_iflag) < 0 || 60 - put_user(termios->c_oflag, &termio->c_oflag) < 0 || 61 - put_user(termios->c_cflag, &termio->c_cflag) < 0 || 62 - put_user(termios->c_lflag, &termio->c_lflag) < 0 || 63 - put_user(termios->c_line, &termio->c_line) < 0 || 64 - copy_to_user(termio->c_cc, termios->c_cc, NCC) != 0) 65 - return -EFAULT; 66 - 67 - return 0; 68 - } 69 - 17 + int user_termio_to_kernel_termios(struct ktermios *, struct termio __user *); 18 + int kernel_termios_to_user_termio(struct termio __user *, struct ktermios *); 70 19 #ifdef TCGETS2 71 - static inline int user_termios_to_kernel_termios(struct ktermios *k, 72 - struct termios2 __user *u) 73 - { 74 - return copy_from_user(k, u, sizeof(struct termios2)); 75 - } 76 - 77 - static inline int kernel_termios_to_user_termios(struct termios2 __user *u, 78 - struct ktermios *k) 79 - { 80 - return copy_to_user(u, k, sizeof(struct termios2)); 81 - } 82 - 83 - static inline int user_termios_to_kernel_termios_1(struct ktermios *k, 84 - struct termios __user *u) 85 - { 86 - return copy_from_user(k, u, sizeof(struct termios)); 87 - } 88 - 89 - static inline int kernel_termios_to_user_termios_1(struct termios __user *u, 90 - struct ktermios *k) 91 - { 92 - return copy_to_user(u, k, sizeof(struct termios)); 93 - } 20 + int user_termios_to_kernel_termios(struct ktermios *, struct termios2 __user *); 21 + int kernel_termios_to_user_termios(struct termios2 __user *, struct ktermios *); 22 + int user_termios_to_kernel_termios_1(struct ktermios *, struct termios __user *); 23 + int kernel_termios_to_user_termios_1(struct termios __user *, struct ktermios *); 94 24 #else /* TCGETS2 */ 95 - static inline int user_termios_to_kernel_termios(struct ktermios *k, 96 - struct termios __user *u) 97 - { 98 - return copy_from_user(k, u, sizeof(struct termios)); 99 - } 100 - 101 - static inline int kernel_termios_to_user_termios(struct termios __user *u, 102 - struct ktermios *k) 103 - { 104 - return copy_to_user(u, k, sizeof(struct termios)); 105 - } 25 + int user_termios_to_kernel_termios(struct ktermios *, struct termios __user *); 26 + int kernel_termios_to_user_termios(struct termios __user *, struct ktermios *); 106 27 #endif /* TCGETS2 */ 107 28 108 29 #endif /* _ASM_GENERIC_TERMIOS_H */