tty_mutex.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. int tty_lock_interruptible(struct tty_struct *tty)
  22. {
  23. int ret;
  24. if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
  25. return -EIO;
  26. tty_kref_get(tty);
  27. ret = mutex_lock_interruptible(&tty->legacy_mutex);
  28. if (ret)
  29. tty_kref_put(tty);
  30. return ret;
  31. }
  32. void __lockfunc tty_unlock(struct tty_struct *tty)
  33. {
  34. if (tty->magic != TTY_MAGIC) {
  35. pr_err("U Bad %p\n", tty);
  36. WARN_ON(1);
  37. return;
  38. }
  39. mutex_unlock(&tty->legacy_mutex);
  40. tty_kref_put(tty);
  41. }
  42. EXPORT_SYMBOL(tty_unlock);
  43. void __lockfunc tty_lock_slave(struct tty_struct *tty)
  44. {
  45. if (tty && tty != tty->link)
  46. tty_lock(tty);
  47. }
  48. void __lockfunc tty_unlock_slave(struct tty_struct *tty)
  49. {
  50. if (tty && tty != tty->link)
  51. tty_unlock(tty);
  52. }
  53. void tty_set_lock_subclass(struct tty_struct *tty)
  54. {
  55. lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
  56. }