^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* termios.h: generic termios/termio user copying/translation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #ifndef _ASM_GENERIC_TERMIOS_BASE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #define _ASM_GENERIC_TERMIOS_BASE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifndef __ARCH_TERMIO_GETPUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Translate a "termio" structure into a "termios". Ugh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static inline int user_termio_to_kernel_termios(struct ktermios *termios,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct termio __user *termio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) unsigned short tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) if (get_user(tmp, &termio->c_iflag) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) termios->c_iflag = (0xffff0000 & termios->c_iflag) | tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) if (get_user(tmp, &termio->c_oflag) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) termios->c_oflag = (0xffff0000 & termios->c_oflag) | tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (get_user(tmp, &termio->c_cflag) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) termios->c_cflag = (0xffff0000 & termios->c_cflag) | tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if (get_user(tmp, &termio->c_lflag) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) termios->c_lflag = (0xffff0000 & termios->c_lflag) | tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (get_user(termios->c_line, &termio->c_line) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (copy_from_user(termios->c_cc, termio->c_cc, NCC) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) fault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * Translate a "termios" structure into a "termio". Ugh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static inline int kernel_termios_to_user_termio(struct termio __user *termio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct ktermios *termios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (put_user(termios->c_iflag, &termio->c_iflag) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) put_user(termios->c_oflag, &termio->c_oflag) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) put_user(termios->c_cflag, &termio->c_cflag) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) put_user(termios->c_lflag, &termio->c_lflag) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) put_user(termios->c_line, &termio->c_line) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) copy_to_user(termio->c_cc, termios->c_cc, NCC) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #ifndef user_termios_to_kernel_termios
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #ifndef kernel_termios_to_user_termios
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define user_termios_to_kernel_termios_1(k, u) copy_from_user(k, u, sizeof(struct termios))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define kernel_termios_to_user_termios_1(u, k) copy_to_user(u, k, sizeof(struct termios))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #endif /* __ARCH_TERMIO_GETPUT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #endif /* _ASM_GENERIC_TERMIOS_BASE_H */