tty_mutex.c 977 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <linux/tty.h>
  2. #include <linux/module.h>
  3. #include <linux/kallsyms.h>
  4. #include <linux/semaphore.h>
  5. #include <linux/sched.h>
  6. /* Legacy tty mutex glue */
  7. /*
  8. * Getting the big tty mutex.
  9. */
  10. void __lockfunc tty_lock(struct tty_struct *tty)
  11. {
  12. if (tty->magic != TTY_MAGIC) {
  13. pr_err("L Bad %p\n", tty);
  14. WARN_ON(1);
  15. return;
  16. }
  17. tty_kref_get(tty);
  18. mutex_lock(&tty->legacy_mutex);
  19. }
  20. EXPORT_SYMBOL(tty_lock);
  21. void __lockfunc tty_unlock(struct tty_struct *tty)
  22. {
  23. if (tty->magic != TTY_MAGIC) {
  24. pr_err("U Bad %p\n", tty);
  25. WARN_ON(1);
  26. return;
  27. }
  28. mutex_unlock(&tty->legacy_mutex);
  29. tty_kref_put(tty);
  30. }
  31. EXPORT_SYMBOL(tty_unlock);
  32. void __lockfunc tty_lock_slave(struct tty_struct *tty)
  33. {
  34. if (tty && tty != tty->link)
  35. tty_lock(tty);
  36. }
  37. void __lockfunc tty_unlock_slave(struct tty_struct *tty)
  38. {
  39. if (tty && tty != tty->link)
  40. tty_unlock(tty);
  41. }
  42. void tty_set_lock_subclass(struct tty_struct *tty)
  43. {
  44. lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
  45. }