1e3b3d0f5SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 28a8dabf2SAlan Cox #include <linux/types.h> 38a8dabf2SAlan Cox #include <linux/errno.h> 48a8dabf2SAlan Cox #include <linux/tty.h> 58a8dabf2SAlan Cox #include <linux/module.h> 68a8dabf2SAlan Cox 78a8dabf2SAlan Cox /* 88a8dabf2SAlan Cox * n_null.c - Null line discipline used in the failure path 98a8dabf2SAlan Cox * 108a8dabf2SAlan Cox * Copyright (C) Intel 2017 118a8dabf2SAlan Cox */ 128a8dabf2SAlan Cox 138a8dabf2SAlan Cox static int n_null_open(struct tty_struct *tty) 148a8dabf2SAlan Cox { 158a8dabf2SAlan Cox return 0; 168a8dabf2SAlan Cox } 178a8dabf2SAlan Cox 188a8dabf2SAlan Cox static void n_null_close(struct tty_struct *tty) 198a8dabf2SAlan Cox { 208a8dabf2SAlan Cox } 218a8dabf2SAlan Cox 228a8dabf2SAlan Cox static ssize_t n_null_read(struct tty_struct *tty, struct file *file, 233b830a9cSLinus Torvalds unsigned char *buf, size_t nr, 243b830a9cSLinus Torvalds void **cookie, unsigned long offset) 258a8dabf2SAlan Cox { 268a8dabf2SAlan Cox return -EOPNOTSUPP; 278a8dabf2SAlan Cox } 288a8dabf2SAlan Cox 298a8dabf2SAlan Cox static ssize_t n_null_write(struct tty_struct *tty, struct file *file, 308a8dabf2SAlan Cox const unsigned char *buf, size_t nr) 318a8dabf2SAlan Cox { 328a8dabf2SAlan Cox return -EOPNOTSUPP; 338a8dabf2SAlan Cox } 348a8dabf2SAlan Cox 358a8dabf2SAlan Cox static void n_null_receivebuf(struct tty_struct *tty, 360f3dcf3bSJiri Slaby const unsigned char *cp, const char *fp, 378a8dabf2SAlan Cox int cnt) 388a8dabf2SAlan Cox { 398a8dabf2SAlan Cox } 408a8dabf2SAlan Cox 418a8dabf2SAlan Cox static struct tty_ldisc_ops null_ldisc = { 428a8dabf2SAlan Cox .owner = THIS_MODULE, 43*fbadf70aSJiri Slaby .num = N_NULL, 448a8dabf2SAlan Cox .name = "n_null", 458a8dabf2SAlan Cox .open = n_null_open, 468a8dabf2SAlan Cox .close = n_null_close, 478a8dabf2SAlan Cox .read = n_null_read, 488a8dabf2SAlan Cox .write = n_null_write, 498a8dabf2SAlan Cox .receive_buf = n_null_receivebuf 508a8dabf2SAlan Cox }; 518a8dabf2SAlan Cox 528a8dabf2SAlan Cox static int __init n_null_init(void) 538a8dabf2SAlan Cox { 54*fbadf70aSJiri Slaby BUG_ON(tty_register_ldisc(&null_ldisc)); 558a8dabf2SAlan Cox return 0; 568a8dabf2SAlan Cox } 578a8dabf2SAlan Cox 588a8dabf2SAlan Cox static void __exit n_null_exit(void) 598a8dabf2SAlan Cox { 608a8dabf2SAlan Cox tty_unregister_ldisc(N_NULL); 618a8dabf2SAlan Cox } 628a8dabf2SAlan Cox 638a8dabf2SAlan Cox module_init(n_null_init); 648a8dabf2SAlan Cox module_exit(n_null_exit); 658a8dabf2SAlan Cox 668a8dabf2SAlan Cox MODULE_LICENSE("GPL"); 678a8dabf2SAlan Cox MODULE_AUTHOR("Alan Cox"); 688a8dabf2SAlan Cox MODULE_ALIAS_LDISC(N_NULL); 698a8dabf2SAlan Cox MODULE_DESCRIPTION("Null ldisc driver"); 70