]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
TTY: remove unneeded tty->index checks
authorJiri Slaby <jslaby@suse.cz>
Mon, 5 Mar 2012 13:52:01 +0000 (14:52 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 8 Mar 2012 19:42:21 +0000 (11:42 -0800)
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>
21 files changed:
arch/ia64/hp/sim/simserial.c
arch/xtensa/platforms/iss/console.c
drivers/char/pcmcia/synclink_cs.c
drivers/isdn/capi/capi.c
drivers/isdn/gigaset/common.c
drivers/isdn/i4l/isdn_tty.c
drivers/s390/char/con3215.c
drivers/tty/amiserial.c
drivers/tty/cyclades.c
drivers/tty/hvc/hvcs.c
drivers/tty/hvc/hvsi.c
drivers/tty/isicom.c
drivers/tty/mxser.c
drivers/tty/rocket.c
drivers/tty/serial/68328serial.c
drivers/tty/serial/crisv10.c
drivers/tty/synclink.c
drivers/tty/synclink_gt.c
drivers/tty/synclinkmp.c
drivers/usb/gadget/u_serial.c
net/irda/ircomm/ircomm_tty.c

index f513dc02bb8799ad2b8ec4d85c75baf859238e97..2a2fe0c56119a086238edb96c57abe265e085bc6 100644 (file)
@@ -769,13 +769,10 @@ errout:
 static int rs_open(struct tty_struct *tty, struct file * filp)
 {
        struct async_struct     *info;
-       int                     retval, line;
+       int                     retval;
        unsigned long           page;
 
-       line = tty->index;
-       if ((line < 0) || (line >= NR_PORTS))
-               return -ENODEV;
-       retval = get_async_struct(line, &info);
+       retval = get_async_struct(tty->index, &info);
        if (retval)
                return retval;
        tty->driver_data = info;
@@ -920,7 +917,7 @@ simrs_init (void)
        if (!ia64_platform_is("hpsim"))
                return -ENODEV;
 
-       hp_simserial_driver = alloc_tty_driver(1);
+       hp_simserial_driver = alloc_tty_driver(NR_PORTS);
        if (!hp_simserial_driver)
                return -ENOMEM;
 
index 247e9d40a52e5800a281e7c74b26658ba807be75..19a802a13096e8e3c0fe290e1bdce59ce980dab0 100644 (file)
@@ -68,11 +68,6 @@ static void rs_poll(unsigned long);
 
 static int rs_open(struct tty_struct *tty, struct file * filp)
 {
-       int line = tty->index;
-
-       if ((line < 0) || (line >= SERIAL_MAX_NUM_LINES))
-               return -ENODEV;
-
        spin_lock(&timer_lock);
 
        if (tty->count == 1) {
@@ -101,6 +96,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
 {
        spin_lock(&timer_lock);
        if (tty->count == 1)
+               /* this will cause a deadlock if the timer ticks right now */
                del_timer_sync(&serial_timer);
        spin_unlock(&timer_lock);
 }
@@ -210,7 +206,7 @@ static const struct tty_operations serial_ops = {
 
 int __init rs_init(void)
 {
-       serial_driver = alloc_tty_driver(1);
+       serial_driver = alloc_tty_driver(SERIAL_MAX_NUM_LINES);
 
        printk ("%s %s\n", serial_name, serial_version);
 
index c3bcb1221e6b7aa4d1a93d8119ec1ebccf3987a7..f6453df4921cb253c34bf854e923b0fc8680f7a4 100644 (file)
@@ -2484,7 +2484,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
 
        /* verify range of specified line number */
        line = tty->index;
-       if ((line < 0) || (line >= mgslpc_device_count)) {
+       if (line >= mgslpc_device_count) {
                printk("%s(%d):mgslpc_open with invalid line #%d.\n",
                        __FILE__,__LINE__,line);
                return -ENODEV;
index baf08eba495cc9f6178a78c4c730a7d986a6cc11..3a7905b06e53a4a52e070af238d2359118e1f355 100644 (file)
@@ -1013,8 +1013,7 @@ static const struct file_operations capi_fops =
 static int
 capinc_tty_install(struct tty_driver *driver, struct tty_struct *tty)
 {
-       int idx = tty->index;
-       struct capiminor *mp = capiminor_get(idx);
+       struct capiminor *mp = capiminor_get(tty->index);
        int ret = tty_standard_install(driver, tty);
 
        if (ret == 0)
index db621db67f61935d593e65b5f5a34dd81acded15..ac0186e54bf4db8635e278f7b734296cf5cc16b5 100644 (file)
@@ -1051,8 +1051,6 @@ static struct cardstate *gigaset_get_cs_by_minor(unsigned minor)
 
 struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty)
 {
-       if (tty->index < 0 || tty->index >= tty->driver->num)
-               return NULL;
        return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start);
 }
 
index 2c26b64ebbea4de6cc0203d35da649c4d41d5bc1..ac4840124bc0d869db9159d3c38efddca5f04b70 100644 (file)
@@ -1590,12 +1590,9 @@ static int
 isdn_tty_open(struct tty_struct *tty, struct file *filp)
 {
        modem_info *info;
-       int retval, line;
+       int retval;
 
-       line = tty->index;
-       if (line < 0 || line >= ISDN_MAX_CHANNELS)
-               return -ENODEV;
-       info = &dev->mdm.info[line];
+       info = &dev->mdm.info[tty->index];
        if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open"))
                return -ENODEV;
        if (!try_module_get(info->owner)) {
index fe916bfd60f288ed4a9be616b26183e4a082486c..ed23fec7abbed11b051b91a968c6e63defda2269 100644 (file)
@@ -926,13 +926,9 @@ console_initcall(con3215_init);
 static int tty3215_open(struct tty_struct *tty, struct file * filp)
 {
        struct raw3215_info *raw;
-       int retval, line;
+       int retval;
 
-       line = tty->index;
-       if ((line < 0) || (line >= NR_3215))
-               return -ENODEV;
-
-       raw = raw3215[line];
+       raw = raw3215[tty->index];
        if (raw == NULL)
                return -ENODEV;
 
index b42f00d987ae408c75a291af4e6be16eff8a1820..753286257554e4815e2dc8032c33436047542408 100644 (file)
@@ -1768,13 +1768,9 @@ static int get_async_struct(int line, struct async_struct **ret_info)
 static int rs_open(struct tty_struct *tty, struct file * filp)
 {
        struct async_struct     *info;
-       int                     retval, line;
+       int retval;
 
-       line = tty->index;
-       if ((line < 0) || (line >= NR_PORTS)) {
-               return -ENODEV;
-       }
-       retval = get_async_struct(line, &info);
+       retval = get_async_struct(tty->index, &info);
        if (retval) {
                return retval;
        }
@@ -1964,7 +1960,7 @@ static int __init amiga_serial_probe(struct platform_device *pdev)
        struct serial_state * state;
        int error;
 
-       serial_driver = alloc_tty_driver(1);
+       serial_driver = alloc_tty_driver(NR_PORTS);
        if (!serial_driver)
                return -ENOMEM;
 
index bc7b5a5650ba11c067c3a45267babb1ebcf86b81..e61cabdd69df36d56ea0c0cd27fcaeadc488f8de 100644 (file)
@@ -1515,13 +1515,9 @@ static void cy_shutdown(struct cyclades_port *info, struct tty_struct *tty)
 static int cy_open(struct tty_struct *tty, struct file *filp)
 {
        struct cyclades_port *info;
-       unsigned int i, line;
+       unsigned int i, line = tty->index;
        int retval;
 
-       line = tty->index;
-       if (tty->index < 0 || NR_PORTS <= line)
-               return -ENODEV;
-
        for (i = 0; i < NR_CARDS; i++)
                if (line < cy_card[i].first_line + cy_card[i].nports &&
                                line >= cy_card[i].first_line)
index da0aa476804d204d8b1b73e4bc9409a64ef4431c..d23759183b4782485f03db20de7fa57279a41ca7 100644 (file)
@@ -1090,27 +1090,23 @@ static int hvcs_enable_device(struct hvcs_struct *hvcsd, uint32_t unit_address,
  */
 static struct hvcs_struct *hvcs_get_by_index(int index)
 {
-       struct hvcs_struct *hvcsd = NULL;
+       struct hvcs_struct *hvcsd;
        unsigned long flags;
 
        spin_lock(&hvcs_structs_lock);
-       /* We can immediately discard OOB requests */
-       if (index >= 0 && index < HVCS_MAX_SERVER_ADAPTERS) {
-               list_for_each_entry(hvcsd, &hvcs_structs, next) {
-                       spin_lock_irqsave(&hvcsd->lock, flags);
-                       if (hvcsd->index == index) {
-                               kref_get(&hvcsd->kref);
-                               spin_unlock_irqrestore(&hvcsd->lock, flags);
-                               spin_unlock(&hvcs_structs_lock);
-                               return hvcsd;
-                       }
+       list_for_each_entry(hvcsd, &hvcs_structs, next) {
+               spin_lock_irqsave(&hvcsd->lock, flags);
+               if (hvcsd->index == index) {
+                       kref_get(&hvcsd->kref);
                        spin_unlock_irqrestore(&hvcsd->lock, flags);
+                       spin_unlock(&hvcs_structs_lock);
+                       return hvcsd;
                }
-               hvcsd = NULL;
+               spin_unlock_irqrestore(&hvcsd->lock, flags);
        }
-
        spin_unlock(&hvcs_structs_lock);
-       return hvcsd;
+
+       return NULL;
 }
 
 /*
index 60bc451641890043c872d89aa76ef132eab1abc5..a7488b7486473c8139d8baae1874ac86bf7979ae 100644 (file)
@@ -737,14 +737,11 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
 {
        struct hvsi_struct *hp;
        unsigned long flags;
-       int line = tty->index;
        int ret;
 
        pr_debug("%s\n", __func__);
 
-       if (line < 0 || line >= hvsi_count)
-               return -ENODEV;
-       hp = &hvsi_ports[line];
+       hp = &hvsi_ports[tty->index];
 
        tty->driver_data = hp;
 
index b3a28b5f02adcb266c4e5c50d048f1c4f253324c..03c14979accf49f68103c00df3763a28a4598eda 100644 (file)
@@ -849,8 +849,6 @@ static struct tty_port *isicom_find_port(struct tty_struct *tty)
        unsigned int board;
        int line = tty->index;
 
-       if (line < 0 || line > PORT_COUNT-1)
-               return NULL;
        board = BOARD(line);
        card = &isi_card[board];
 
index 260d031235247dd07f6bdd8793dc726d08528638..17ff377e41292899dc9c8eac0f7a2941a377d616 100644 (file)
@@ -1010,8 +1010,6 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
        line = tty->index;
        if (line == MXSER_PORTS)
                return 0;
-       if (line < 0 || line > MXSER_PORTS)
-               return -ENODEV;
        info = &mxser_boards[line / MXSER_PORTS_PER_BOARD].ports[line % MXSER_PORTS_PER_BOARD];
        if (!info->ioaddr)
                return -ENODEV;
index b088e1ea43311fcc8a53121feeeecd55cb0b5af8..777d5f9cf6cc13e4d91c3ec175621aa4c16d2456 100644 (file)
@@ -892,12 +892,12 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
 {
        struct r_port *info;
        struct tty_port *port;
-       int line = 0, retval;
+       int retval;
        CHANNEL_t *cp;
        unsigned long page;
 
-       line = tty->index;
-       if (line < 0 || line >= MAX_RP_PORTS || ((info = rp_table[line]) == NULL))
+       info = rp_table[tty->index];
+       if (info == NULL)
                return -ENXIO;
        port = &info->port;
        
index a88ef9782a4fbb7163c63ccc787add5ed5c8efa6..7398390e7e65111b0658a52e1559045651e42363 100644 (file)
@@ -1190,14 +1190,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
 int rs_open(struct tty_struct *tty, struct file * filp)
 {
        struct m68k_serial      *info;
-       int                     retval, line;
-
-       line = tty->index;
-       
-       if (line >= NR_PORTS || line < 0) /* we have exactly one */
-               return -ENODEV;
+       int retval;
 
-       info = &m68k_soft[line];
+       info = &m68k_soft[tty->index];
 
        if (serial_paranoia_check(info, tty->name, "rs_open"))
                return -ENODEV;
index 1dfba7b779c84ed1f151b490295b0a99751b7b72..23d7916968793652e61a050531d2bae00bcecfd5 100644 (file)
@@ -4105,20 +4105,11 @@ static int
 rs_open(struct tty_struct *tty, struct file * filp)
 {
        struct e100_serial      *info;
-       int                     retval, line;
+       int                     retval;
        unsigned long           page;
        int                     allocated_resources = 0;
 
-       /* find which port we want to open */
-       line = tty->index;
-
-       if (line < 0 || line >= NR_PORTS)
-               return -ENODEV;
-
-       /* find the corresponding e100_serial struct in the table */
-       info = rs_table + line;
-
-       /* don't allow the opening of ports that are not enabled in the HW config */
+       info = rs_table + tty->index;
        if (!info->enabled)
                return -ENODEV;
 
@@ -4131,7 +4122,7 @@ rs_open(struct tty_struct *tty, struct file * filp)
        tty->driver_data = info;
        info->port.tty = tty;
 
-       info->port.tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
+       tty->low_latency = !!(info->flags & ASYNC_LOW_LATENCY);
 
        if (!tmp_buf) {
                page = get_zeroed_page(GFP_KERNEL);
index 2b2988c779c74d6c1b76eca2312c712005378e12..8e518da85fd55749a5160de4640e9449568addbb 100644 (file)
@@ -3381,7 +3381,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
 
        /* verify range of specified line number */     
        line = tty->index;
-       if ((line < 0) || (line >= mgsl_device_count)) {
+       if (line >= mgsl_device_count) {
                printk("%s(%d):mgsl_open with invalid line #%d.\n",
                        __FILE__,__LINE__,line);
                return -ENODEV;
index a8b66be37e6e52b8aec9f855992f1140c8c1ca4a..6bee4907c6a50295a2b604360e3df53b447a9568 100644 (file)
@@ -654,7 +654,7 @@ static int open(struct tty_struct *tty, struct file *filp)
        unsigned long flags;
 
        line = tty->index;
-       if ((line < 0) || (line >= slgt_device_count)) {
+       if (line >= slgt_device_count) {
                DBGERR(("%s: open with invalid line #%d.\n", driver_name, line));
                return -ENODEV;
        }
index ddabb61c85ba0173ad8466e189115d5499d9837b..4fb6c4b31b79a307638545c2b28d8dc1992f3478 100644 (file)
@@ -721,7 +721,7 @@ static int open(struct tty_struct *tty, struct file *filp)
        unsigned long flags;
 
        line = tty->index;
-       if ((line < 0) || (line >= synclinkmp_device_count)) {
+       if (line >= synclinkmp_device_count) {
                printk("%s(%d): open with invalid line #%d.\n",
                        __FILE__,__LINE__,line);
                return -ENODEV;
index 490b01dd5d6093dcee11eb03ce587bb494cc6ded..6c23938d2711aee943637b1d20db1cd385d05d41 100644 (file)
@@ -725,9 +725,6 @@ static int gs_open(struct tty_struct *tty, struct file *file)
        struct gs_port  *port;
        int             status;
 
-       if (port_num < 0 || port_num >= n_ports)
-               return -ENXIO;
-
        do {
                mutex_lock(&ports[port_num].lock);
                port = ports[port_num].port;
index 828f88603d6cac0eb37f9cac313106d16fd8047b..6b9d5a0e42f9fb3753e32c0b167e202657b372b3 100644 (file)
@@ -365,16 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
 static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
 {
        struct ircomm_tty_cb *self;
-       unsigned int line;
+       unsigned int line = tty->index;
        unsigned long   flags;
        int ret;
 
        IRDA_DEBUG(2, "%s()\n", __func__ );
 
-       line = tty->index;
-       if (line >= IRCOMM_TTY_PORTS)
-               return -ENODEV;
-
        /* Check if instance already exists */
        self = hashbin_lock_find(ircomm_tty, line, NULL);
        if (!self) {