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:
static int rs_open(struct tty_struct *tty, struct file * filp)
{
struct async_struct *info;
static int rs_open(struct tty_struct *tty, struct file * filp)
{
struct async_struct *info;
- 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;
if (retval)
return retval;
tty->driver_data = info;
if (!ia64_platform_is("hpsim"))
return -ENODEV;
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;
if (!hp_simserial_driver)
return -ENOMEM;
static int rs_open(struct tty_struct *tty, struct file * filp)
{
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) {
spin_lock(&timer_lock);
if (tty->count == 1) {
{
spin_lock(&timer_lock);
if (tty->count == 1)
{
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);
}
del_timer_sync(&serial_timer);
spin_unlock(&timer_lock);
}
int __init rs_init(void)
{
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);
printk ("%s %s\n", serial_name, serial_version);
/* verify range of specified line number */
line = tty->index;
/* 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;
printk("%s(%d):mgslpc_open with invalid line #%d.\n",
__FILE__,__LINE__,line);
return -ENODEV;
static int
capinc_tty_install(struct tty_driver *driver, struct tty_struct *tty)
{
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)
int ret = tty_standard_install(driver, tty);
if (ret == 0)
struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty)
{
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);
}
return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start);
}
isdn_tty_open(struct tty_struct *tty, struct file *filp)
{
modem_info *info;
isdn_tty_open(struct tty_struct *tty, struct file *filp)
{
modem_info *info;
- 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)) {
if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open"))
return -ENODEV;
if (!try_module_get(info->owner)) {
static int tty3215_open(struct tty_struct *tty, struct file * filp)
{
struct raw3215_info *raw;
static int tty3215_open(struct tty_struct *tty, struct file * filp)
{
struct raw3215_info *raw;
- line = tty->index;
- if ((line < 0) || (line >= NR_3215))
- return -ENODEV;
-
- raw = raw3215[line];
+ raw = raw3215[tty->index];
if (raw == NULL)
return -ENODEV;
if (raw == NULL)
return -ENODEV;
static int rs_open(struct tty_struct *tty, struct file * filp)
{
struct async_struct *info;
static int rs_open(struct tty_struct *tty, struct file * filp)
{
struct async_struct *info;
- 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;
}
if (retval) {
return retval;
}
struct serial_state * state;
int error;
struct serial_state * state;
int error;
- serial_driver = alloc_tty_driver(1);
+ serial_driver = alloc_tty_driver(NR_PORTS);
if (!serial_driver)
return -ENOMEM;
if (!serial_driver)
return -ENOMEM;
static int cy_open(struct tty_struct *tty, struct file *filp)
{
struct cyclades_port *info;
static int cy_open(struct tty_struct *tty, struct file *filp)
{
struct cyclades_port *info;
+ unsigned int i, line = tty->index;
- 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)
for (i = 0; i < NR_CARDS; i++)
if (line < cy_card[i].first_line + cy_card[i].nports &&
line >= cy_card[i].first_line)
*/
static struct hvcs_struct *hvcs_get_by_index(int index)
{
*/
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);
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_irqrestore(&hvcsd->lock, flags);
+ spin_unlock(&hvcs_structs_lock);
+ return hvcsd;
+ spin_unlock_irqrestore(&hvcsd->lock, flags);
spin_unlock(&hvcs_structs_lock);
spin_unlock(&hvcs_structs_lock);
{
struct hvsi_struct *hp;
unsigned long flags;
{
struct hvsi_struct *hp;
unsigned long flags;
int ret;
pr_debug("%s\n", __func__);
int ret;
pr_debug("%s\n", __func__);
- if (line < 0 || line >= hvsi_count)
- return -ENODEV;
- hp = &hvsi_ports[line];
+ hp = &hvsi_ports[tty->index];
unsigned int board;
int line = tty->index;
unsigned int board;
int line = tty->index;
- if (line < 0 || line > PORT_COUNT-1)
- return NULL;
board = BOARD(line);
card = &isi_card[board];
board = BOARD(line);
card = &isi_card[board];
line = tty->index;
if (line == MXSER_PORTS)
return 0;
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;
info = &mxser_boards[line / MXSER_PORTS_PER_BOARD].ports[line % MXSER_PORTS_PER_BOARD];
if (!info->ioaddr)
return -ENODEV;
{
struct r_port *info;
struct tty_port *port;
{
struct r_port *info;
struct tty_port *port;
CHANNEL_t *cp;
unsigned long page;
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;
return -ENXIO;
port = &info->port;
int rs_open(struct tty_struct *tty, struct file * filp)
{
struct m68k_serial *info;
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;
- info = &m68k_soft[line];
+ info = &m68k_soft[tty->index];
if (serial_paranoia_check(info, tty->name, "rs_open"))
return -ENODEV;
if (serial_paranoia_check(info, tty->name, "rs_open"))
return -ENODEV;
rs_open(struct tty_struct *tty, struct file * filp)
{
struct e100_serial *info;
rs_open(struct tty_struct *tty, struct file * filp)
{
struct e100_serial *info;
unsigned long page;
int allocated_resources = 0;
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;
if (!info->enabled)
return -ENODEV;
tty->driver_data = info;
info->port.tty = tty;
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);
if (!tmp_buf) {
page = get_zeroed_page(GFP_KERNEL);
/* verify range of specified line number */
line = tty->index;
/* 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;
printk("%s(%d):mgsl_open with invalid line #%d.\n",
__FILE__,__LINE__,line);
return -ENODEV;
unsigned long flags;
line = tty->index;
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;
}
DBGERR(("%s: open with invalid line #%d.\n", driver_name, line));
return -ENODEV;
}
unsigned long flags;
line = tty->index;
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;
printk("%s(%d): open with invalid line #%d.\n",
__FILE__,__LINE__,line);
return -ENODEV;
struct gs_port *port;
int status;
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;
do {
mutex_lock(&ports[port_num].lock);
port = ports[port_num].port;
static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
{
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 = tty->index;
unsigned long flags;
int ret;
IRDA_DEBUG(2, "%s()\n", __func__ );
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) {
/* Check if instance already exists */
self = hashbin_lock_find(ircomm_tty, line, NULL);
if (!self) {