Linux Audio

Check our new training course

Embedded Linux training

Mar 31-Apr 8, 2025
Register
Loading...
v4.10.11
 
  1#ifndef _ASM_GENERIC_TERMIOS_H
  2#define _ASM_GENERIC_TERMIOS_H
  3
  4
  5#include <linux/uaccess.h>
  6#include <uapi/asm-generic/termios.h>
  7
  8/*	intr=^C		quit=^\		erase=del	kill=^U
  9	eof=^D		vtime=\0	vmin=\1		sxtc=\0
 10	start=^Q	stop=^S		susp=^Z		eol=\0
 11	reprint=^R	discard=^U	werase=^W	lnext=^V
 12	eol2=\0
 13*/
 14#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
 15
 16/*
 17 * Translate a "termio" structure into a "termios". Ugh.
 18 */
 19static inline int user_termio_to_kernel_termios(struct ktermios *termios,
 20						const struct termio __user *termio)
 21{
 22	unsigned short tmp;
 23
 24	if (get_user(tmp, &termio->c_iflag) < 0)
 25		goto fault;
 26	termios->c_iflag = (0xffff0000 & termios->c_iflag) | tmp;
 27
 28	if (get_user(tmp, &termio->c_oflag) < 0)
 29		goto fault;
 30	termios->c_oflag = (0xffff0000 & termios->c_oflag) | tmp;
 31
 32	if (get_user(tmp, &termio->c_cflag) < 0)
 33		goto fault;
 34	termios->c_cflag = (0xffff0000 & termios->c_cflag) | tmp;
 35
 36	if (get_user(tmp, &termio->c_lflag) < 0)
 37		goto fault;
 38	termios->c_lflag = (0xffff0000 & termios->c_lflag) | tmp;
 39
 40	if (get_user(termios->c_line, &termio->c_line) < 0)
 41		goto fault;
 42
 43	if (copy_from_user(termios->c_cc, termio->c_cc, NCC) != 0)
 44		goto fault;
 45
 46	return 0;
 47
 48 fault:
 49	return -EFAULT;
 50}
 51
 52/*
 53 * Translate a "termios" structure into a "termio". Ugh.
 54 */
 55static inline int kernel_termios_to_user_termio(struct termio __user *termio,
 56						struct ktermios *termios)
 57{
 58	if (put_user(termios->c_iflag, &termio->c_iflag) < 0 ||
 59	    put_user(termios->c_oflag, &termio->c_oflag) < 0 ||
 60	    put_user(termios->c_cflag, &termio->c_cflag) < 0 ||
 61	    put_user(termios->c_lflag, &termio->c_lflag) < 0 ||
 62	    put_user(termios->c_line,  &termio->c_line) < 0 ||
 63	    copy_to_user(termio->c_cc, termios->c_cc, NCC) != 0)
 64		return -EFAULT;
 65
 66	return 0;
 67}
 68
 69#ifdef TCGETS2
 70static inline int user_termios_to_kernel_termios(struct ktermios *k,
 71						 struct termios2 __user *u)
 72{
 73	return copy_from_user(k, u, sizeof(struct termios2));
 74}
 75
 76static inline int kernel_termios_to_user_termios(struct termios2 __user *u,
 77						 struct ktermios *k)
 78{
 79	return copy_to_user(u, k, sizeof(struct termios2));
 80}
 81
 82static inline int user_termios_to_kernel_termios_1(struct ktermios *k,
 83						   struct termios __user *u)
 84{
 85	return copy_from_user(k, u, sizeof(struct termios));
 86}
 87
 88static inline int kernel_termios_to_user_termios_1(struct termios __user *u,
 89						   struct ktermios *k)
 90{
 91	return copy_to_user(u, k, sizeof(struct termios));
 92}
 93#else /* TCGETS2 */
 94static inline int user_termios_to_kernel_termios(struct ktermios *k,
 95						 struct termios __user *u)
 96{
 97	return copy_from_user(k, u, sizeof(struct termios));
 98}
 99
100static inline int kernel_termios_to_user_termios(struct termios __user *u,
101						 struct ktermios *k)
102{
103	return copy_to_user(u, k, sizeof(struct termios));
104}
105#endif /* TCGETS2 */
106
107#endif /* _ASM_GENERIC_TERMIOS_H */
v5.9
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef _ASM_GENERIC_TERMIOS_H
  3#define _ASM_GENERIC_TERMIOS_H
  4
  5
  6#include <linux/uaccess.h>
  7#include <uapi/asm-generic/termios.h>
  8
  9/*	intr=^C		quit=^\		erase=del	kill=^U
 10	eof=^D		vtime=\0	vmin=\1		sxtc=\0
 11	start=^Q	stop=^S		susp=^Z		eol=\0
 12	reprint=^R	discard=^U	werase=^W	lnext=^V
 13	eol2=\0
 14*/
 15#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
 16
 17/*
 18 * Translate a "termio" structure into a "termios". Ugh.
 19 */
 20static 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 */
 56static 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
 70#ifdef TCGETS2
 71static 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
 77static 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
 83static 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
 89static 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}
 94#else /* TCGETS2 */
 95static 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
101static 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}
106#endif /* TCGETS2 */
107
108#endif /* _ASM_GENERIC_TERMIOS_H */