18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci#include <linux/types.h> 38c2ecf20Sopenharmony_ci#include <linux/errno.h> 48c2ecf20Sopenharmony_ci#include <linux/tty.h> 58c2ecf20Sopenharmony_ci#include <linux/module.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci/* 88c2ecf20Sopenharmony_ci * n_null.c - Null line discipline used in the failure path 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Copyright (C) Intel 2017 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistatic int n_null_open(struct tty_struct *tty) 148c2ecf20Sopenharmony_ci{ 158c2ecf20Sopenharmony_ci return 0; 168c2ecf20Sopenharmony_ci} 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistatic void n_null_close(struct tty_struct *tty) 198c2ecf20Sopenharmony_ci{ 208c2ecf20Sopenharmony_ci} 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistatic ssize_t n_null_read(struct tty_struct *tty, struct file *file, 238c2ecf20Sopenharmony_ci unsigned char *buf, size_t nr, 248c2ecf20Sopenharmony_ci void **cookie, unsigned long offset) 258c2ecf20Sopenharmony_ci{ 268c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 278c2ecf20Sopenharmony_ci} 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistatic ssize_t n_null_write(struct tty_struct *tty, struct file *file, 308c2ecf20Sopenharmony_ci const unsigned char *buf, size_t nr) 318c2ecf20Sopenharmony_ci{ 328c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 338c2ecf20Sopenharmony_ci} 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_cistatic void n_null_receivebuf(struct tty_struct *tty, 368c2ecf20Sopenharmony_ci const unsigned char *cp, char *fp, 378c2ecf20Sopenharmony_ci int cnt) 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci} 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic struct tty_ldisc_ops null_ldisc = { 428c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 438c2ecf20Sopenharmony_ci .magic = TTY_LDISC_MAGIC, 448c2ecf20Sopenharmony_ci .name = "n_null", 458c2ecf20Sopenharmony_ci .open = n_null_open, 468c2ecf20Sopenharmony_ci .close = n_null_close, 478c2ecf20Sopenharmony_ci .read = n_null_read, 488c2ecf20Sopenharmony_ci .write = n_null_write, 498c2ecf20Sopenharmony_ci .receive_buf = n_null_receivebuf 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic int __init n_null_init(void) 538c2ecf20Sopenharmony_ci{ 548c2ecf20Sopenharmony_ci BUG_ON(tty_register_ldisc(N_NULL, &null_ldisc)); 558c2ecf20Sopenharmony_ci return 0; 568c2ecf20Sopenharmony_ci} 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistatic void __exit n_null_exit(void) 598c2ecf20Sopenharmony_ci{ 608c2ecf20Sopenharmony_ci tty_unregister_ldisc(N_NULL); 618c2ecf20Sopenharmony_ci} 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cimodule_init(n_null_init); 648c2ecf20Sopenharmony_cimodule_exit(n_null_exit); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 678c2ecf20Sopenharmony_ciMODULE_AUTHOR("Alan Cox"); 688c2ecf20Sopenharmony_ciMODULE_ALIAS_LDISC(N_NULL); 698c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Null ldisc driver"); 70