blob: cf6dc0fa401a255ad359a9073e8247ea232f5055 [file] [log] [blame]
Greg Kroah-Hartmane3b3d0f2017-11-06 18:11:51 +01001// SPDX-License-Identifier: GPL-2.0
Alan Cox8a8dabf2017-06-02 13:49:30 +01002#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
26static int n_null_open(struct tty_struct *tty)
27{
28 return 0;
29}
30
31static void n_null_close(struct tty_struct *tty)
32{
33}
34
35static 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
41static 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
47static void n_null_receivebuf(struct tty_struct *tty,
48 const unsigned char *cp, char *fp,
49 int cnt)
50{
51}
52
53static 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
64static int __init n_null_init(void)
65{
66 BUG_ON(tty_register_ldisc(N_NULL, &null_ldisc));
67 return 0;
68}
69
70static void __exit n_null_exit(void)
71{
72 tty_unregister_ldisc(N_NULL);
73}
74
75module_init(n_null_init);
76module_exit(n_null_exit);
77
78MODULE_LICENSE("GPL");
79MODULE_AUTHOR("Alan Cox");
80MODULE_ALIAS_LDISC(N_NULL);
81MODULE_DESCRIPTION("Null ldisc driver");