hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/tty/tty_io.c
....@@ -108,6 +108,7 @@
108108
109109 #include <linux/kmod.h>
110110 #include <linux/nsproxy.h>
111
+#include "tty.h"
111112
112113 #undef TTY_DEBUG_HANGUP
113114 #ifdef TTY_DEBUG_HANGUP
....@@ -941,13 +942,13 @@
941942 return i;
942943 }
943944
944
-static void tty_write_unlock(struct tty_struct *tty)
945
+void tty_write_unlock(struct tty_struct *tty)
945946 {
946947 mutex_unlock(&tty->atomic_write_lock);
947948 wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT);
948949 }
949950
950
-static int tty_write_lock(struct tty_struct *tty, int ndelay)
951
+int tty_write_lock(struct tty_struct *tty, int ndelay)
951952 {
952953 if (!mutex_trylock(&tty->atomic_write_lock)) {
953954 if (ndelay)
....@@ -1237,14 +1238,16 @@
12371238 {
12381239 struct tty_struct *tty;
12391240
1240
- if (driver->ops->lookup)
1241
+ if (driver->ops->lookup) {
12411242 if (!file)
12421243 tty = ERR_PTR(-EIO);
12431244 else
12441245 tty = driver->ops->lookup(driver, file, idx);
1245
- else
1246
+ } else {
1247
+ if (idx >= driver->num)
1248
+ return ERR_PTR(-EINVAL);
12461249 tty = driver->ttys[idx];
1247
-
1250
+ }
12481251 if (!IS_ERR(tty))
12491252 tty_kref_get(tty);
12501253 return tty;