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 | static ssize_t n_null_read(struct tty_struct *tty, struct file *file, u8 *buf, |
14 | size_t nr, void **cookie, unsigned long offset) |
15 | { |
16 | return -EOPNOTSUPP; |
17 | } |
18 | |
19 | static ssize_t n_null_write(struct tty_struct *tty, struct file *file, |
20 | const u8 *buf, size_t nr) |
21 | { |
22 | return -EOPNOTSUPP; |
23 | } |
24 | |
25 | static struct tty_ldisc_ops null_ldisc = { |
26 | .owner = THIS_MODULE, |
27 | .num = N_NULL, |
28 | .name = "n_null" , |
29 | .read = n_null_read, |
30 | .write = n_null_write, |
31 | }; |
32 | |
33 | static int __init n_null_init(void) |
34 | { |
35 | BUG_ON(tty_register_ldisc(&null_ldisc)); |
36 | return 0; |
37 | } |
38 | |
39 | static void __exit n_null_exit(void) |
40 | { |
41 | tty_unregister_ldisc(ldisc: &null_ldisc); |
42 | } |
43 | |
44 | module_init(n_null_init); |
45 | module_exit(n_null_exit); |
46 | |
47 | MODULE_LICENSE("GPL" ); |
48 | MODULE_AUTHOR("Alan Cox" ); |
49 | MODULE_ALIAS_LDISC(N_NULL); |
50 | MODULE_DESCRIPTION("Null ldisc driver" ); |
51 | |