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 <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
This commit is contained in:
Jiri Slaby 2012-03-05 14:52:01 +01:00 • committed by Greg Kroah-Hartman
commit 410235fd4d
21 changed files with 38 additions and 95 deletions

View 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;

View 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)

View 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;
}
/*

View 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;

View 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];

View 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;

View 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;

View 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;
int retval;
line = tty->index;
if (line >= NR_PORTS || line < 0) /* we have exactly one */
return -ENODEV;
info = &m68k_soft[line];
info = &m68k_soft[tty->index];
if (serial_paranoia_check(info, tty->name, "rs_open"))
return -ENODEV;

View 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);

View 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;

View 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;
}

View 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;