Skip to content

Commit a4ed2e7

Browse files
peterhurleydavem330
authored andcommitted
net/irda: Fix port open counts
Saving the port count bump is unsafe. If the tty is hung up while this open was blocking, the port count is zeroed. Explicitly check if the tty was hung up while blocking, and correct the port count if not. Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0305d06 commit a4ed2e7

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

‎net/irda/ircomm/ircomm_tty.c‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
280280
struct tty_port *port = &self->port;
281281
DECLARE_WAITQUEUE(wait, current);
282282
int retval;
283-
int do_clocal = 0, extra_count = 0;
283+
int do_clocal = 0;
284284
unsigned long flags;
285285

286286
IRDA_DEBUG(2, "%s()\n", __func__ );
@@ -315,10 +315,8 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
315315
__FILE__, __LINE__, tty->driver->name, port->count);
316316

317317
spin_lock_irqsave(&port->lock, flags);
318-
if (!tty_hung_up_p(filp)) {
319-
extra_count = 1;
318+
if (!tty_hung_up_p(filp))
320319
port->count--;
321-
}
322320
spin_unlock_irqrestore(&port->lock, flags);
323321
port->blocked_open++;
324322

@@ -361,12 +359,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
361359
__set_current_state(TASK_RUNNING);
362360
remove_wait_queue(&port->open_wait, &wait);
363361

364-
if (extra_count) {
365-
/* ++ is not atomic, so this should be protected - Jean II */
366-
spin_lock_irqsave(&port->lock, flags);
362+
spin_lock_irqsave(&port->lock, flags);
363+
if (!tty_hung_up_p(filp))
367364
port->count++;
368-
spin_unlock_irqrestore(&port->lock, flags);
369-
}
365+
spin_unlock_irqrestore(&port->lock, flags);
370366
port->blocked_open--;
371367

372368
IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",

0 commit comments

Comments
 (0)