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