tty_mutex.c 994 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/tty.h>
  3. #include <linux/module.h>
  4. #include <linux/kallsyms.h>
  5. #include <linux/semaphore.h>
  6. #include <linux/sched.h>
  7. #include "tty.h"
  8. /* Legacy tty mutex glue */
  9. /*
  10. * Getting the big tty mutex.
  11. */
  12. void tty_lock(struct tty_struct *tty)
  13. {
  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. tty_kref_get(tty);
  22. ret = mutex_lock_interruptible(&tty->legacy_mutex);
  23. if (ret)
  24. tty_kref_put(tty);
  25. return ret;
  26. }
  27. void tty_unlock(struct tty_struct *tty)
  28. {
  29. mutex_unlock(&tty->legacy_mutex);
  30. tty_kref_put(tty);
  31. }
  32. EXPORT_SYMBOL(tty_unlock);
  33. void tty_lock_slave(struct tty_struct *tty)
  34. {
  35. if (tty && tty != tty->link)
  36. tty_lock(tty);
  37. }
  38. void tty_unlock_slave(struct tty_struct *tty)
  39. {
  40. if (tty && tty != tty->link)
  41. tty_unlock(tty);
  42. }
  43. void tty_set_lock_subclass(struct tty_struct *tty)
  44. {
  45. lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
  46. }