n_null.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. * n_null.c - Null line discipline used in the failure path
  8. *
  9. * Copyright (C) Intel 2017
  10. *
  11. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. */
  24. static int n_null_open(struct tty_struct *tty)
  25. {
  26. return 0;
  27. }
  28. static void n_null_close(struct tty_struct *tty)
  29. {
  30. }
  31. static ssize_t n_null_read(struct tty_struct *tty, struct file *file,
  32. unsigned char __user * buf, size_t nr)
  33. {
  34. return -EOPNOTSUPP;
  35. }
  36. static ssize_t n_null_write(struct tty_struct *tty, struct file *file,
  37. const unsigned char *buf, size_t nr)
  38. {
  39. return -EOPNOTSUPP;
  40. }
  41. static void n_null_receivebuf(struct tty_struct *tty,
  42. const unsigned char *cp, char *fp,
  43. int cnt)
  44. {
  45. }
  46. static struct tty_ldisc_ops null_ldisc = {
  47. .owner = THIS_MODULE,
  48. .magic = TTY_LDISC_MAGIC,
  49. .name = "n_null",
  50. .open = n_null_open,
  51. .close = n_null_close,
  52. .read = n_null_read,
  53. .write = n_null_write,
  54. .receive_buf = n_null_receivebuf
  55. };
  56. static int __init n_null_init(void)
  57. {
  58. BUG_ON(tty_register_ldisc(N_NULL, &null_ldisc));
  59. return 0;
  60. }
  61. static void __exit n_null_exit(void)
  62. {
  63. tty_unregister_ldisc(N_NULL);
  64. }
  65. module_init(n_null_init);
  66. module_exit(n_null_exit);
  67. MODULE_LICENSE("GPL");
  68. MODULE_AUTHOR("Alan Cox");
  69. MODULE_ALIAS_LDISC(N_NULL);
  70. MODULE_DESCRIPTION("Null ldisc driver");