tty_mutex.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 tty_lock(struct tty_struct *tty)
  11. {
  12. if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
  13. return;
  14. tty_kref_get(tty);
  15. mutex_lock(&tty->legacy_mutex);
  16. }
  17. EXPORT_SYMBOL(tty_lock);
  18. int tty_lock_interruptible(struct tty_struct *tty)
  19. {
  20. int ret;
  21. if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
  22. return -EIO;
  23. tty_kref_get(tty);
  24. ret = mutex_lock_interruptible(&tty->legacy_mutex);
  25. if (ret)
  26. tty_kref_put(tty);
  27. return ret;
  28. }
  29. void tty_unlock(struct tty_struct *tty)
  30. {
  31. if (WARN(tty->magic != TTY_MAGIC, "U Bad %p\n", tty))
  32. return;
  33. mutex_unlock(&tty->legacy_mutex);
  34. tty_kref_put(tty);
  35. }
  36. EXPORT_SYMBOL(tty_unlock);
  37. void tty_lock_slave(struct tty_struct *tty)
  38. {
  39. if (tty && tty != tty->link)
  40. tty_lock(tty);
  41. }
  42. void tty_unlock_slave(struct tty_struct *tty)
  43. {
  44. if (tty && tty != tty->link)
  45. tty_unlock(tty);
  46. }
  47. void tty_set_lock_subclass(struct tty_struct *tty)
  48. {
  49. lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
  50. }