aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2012-03-05 08:52:01 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-03-08 14:42:21 -0500
commit410235fd4d20b8feaf8930a0575d23acc088aa87 (patch)
treead21d071a29ef0ad400393328ca4ab0588d5b2b7 /drivers
parent44a1bfd95d0a6c0096e79a883197596e1ce83cc3 (diff)
TTY: remove unneeded tty->index checks
Checking if tty->index is in bounds is not needed. The tty has the index set in the initial open. This is done in get_tty_driver. And it can be only in interval <0,driver->num). So remove the tests which check exactly this interval. Some are left untouched as they check against the current backing device count. (Leaving apart that the check is racy in most of the cases.) Signed-off-by: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/pcmcia/synclink_cs.c2
-rw-r--r--drivers/isdn/capi/capi.c3
-rw-r--r--drivers/isdn/gigaset/common.c2
-rw-r--r--drivers/isdn/i4l/isdn_tty.c7
-rw-r--r--drivers/s390/char/con3215.c8
-rw-r--r--drivers/tty/amiserial.c10
-rw-r--r--drivers/tty/cyclades.c6
-rw-r--r--drivers/tty/hvc/hvcs.c24
-rw-r--r--drivers/tty/hvc/hvsi.c5
-rw-r--r--drivers/tty/isicom.c2
-rw-r--r--drivers/tty/mxser.c2
-rw-r--r--drivers/tty/rocket.c6
-rw-r--r--drivers/tty/serial/68328serial.c9
-rw-r--r--drivers/tty/serial/crisv10.c15
-rw-r--r--drivers/tty/synclink.c2
-rw-r--r--drivers/tty/synclink_gt.c2
-rw-r--r--drivers/tty/synclinkmp.c2
-rw-r--r--drivers/usb/gadget/u_serial.c3
18 files changed, 32 insertions, 78 deletions
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index c3bcb1221e6b..f6453df4921c 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -2484,7 +2484,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
2484 2484
2485 /* verify range of specified line number */ 2485 /* verify range of specified line number */
2486 line = tty->index; 2486 line = tty->index;
2487 if ((line < 0) || (line >= mgslpc_device_count)) { 2487 if (line >= mgslpc_device_count) {
2488 printk("%s(%d):mgslpc_open with invalid line #%d.\n", 2488 printk("%s(%d):mgslpc_open with invalid line #%d.\n",
2489 __FILE__,__LINE__,line); 2489 __FILE__,__LINE__,line);
2490 return -ENODEV; 2490 return -ENODEV;
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index baf08eba495c..3a7905b06e53 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1013,8 +1013,7 @@ static const struct file_operations capi_fops =
1013static int 1013static int
1014capinc_tty_install(struct tty_driver *driver, struct tty_struct *tty) 1014capinc_tty_install(struct tty_driver *driver, struct tty_struct *tty)
1015{ 1015{
1016 int idx = tty->index; 1016 struct capiminor *mp = capiminor_get(tty->index);
1017 struct capiminor *mp = capiminor_get(idx);
1018 int ret = tty_standard_install(driver, tty); 1017 int ret = tty_standard_install(driver, tty);
1019 1018
1020 if (ret == 0) 1019 if (ret == 0)
diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
index db621db67f61..ac0186e54bf4 100644
--- a/drivers/isdn/gigaset/common.c
+++ b/drivers/isdn/gigaset/common.c
@@ -1051,8 +1051,6 @@ static struct cardstate *gigaset_get_cs_by_minor(unsigned minor)
1051 1051
1052struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty) 1052struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty)
1053{ 1053{
1054 if (tty->index < 0 || tty->index >= tty->driver->num)
1055 return NULL;
1056 return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start); 1054 return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start);
1057} 1055}
1058 1056
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index 2c26b64ebbea..ac4840124bc0 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -1590,12 +1590,9 @@ static int
1590isdn_tty_open(struct tty_struct *tty, struct file *filp) 1590isdn_tty_open(struct tty_struct *tty, struct file *filp)
1591{ 1591{
1592 modem_info *info; 1592 modem_info *info;
1593 int retval, line; 1593 int retval;
1594 1594
1595 line = tty->index; 1595 info = &dev->mdm.info[tty->index];
1596 if (line < 0 || line >= ISDN_MAX_CHANNELS)
1597 return -ENODEV;
1598 info = &dev->mdm.info[line];
1599 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open")) 1596 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open"))
1600 return -ENODEV; 1597 return -ENODEV;
1601 if (!try_module_get(info->owner)) { 1598 if (!try_module_get(info->owner)) {
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index fe916bfd60f2..ed23fec7abbe 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -926,13 +926,9 @@ console_initcall(con3215_init);
926static int tty3215_open(struct tty_struct *tty, struct file * filp) 926static int tty3215_open(struct tty_struct *tty, struct file * filp)
927{ 927{
928 struct raw3215_info *raw; 928 struct raw3215_info *raw;
929 int retval, line; 929 int retval;
930 930
931 line = tty->index; 931 raw = raw3215[tty->index];
932 if ((line < 0) || (line >= NR_3215))
933 return -ENODEV;
934
935 raw = raw3215[line];
936 if (raw == NULL) 932 if (raw == NULL)
937 return -ENODEV; 933 return -ENODEV;
938 934
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index b42f00d987ae..753286257554 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -1768,13 +1768,9 @@ static int get_async_struct(int line, struct async_struct **ret_info)
1768static int rs_open(struct tty_struct *tty, struct file * filp) 1768static int rs_open(struct tty_struct *tty, struct file * filp)
1769{ 1769{
1770 struct async_struct *info; 1770 struct async_struct *info;
1771 int retval, line; 1771 int retval;
1772 1772
1773 line = tty->index; 1773 retval = get_async_struct(tty->index, &info);
1774 if ((line < 0) || (line >= NR_PORTS)) {
1775 return -ENODEV;
1776 }
1777 retval = get_async_struct(line, &info);
1778 if (retval) { 1774 if (retval) {
1779 return retval; 1775 return retval;
1780 } 1776 }
@@ -1964,7 +1960,7 @@ static int __init amiga_serial_probe(struct platform_device *pdev)
1964 struct serial_state * state; 1960 struct serial_state * state;
1965 int error; 1961 int error;
1966 1962
1967 serial_driver = alloc_tty_driver(1); 1963 serial_driver = alloc_tty_driver(NR_PORTS);
1968 if (!serial_driver) 1964 if (!serial_driver)
1969 return -ENOMEM; 1965 return -ENOMEM;
1970 1966
diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
index bc7b5a5650ba..e61cabdd69df 100644
--- a/drivers/tty/cyclades.c
+++ b/drivers/tty/cyclades.c
@@ -1515,13 +1515,9 @@ static void cy_shutdown(struct cyclades_port *info, struct tty_struct *tty)
1515static int cy_open(struct tty_struct *tty, struct file *filp) 1515static int cy_open(struct tty_struct *tty, struct file *filp)
1516{ 1516{
1517 struct cyclades_port *info; 1517 struct cyclades_port *info;
1518 unsigned int i, line; 1518 unsigned int i, line = tty->index;
1519 int retval; 1519 int retval;
1520 1520
1521 line = tty->index;
1522 if (tty->index < 0 || NR_PORTS <= line)
1523 return -ENODEV;
1524
1525 for (i = 0; i < NR_CARDS; i++) 1521 for (i = 0; i < NR_CARDS; i++)
1526 if (line < cy_card[i].first_line + cy_card[i].nports && 1522 if (line < cy_card[i].first_line + cy_card[i].nports &&
1527 line >= cy_card[i].first_line) 1523 line >= cy_card[i].first_line)
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index da0aa476804d..d23759183b47 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -1090,27 +1090,23 @@ static int hvcs_enable_device(struct hvcs_struct *hvcsd, uint32_t unit_address,
1090 */ 1090 */
1091static struct hvcs_struct *hvcs_get_by_index(int index) 1091static struct hvcs_struct *hvcs_get_by_index(int index)
1092{ 1092{
1093 struct hvcs_struct *hvcsd = NULL; 1093 struct hvcs_struct *hvcsd;
1094 unsigned long flags; 1094 unsigned long flags;
1095 1095
1096 spin_lock(&hvcs_structs_lock); 1096 spin_lock(&hvcs_structs_lock);
1097 /* We can immediately discard OOB requests */ 1097 list_for_each_entry(hvcsd, &hvcs_structs, next) {
1098 if (index >= 0 && index < HVCS_MAX_SERVER_ADAPTERS) { 1098 spin_lock_irqsave(&hvcsd->lock, flags);
1099 list_for_each_entry(hvcsd, &hvcs_structs, next) { 1099 if (hvcsd->index == index) {
1100 spin_lock_irqsave(&hvcsd->lock, flags); 1100 kref_get(&hvcsd->kref);
1101 if (hvcsd->index == index) {
1102 kref_get(&hvcsd->kref);
1103 spin_unlock_irqrestore(&hvcsd->lock, flags);
1104 spin_unlock(&hvcs_structs_lock);
1105 return hvcsd;
1106 }
1107 spin_unlock_irqrestore(&hvcsd->lock, flags); 1101 spin_unlock_irqrestore(&hvcsd->lock, flags);
1102 spin_unlock(&hvcs_structs_lock);
1103 return hvcsd;
1108 } 1104 }
1109 hvcsd = NULL; 1105 spin_unlock_irqrestore(&hvcsd->lock, flags);
1110 } 1106 }
1111
1112 spin_unlock(&hvcs_structs_lock); 1107 spin_unlock(&hvcs_structs_lock);
1113 return hvcsd; 1108
1109 return NULL;
1114} 1110}
1115 1111
1116/* 1112/*
diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
index 60bc45164189..a7488b748647 100644
--- a/drivers/tty/hvc/hvsi.c
+++ b/drivers/tty/hvc/hvsi.c
@@ -737,14 +737,11 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
737{ 737{
738 struct hvsi_struct *hp; 738 struct hvsi_struct *hp;
739 unsigned long flags; 739 unsigned long flags;
740 int line = tty->index;
741 int ret; 740 int ret;
742 741
743 pr_debug("%s\n", __func__); 742 pr_debug("%s\n", __func__);
744 743
745 if (line < 0 || line >= hvsi_count) 744 hp = &hvsi_ports[tty->index];
746 return -ENODEV;
747 hp = &hvsi_ports[line];
748 745
749 tty->driver_data = hp; 746 tty->driver_data = hp;
750 747
diff --git a/drivers/tty/isicom.c b/drivers/tty/isicom.c
index b3a28b5f02ad..03c14979accf 100644
--- a/drivers/tty/isicom.c
+++ b/drivers/tty/isicom.c
@@ -849,8 +849,6 @@ static struct tty_port *isicom_find_port(struct tty_struct *tty)
849 unsigned int board; 849 unsigned int board;
850 int line = tty->index; 850 int line = tty->index;
851 851
852 if (line < 0 || line > PORT_COUNT-1)
853 return NULL;
854 board = BOARD(line); 852 board = BOARD(line);
855 card = &isi_card[board]; 853 card = &isi_card[board];
856 854
diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index 260d03123524..17ff377e4129 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -1010,8 +1010,6 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
1010 line = tty->index; 1010 line = tty->index;
1011 if (line == MXSER_PORTS) 1011 if (line == MXSER_PORTS)
1012 return 0; 1012 return 0;
1013 if (line < 0 || line > MXSER_PORTS)
1014 return -ENODEV;
1015 info = &mxser_boards[line / MXSER_PORTS_PER_BOARD].ports[line % MXSER_PORTS_PER_BOARD]; 1013 info = &mxser_boards[line / MXSER_PORTS_PER_BOARD].ports[line % MXSER_PORTS_PER_BOARD];
1016 if (!info->ioaddr) 1014 if (!info->ioaddr)
1017 return -ENODEV; 1015 return -ENODEV;
diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
index b088e1ea4331..777d5f9cf6cc 100644
--- a/drivers/tty/rocket.c
+++ b/drivers/tty/rocket.c
@@ -892,12 +892,12 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
892{ 892{
893 struct r_port *info; 893 struct r_port *info;
894 struct tty_port *port; 894 struct tty_port *port;
895 int line = 0, retval; 895 int retval;
896 CHANNEL_t *cp; 896 CHANNEL_t *cp;
897 unsigned long page; 897 unsigned long page;
898 898
899 line = tty->index; 899 info = rp_table[tty->index];
900 if (line < 0 || line >= MAX_RP_PORTS || ((info = rp_table[line]) == NULL)) 900 if (info == NULL)
901 return -ENXIO; 901 return -ENXIO;
902 port = &info->port; 902 port = &info->port;
903 903
diff --git a/drivers/tty/serial/68328serial.c b/drivers/tty/serial/68328serial.c
index a88ef9782a4f..7398390e7e65 100644
--- a/drivers/tty/serial/68328serial.c
+++ b/drivers/tty/serial/68328serial.c
@@ -1190,14 +1190,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
1190int rs_open(struct tty_struct *tty, struct file * filp) 1190int rs_open(struct tty_struct *tty, struct file * filp)
1191{ 1191{
1192 struct m68k_serial *info; 1192 struct m68k_serial *info;
1193 int retval, line; 1193 int retval;
1194
1195 line = tty->index;
1196
1197 if (line >= NR_PORTS || line < 0) /* we have exactly one */
1198 return -ENODEV;
1199 1194
1200 info = &m68k_soft[line]; 1195 info = &m68k_soft[tty->index];
1201 1196
1202 if (serial_paranoia_check(info, tty->name, "rs_open")) 1197 if (serial_paranoia_check(info, tty->name, "rs_open"))
1203 return -ENODEV; 1198 return -ENODEV;
diff --git a/drivers/tty/serial/crisv10.c b/drivers/tty/serial/crisv10.c
index 1dfba7b779c8..23d791696879 100644
--- a/drivers/tty/serial/crisv10.c
+++ b/drivers/tty/serial/crisv10.c
@@ -4105,20 +4105,11 @@ static int
4105rs_open(struct tty_struct *tty, struct file * filp) 4105rs_open(struct tty_struct *tty, struct file * filp)
4106{ 4106{
4107 struct e100_serial *info; 4107 struct e100_serial *info;
4108 int retval, line; 4108 int retval;
4109 unsigned long page; 4109 unsigned long page;
4110 int allocated_resources = 0; 4110 int allocated_resources = 0;
4111 4111
4112 /* find which port we want to open */ 4112 info = rs_table + tty->index;
4113 line = tty->index;
4114
4115 if (line < 0 || line >= NR_PORTS)
4116 return -ENODEV;
4117
4118 /* find the corresponding e100_serial struct in the table */
4119 info = rs_table + line;
4120
4121 /* don't allow the opening of ports that are not enabled in the HW config */
4122 if (!info->enabled) 4113 if (!info->enabled)
4123 return -ENODEV; 4114 return -ENODEV;
4124 4115
@@ -4131,7 +4122,7 @@ rs_open(struct tty_struct *tty, struct file * filp)
4131 tty->driver_data = info; 4122 tty->driver_data = info;
4132 info->port.tty = tty; 4123 info->port.tty = tty;
4133 4124
4134 info->port.tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 4125 tty->low_latency = !!(info->flags & ASYNC_LOW_LATENCY);
4135 4126
4136 if (!tmp_buf) { 4127 if (!tmp_buf) {
4137 page = get_zeroed_page(GFP_KERNEL); 4128 page = get_zeroed_page(GFP_KERNEL);
diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
index 2b2988c779c7..8e518da85fd5 100644
--- a/drivers/tty/synclink.c
+++ b/drivers/tty/synclink.c
@@ -3381,7 +3381,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
3381 3381
3382 /* verify range of specified line number */ 3382 /* verify range of specified line number */
3383 line = tty->index; 3383 line = tty->index;
3384 if ((line < 0) || (line >= mgsl_device_count)) { 3384 if (line >= mgsl_device_count) {
3385 printk("%s(%d):mgsl_open with invalid line #%d.\n", 3385 printk("%s(%d):mgsl_open with invalid line #%d.\n",
3386 __FILE__,__LINE__,line); 3386 __FILE__,__LINE__,line);
3387 return -ENODEV; 3387 return -ENODEV;
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
index a8b66be37e6e..6bee4907c6a5 100644
--- a/drivers/tty/synclink_gt.c
+++ b/drivers/tty/synclink_gt.c
@@ -654,7 +654,7 @@ static int open(struct tty_struct *tty, struct file *filp)
654 unsigned long flags; 654 unsigned long flags;
655 655
656 line = tty->index; 656 line = tty->index;
657 if ((line < 0) || (line >= slgt_device_count)) { 657 if (line >= slgt_device_count) {
658 DBGERR(("%s: open with invalid line #%d.\n", driver_name, line)); 658 DBGERR(("%s: open with invalid line #%d.\n", driver_name, line));
659 return -ENODEV; 659 return -ENODEV;
660 } 660 }
diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
index ddabb61c85ba..4fb6c4b31b79 100644
--- a/drivers/tty/synclinkmp.c
+++ b/drivers/tty/synclinkmp.c
@@ -721,7 +721,7 @@ static int open(struct tty_struct *tty, struct file *filp)
721 unsigned long flags; 721 unsigned long flags;
722 722
723 line = tty->index; 723 line = tty->index;
724 if ((line < 0) || (line >= synclinkmp_device_count)) { 724 if (line >= synclinkmp_device_count) {
725 printk("%s(%d): open with invalid line #%d.\n", 725 printk("%s(%d): open with invalid line #%d.\n",
726 __FILE__,__LINE__,line); 726 __FILE__,__LINE__,line);
727 return -ENODEV; 727 return -ENODEV;
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index 490b01dd5d60..6c23938d2711 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -725,9 +725,6 @@ static int gs_open(struct tty_struct *tty, struct file *file)
725 struct gs_port *port; 725 struct gs_port *port;
726 int status; 726 int status;
727 727
728 if (port_num < 0 || port_num >= n_ports)
729 return -ENXIO;
730
731 do { 728 do {
732 mutex_lock(&ports[port_num].lock); 729 mutex_lock(&ports[port_num].lock);
733 port = ports[port_num].port; 730 port = ports[port_num].port;