Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/types.h>
0003 #include <linux/errno.h>
0004 #include <linux/tty.h>
0005 #include <linux/module.h>
0006 
0007 /*
0008  *  n_null.c - Null line discipline used in the failure path
0009  *
0010  *  Copyright (C) Intel 2017
0011  */
0012 
0013 static int n_null_open(struct tty_struct *tty)
0014 {
0015     return 0;
0016 }
0017 
0018 static void n_null_close(struct tty_struct *tty)
0019 {
0020 }
0021 
0022 static ssize_t n_null_read(struct tty_struct *tty, struct file *file,
0023                unsigned char *buf, size_t nr,
0024                void **cookie, unsigned long offset)
0025 {
0026     return -EOPNOTSUPP;
0027 }
0028 
0029 static ssize_t n_null_write(struct tty_struct *tty, struct file *file,
0030                 const unsigned char *buf, size_t nr)
0031 {
0032     return -EOPNOTSUPP;
0033 }
0034 
0035 static void n_null_receivebuf(struct tty_struct *tty,
0036                  const unsigned char *cp, const char *fp,
0037                  int cnt)
0038 {
0039 }
0040 
0041 static struct tty_ldisc_ops null_ldisc = {
0042     .owner      =   THIS_MODULE,
0043     .num        =   N_NULL,
0044     .name       =   "n_null",
0045     .open       =   n_null_open,
0046     .close      =   n_null_close,
0047     .read       =   n_null_read,
0048     .write      =   n_null_write,
0049     .receive_buf    =   n_null_receivebuf
0050 };
0051 
0052 static int __init n_null_init(void)
0053 {
0054     BUG_ON(tty_register_ldisc(&null_ldisc));
0055     return 0;
0056 }
0057 
0058 static void __exit n_null_exit(void)
0059 {
0060     tty_unregister_ldisc(&null_ldisc);
0061 }
0062 
0063 module_init(n_null_init);
0064 module_exit(n_null_exit);
0065 
0066 MODULE_LICENSE("GPL");
0067 MODULE_AUTHOR("Alan Cox");
0068 MODULE_ALIAS_LDISC(N_NULL);
0069 MODULE_DESCRIPTION("Null ldisc driver");