n_null.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. static int n_null_open(struct tty_struct *tty)
  12. {
  13. return 0;
  14. }
  15. static void n_null_close(struct tty_struct *tty)
  16. {
  17. }
  18. static ssize_t n_null_read(struct tty_struct *tty, struct file *file,
  19. unsigned char __user * buf, size_t nr)
  20. {
  21. return -EOPNOTSUPP;
  22. }
  23. static ssize_t n_null_write(struct tty_struct *tty, struct file *file,
  24. const unsigned char *buf, size_t nr)
  25. {
  26. return -EOPNOTSUPP;
  27. }
  28. static void n_null_receivebuf(struct tty_struct *tty,
  29. const unsigned char *cp, char *fp,
  30. int cnt)
  31. {
  32. }
  33. static struct tty_ldisc_ops null_ldisc = {
  34. .owner = THIS_MODULE,
  35. .magic = TTY_LDISC_MAGIC,
  36. .name = "n_null",
  37. .open = n_null_open,
  38. .close = n_null_close,
  39. .read = n_null_read,
  40. .write = n_null_write,
  41. .receive_buf = n_null_receivebuf
  42. };
  43. static int __init n_null_init(void)
  44. {
  45. BUG_ON(tty_register_ldisc(N_NULL, &null_ldisc));
  46. return 0;
  47. }
  48. static void __exit n_null_exit(void)
  49. {
  50. tty_unregister_ldisc(N_NULL);
  51. }
  52. module_init(n_null_init);
  53. module_exit(n_null_exit);
  54. MODULE_LICENSE("GPL");
  55. MODULE_AUTHOR("Alan Cox");
  56. MODULE_ALIAS_LDISC(N_NULL);
  57. MODULE_DESCRIPTION("Null ldisc driver");