Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 122426
b: refs/heads/master
c: 9a5df92
h: refs/heads/master
v: v3
  • Loading branch information
Marcel Holtmann committed Nov 30, 2008
1 parent ae5404f commit 3874372
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2e792995e4cb425422dc379c3618447c462756a8
refs/heads/master: 9a5df92374d65e2886b92e98dd7d873c533a83ff
30 changes: 21 additions & 9 deletions trunk/net/bluetooth/rfcomm/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct rfcomm_dev {
char name[12];
int id;
unsigned long flags;
int opened;
atomic_t opened;
int err;

bdaddr_t src;
Expand Down Expand Up @@ -256,6 +256,8 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
dev->flags = req->flags &
((1 << RFCOMM_RELEASE_ONHUP) | (1 << RFCOMM_REUSE_DLC));

atomic_set(&dev->opened, 0);

init_waitqueue_head(&dev->wait);
tasklet_init(&dev->wakeup_task, rfcomm_tty_wakeup, (unsigned long) dev);

Expand Down Expand Up @@ -325,10 +327,10 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
{
BT_DBG("dev %p", dev);

if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags))
BUG_ON(1);
else
set_bit(RFCOMM_TTY_RELEASED, &dev->flags);
BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));

if (atomic_read(&dev->opened) > 0)
return;

write_lock_bh(&rfcomm_dev_lock);
list_del_init(&dev->list);
Expand Down Expand Up @@ -684,9 +686,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
if (!dev)
return -ENODEV;

BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst), dev->channel, dev->opened);
BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
dev->channel, atomic_read(&dev->opened));

if (dev->opened++ != 0)
if (atomic_inc_return(&dev->opened) > 1)
return 0;

dlc = dev->dlc;
Expand Down Expand Up @@ -742,9 +745,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
if (!dev)
return;

BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc, dev->opened);
BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
atomic_read(&dev->opened));

if (--dev->opened == 0) {
if (atomic_dec_and_test(&dev->opened)) {
if (dev->tty_dev->parent)
device_move(dev->tty_dev, NULL);

Expand All @@ -758,6 +762,14 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
tty->driver_data = NULL;
dev->tty = NULL;
rfcomm_dlc_unlock(dev->dlc);

if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) {
write_lock_bh(&rfcomm_dev_lock);
list_del_init(&dev->list);
write_unlock_bh(&rfcomm_dev_lock);

rfcomm_dev_put(dev);
}
}

rfcomm_dev_put(dev);
Expand Down

0 comments on commit 3874372

Please sign in to comment.