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