1 #include <linux/types.h> 2 #include <linux/errno.h> 3 #include <linux/tty.h> 4 #include <linux/module.h> 5 6 /* 7 * n_null.c - Null line discipline used in the failure path 8 * 9 * Copyright (C) Intel 2017 10 * 11 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 12 * 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License version 2 15 * as published by the Free Software Foundation. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 23 */ 24 25 static int n_null_open(struct tty_struct *tty) 26 { 27 return 0; 28 } 29 30 static void n_null_close(struct tty_struct *tty) 31 { 32 } 33 34 static ssize_t n_null_read(struct tty_struct *tty, struct file *file, 35 unsigned char __user * buf, size_t nr) 36 { 37 return -EOPNOTSUPP; 38 } 39 40 static ssize_t n_null_write(struct tty_struct *tty, struct file *file, 41 const unsigned char *buf, size_t nr) 42 { 43 return -EOPNOTSUPP; 44 } 45 46 static void n_null_receivebuf(struct tty_struct *tty, 47 const unsigned char *cp, char *fp, 48 int cnt) 49 { 50 } 51 52 static struct tty_ldisc_ops null_ldisc = { 53 .owner = THIS_MODULE, 54 .magic = TTY_LDISC_MAGIC, 55 .name = "n_null", 56 .open = n_null_open, 57 .close = n_null_close, 58 .read = n_null_read, 59 .write = n_null_write, 60 .receive_buf = n_null_receivebuf 61 }; 62 63 static int __init n_null_init(void) 64 { 65 BUG_ON(tty_register_ldisc(N_NULL, &null_ldisc)); 66 return 0; 67 } 68 69 static void __exit n_null_exit(void) 70 { 71 tty_unregister_ldisc(N_NULL); 72 } 73 74 module_init(n_null_init); 75 module_exit(n_null_exit); 76 77 MODULE_LICENSE("GPL"); 78 MODULE_AUTHOR("Alan Cox"); 79 MODULE_ALIAS_LDISC(N_NULL); 80 MODULE_DESCRIPTION("Null ldisc driver"); 81