18a8dabf2SAlan Cox #include <linux/types.h> 28a8dabf2SAlan Cox #include <linux/errno.h> 38a8dabf2SAlan Cox #include <linux/tty.h> 48a8dabf2SAlan Cox #include <linux/module.h> 58a8dabf2SAlan Cox 68a8dabf2SAlan Cox /* 78a8dabf2SAlan Cox * n_null.c - Null line discipline used in the failure path 88a8dabf2SAlan Cox * 98a8dabf2SAlan Cox * Copyright (C) Intel 2017 108a8dabf2SAlan Cox * 118a8dabf2SAlan Cox * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 128a8dabf2SAlan Cox * 138a8dabf2SAlan Cox * This program is free software; you can redistribute it and/or modify 148a8dabf2SAlan Cox * it under the terms of the GNU General Public License version 2 158a8dabf2SAlan Cox * as published by the Free Software Foundation. 168a8dabf2SAlan Cox * 178a8dabf2SAlan Cox * This program is distributed in the hope that it will be useful, 188a8dabf2SAlan Cox * but WITHOUT ANY WARRANTY; without even the implied warranty of 198a8dabf2SAlan Cox * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 208a8dabf2SAlan Cox * GNU General Public License for more details. 218a8dabf2SAlan Cox * 228a8dabf2SAlan Cox * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 238a8dabf2SAlan Cox */ 248a8dabf2SAlan Cox 258a8dabf2SAlan Cox static int n_null_open(struct tty_struct *tty) 268a8dabf2SAlan Cox { 278a8dabf2SAlan Cox return 0; 288a8dabf2SAlan Cox } 298a8dabf2SAlan Cox 308a8dabf2SAlan Cox static void n_null_close(struct tty_struct *tty) 318a8dabf2SAlan Cox { 328a8dabf2SAlan Cox } 338a8dabf2SAlan Cox 348a8dabf2SAlan Cox static ssize_t n_null_read(struct tty_struct *tty, struct file *file, 358a8dabf2SAlan Cox unsigned char __user * buf, size_t nr) 368a8dabf2SAlan Cox { 378a8dabf2SAlan Cox return -EOPNOTSUPP; 388a8dabf2SAlan Cox } 398a8dabf2SAlan Cox 408a8dabf2SAlan Cox static ssize_t n_null_write(struct tty_struct *tty, struct file *file, 418a8dabf2SAlan Cox const unsigned char *buf, size_t nr) 428a8dabf2SAlan Cox { 438a8dabf2SAlan Cox return -EOPNOTSUPP; 448a8dabf2SAlan Cox } 458a8dabf2SAlan Cox 468a8dabf2SAlan Cox static void n_null_receivebuf(struct tty_struct *tty, 478a8dabf2SAlan Cox const unsigned char *cp, char *fp, 488a8dabf2SAlan Cox int cnt) 498a8dabf2SAlan Cox { 508a8dabf2SAlan Cox } 518a8dabf2SAlan Cox 528a8dabf2SAlan Cox static struct tty_ldisc_ops null_ldisc = { 538a8dabf2SAlan Cox .owner = THIS_MODULE, 548a8dabf2SAlan Cox .magic = TTY_LDISC_MAGIC, 558a8dabf2SAlan Cox .name = "n_null", 568a8dabf2SAlan Cox .open = n_null_open, 578a8dabf2SAlan Cox .close = n_null_close, 588a8dabf2SAlan Cox .read = n_null_read, 598a8dabf2SAlan Cox .write = n_null_write, 608a8dabf2SAlan Cox .receive_buf = n_null_receivebuf 618a8dabf2SAlan Cox }; 628a8dabf2SAlan Cox 638a8dabf2SAlan Cox static int __init n_null_init(void) 648a8dabf2SAlan Cox { 658a8dabf2SAlan Cox BUG_ON(tty_register_ldisc(N_NULL, &null_ldisc)); 668a8dabf2SAlan Cox return 0; 678a8dabf2SAlan Cox } 688a8dabf2SAlan Cox 698a8dabf2SAlan Cox static void __exit n_null_exit(void) 708a8dabf2SAlan Cox { 718a8dabf2SAlan Cox tty_unregister_ldisc(N_NULL); 728a8dabf2SAlan Cox } 738a8dabf2SAlan Cox 748a8dabf2SAlan Cox module_init(n_null_init); 758a8dabf2SAlan Cox module_exit(n_null_exit); 768a8dabf2SAlan Cox 778a8dabf2SAlan Cox MODULE_LICENSE("GPL"); 788a8dabf2SAlan Cox MODULE_AUTHOR("Alan Cox"); 798a8dabf2SAlan Cox MODULE_ALIAS_LDISC(N_NULL); 808a8dabf2SAlan Cox MODULE_DESCRIPTION("Null ldisc driver"); 81