Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* termios.h: generic termios/termio user copying/translation
0003  */
0004 
0005 #ifndef _ASM_GENERIC_TERMIOS_BASE_H
0006 #define _ASM_GENERIC_TERMIOS_BASE_H
0007 
0008 #include <linux/uaccess.h>
0009 
0010 #ifndef __ARCH_TERMIO_GETPUT
0011 
0012 /*
0013  * Translate a "termio" structure into a "termios". Ugh.
0014  */
0015 static inline int user_termio_to_kernel_termios(struct ktermios *termios,
0016                         struct termio __user *termio)
0017 {
0018     unsigned short tmp;
0019 
0020     if (get_user(tmp, &termio->c_iflag) < 0)
0021         goto fault;
0022     termios->c_iflag = (0xffff0000 & termios->c_iflag) | tmp;
0023 
0024     if (get_user(tmp, &termio->c_oflag) < 0)
0025         goto fault;
0026     termios->c_oflag = (0xffff0000 & termios->c_oflag) | tmp;
0027 
0028     if (get_user(tmp, &termio->c_cflag) < 0)
0029         goto fault;
0030     termios->c_cflag = (0xffff0000 & termios->c_cflag) | tmp;
0031 
0032     if (get_user(tmp, &termio->c_lflag) < 0)
0033         goto fault;
0034     termios->c_lflag = (0xffff0000 & termios->c_lflag) | tmp;
0035 
0036     if (get_user(termios->c_line, &termio->c_line) < 0)
0037         goto fault;
0038 
0039     if (copy_from_user(termios->c_cc, termio->c_cc, NCC) != 0)
0040         goto fault;
0041 
0042     return 0;
0043 
0044  fault:
0045     return -EFAULT;
0046 }
0047 
0048 /*
0049  * Translate a "termios" structure into a "termio". Ugh.
0050  */
0051 static inline int kernel_termios_to_user_termio(struct termio __user *termio,
0052                         struct ktermios *termios)
0053 {
0054     if (put_user(termios->c_iflag, &termio->c_iflag) < 0 ||
0055         put_user(termios->c_oflag, &termio->c_oflag) < 0 ||
0056         put_user(termios->c_cflag, &termio->c_cflag) < 0 ||
0057         put_user(termios->c_lflag, &termio->c_lflag) < 0 ||
0058         put_user(termios->c_line,  &termio->c_line) < 0 ||
0059         copy_to_user(termio->c_cc, termios->c_cc, NCC) != 0)
0060         return -EFAULT;
0061 
0062     return 0;
0063 }
0064 
0065 #ifndef user_termios_to_kernel_termios
0066 #define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios))
0067 #endif
0068 
0069 #ifndef kernel_termios_to_user_termios
0070 #define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios))
0071 #endif
0072 
0073 #define user_termios_to_kernel_termios_1(k, u) copy_from_user(k, u, sizeof(struct termios))
0074 #define kernel_termios_to_user_termios_1(u, k) copy_to_user(u, k, sizeof(struct termios))
0075 
0076 #endif  /* __ARCH_TERMIO_GETPUT */
0077 
0078 #endif /* _ASM_GENERIC_TERMIOS_BASE_H */