aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/rfcomm
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2012-04-02 07:54:53 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-04-09 15:04:31 -0400
commitf997a01e3272f08cbbf77392b846878332dafc22 (patch)
tree06f2508290e7b2a0117a26af459483a7aa6823ee /net/bluetooth/rfcomm
parentb2c4be398bf771a09f84eae6cf12cbd685384b8d (diff)
TTY: rfcomm/tty, use count from tty_port
This means converting an atomic counter to a counter protected by lock. This is the first step needed to convert the rest of the code to the tty_port helpers. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'net/bluetooth/rfcomm')
-rw-r--r--net/bluetooth/rfcomm/tty.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index 0433d263233..d1820ff14ae 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -54,7 +54,6 @@ struct rfcomm_dev {
54 char name[12]; 54 char name[12];
55 int id; 55 int id;
56 unsigned long flags; 56 unsigned long flags;
57 atomic_t opened;
58 int err; 57 int err;
59 58
60 bdaddr_t src; 59 bdaddr_t src;
@@ -240,8 +239,6 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
240 dev->flags = req->flags & 239 dev->flags = req->flags &
241 ((1 << RFCOMM_RELEASE_ONHUP) | (1 << RFCOMM_REUSE_DLC)); 240 ((1 << RFCOMM_RELEASE_ONHUP) | (1 << RFCOMM_REUSE_DLC));
242 241
243 atomic_set(&dev->opened, 0);
244
245 tty_port_init(&dev->port); 242 tty_port_init(&dev->port);
246 dev->port.ops = &rfcomm_port_ops; 243 dev->port.ops = &rfcomm_port_ops;
247 init_waitqueue_head(&dev->wait); 244 init_waitqueue_head(&dev->wait);
@@ -311,12 +308,17 @@ free:
311 308
312static void rfcomm_dev_del(struct rfcomm_dev *dev) 309static void rfcomm_dev_del(struct rfcomm_dev *dev)
313{ 310{
311 unsigned long flags;
314 BT_DBG("dev %p", dev); 312 BT_DBG("dev %p", dev);
315 313
316 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags)); 314 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
317 315
318 if (atomic_read(&dev->opened) > 0) 316 spin_lock_irqsave(&dev->port.lock, flags);
317 if (dev->port.count > 0) {
318 spin_unlock_irqrestore(&dev->port.lock, flags);
319 return; 319 return;
320 }
321 spin_unlock_irqrestore(&dev->port.lock, flags);
320 322
321 spin_lock(&rfcomm_dev_lock); 323 spin_lock(&rfcomm_dev_lock);
322 list_del_init(&dev->list); 324 list_del_init(&dev->list);
@@ -651,6 +653,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
651 DECLARE_WAITQUEUE(wait, current); 653 DECLARE_WAITQUEUE(wait, current);
652 struct rfcomm_dev *dev; 654 struct rfcomm_dev *dev;
653 struct rfcomm_dlc *dlc; 655 struct rfcomm_dlc *dlc;
656 unsigned long flags;
654 int err, id; 657 int err, id;
655 658
656 id = tty->index; 659 id = tty->index;
@@ -666,10 +669,14 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
666 return -ENODEV; 669 return -ENODEV;
667 670
668 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst), 671 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
669 dev->channel, atomic_read(&dev->opened)); 672 dev->channel, dev->port.count);
670 673
671 if (atomic_inc_return(&dev->opened) > 1) 674 spin_lock_irqsave(&dev->port.lock, flags);
675 if (++dev->port.count > 1) {
676 spin_unlock_irqrestore(&dev->port.lock, flags);
672 return 0; 677 return 0;
678 }
679 spin_unlock_irqrestore(&dev->port.lock, flags);
673 680
674 dlc = dev->dlc; 681 dlc = dev->dlc;
675 682
@@ -724,13 +731,17 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
724static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp) 731static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
725{ 732{
726 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data; 733 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
734 unsigned long flags;
735
727 if (!dev) 736 if (!dev)
728 return; 737 return;
729 738
730 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc, 739 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
731 atomic_read(&dev->opened)); 740 dev->port.count);
732 741
733 if (atomic_dec_and_test(&dev->opened)) { 742 spin_lock_irqsave(&dev->port.lock, flags);
743 if (!--dev->port.count) {
744 spin_unlock_irqrestore(&dev->port.lock, flags);
734 if (dev->tty_dev->parent) 745 if (dev->tty_dev->parent)
735 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST); 746 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
736 747
@@ -751,7 +762,8 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
751 762
752 tty_port_put(&dev->port); 763 tty_port_put(&dev->port);
753 } 764 }
754 } 765 } else
766 spin_unlock_irqrestore(&dev->port.lock, flags);
755 767
756 tty_port_put(&dev->port); 768 tty_port_put(&dev->port);
757} 769}