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