Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 1/4] Bluetooth: Use zero timeout for immediate scheduling
@ 2014-08-17 21:41 johan.hedberg
  2014-08-17 21:41 ` [PATCH 2/4] Bluetooth: Fix hci_conn reference counting with hci_chan johan.hedberg
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: johan.hedberg @ 2014-08-17 21:41 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

There's no point in passing a "small" timeout to queue_delayed_work() to
try to get the callback faster scheduled. Passing 0 is perfectly valid
and will cause a shortcut to a direct queue_work().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index aa75eee8ad7f..18c24f6fce6c 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -791,7 +791,7 @@ static inline void hci_conn_drop(struct hci_conn *conn)
 				if (!conn->out)
 					timeo *= 2;
 			} else {
-				timeo = msecs_to_jiffies(10);
+				timeo = 0;
 			}
 			break;
 
@@ -800,7 +800,7 @@ static inline void hci_conn_drop(struct hci_conn *conn)
 			break;
 
 		default:
-			timeo = msecs_to_jiffies(10);
+			timeo = 0;
 			break;
 		}
 
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/4] Bluetooth: Fix hci_conn reference counting with hci_chan
  2014-08-17 21:41 [PATCH 1/4] Bluetooth: Use zero timeout for immediate scheduling johan.hedberg
@ 2014-08-17 21:41 ` johan.hedberg
  2014-08-17 22:15   ` Marcel Holtmann
  2014-08-17 21:41 ` [PATCH 3/4] Bluetooth: Set disc_timeout to 0 when calling hci_chan_del johan.hedberg
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: johan.hedberg @ 2014-08-17 21:41 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

The hci_chan_del() function was doing a hci_conn_drop() but there was no
matching hci_conn_hold() in the hci_chan_create() function. Furthermore,
as the hci_chan struct holds a pointer to the hci_conn there should be
proper use of hci_conn_get/put. This patch fixes both issues so that
hci_chan does correct reference counting of the hci_conn object.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/hci_conn.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 4ecc9d5fce7a..7815826a48e4 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1295,7 +1295,8 @@ struct hci_chan *hci_chan_create(struct hci_conn *conn)
 	if (!chan)
 		return NULL;
 
-	chan->conn = conn;
+	chan->conn = hci_conn_get(conn);
+	hci_conn_hold(conn);
 	skb_queue_head_init(&chan->data_q);
 	chan->state = BT_CONNECTED;
 
@@ -1316,6 +1317,7 @@ void hci_chan_del(struct hci_chan *chan)
 	synchronize_rcu();
 
 	hci_conn_drop(conn);
+	hci_conn_put(conn);
 
 	skb_queue_purge(&chan->data_q);
 	kfree(chan);
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/4] Bluetooth: Set disc_timeout to 0 when calling hci_chan_del
  2014-08-17 21:41 [PATCH 1/4] Bluetooth: Use zero timeout for immediate scheduling johan.hedberg
  2014-08-17 21:41 ` [PATCH 2/4] Bluetooth: Fix hci_conn reference counting with hci_chan johan.hedberg
@ 2014-08-17 21:41 ` johan.hedberg
  2014-08-17 22:15   ` Marcel Holtmann
  2014-08-17 21:41 ` [PATCH 4/4] Bluetooth: Ignore incoming data after initiating disconnection johan.hedberg
  2014-08-17 22:15 ` [PATCH 1/4] Bluetooth: Use zero timeout for immediate scheduling Marcel Holtmann
  3 siblings, 1 reply; 8+ messages in thread
From: johan.hedberg @ 2014-08-17 21:41 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

The hci_chan_del() function is used in scenarios where we've decided we
want to get rid of the underlying baseband link. It makes therefore
sense to force the disc_timeout to 0 so that the disconnection routines
are immediately scheduled.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/hci_conn.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 7815826a48e4..cb04a4e3c829 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1316,6 +1316,9 @@ void hci_chan_del(struct hci_chan *chan)
 
 	synchronize_rcu();
 
+	/* Force the connection to be immediately dropped */
+	conn->disc_timeout = 0;
+
 	hci_conn_drop(conn);
 	hci_conn_put(conn);
 
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/4] Bluetooth: Ignore incoming data after initiating disconnection
  2014-08-17 21:41 [PATCH 1/4] Bluetooth: Use zero timeout for immediate scheduling johan.hedberg
  2014-08-17 21:41 ` [PATCH 2/4] Bluetooth: Fix hci_conn reference counting with hci_chan johan.hedberg
  2014-08-17 21:41 ` [PATCH 3/4] Bluetooth: Set disc_timeout to 0 when calling hci_chan_del johan.hedberg
@ 2014-08-17 21:41 ` johan.hedberg
  2014-08-17 22:15   ` Marcel Holtmann
  2014-08-17 22:15 ` [PATCH 1/4] Bluetooth: Use zero timeout for immediate scheduling Marcel Holtmann
  3 siblings, 1 reply; 8+ messages in thread
From: johan.hedberg @ 2014-08-17 21:41 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

When hci_chan_del is called the disconnection routines get scheduled
through a workqueue. If there's any incoming ACL data before the
routines get executed there's a chance that a new hci_chan is created
and the disconnection never happens. This patch adds a new hci_conn flag
to indicate that we're in the process of driving the connection down. We
set the flag in hci_chan_del and check for it in hci_chan_create so that
no new channels are created for the same connection.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h | 1 +
 net/bluetooth/hci_conn.c         | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 18c24f6fce6c..dbe73642c54c 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -553,6 +553,7 @@ enum {
 	HCI_CONN_FIPS,
 	HCI_CONN_STK_ENCRYPT,
 	HCI_CONN_AUTH_INITIATOR,
+	HCI_CONN_DROP,
 };
 
 static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index cb04a4e3c829..aaa7e388d026 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1291,6 +1291,11 @@ struct hci_chan *hci_chan_create(struct hci_conn *conn)
 
 	BT_DBG("%s hcon %p", hdev->name, conn);
 
+	if (test_bit(HCI_CONN_DROP, &conn->flags)) {
+		BT_DBG("Refusing to create new hci_chan");
+		return NULL;
+	}
+
 	chan = kzalloc(sizeof(*chan), GFP_KERNEL);
 	if (!chan)
 		return NULL;
@@ -1318,6 +1323,7 @@ void hci_chan_del(struct hci_chan *chan)
 
 	/* Force the connection to be immediately dropped */
 	conn->disc_timeout = 0;
+	set_bit(HCI_CONN_DROP, &conn->flags);
 
 	hci_conn_drop(conn);
 	hci_conn_put(conn);
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/4] Bluetooth: Ignore incoming data after initiating disconnection
  2014-08-17 21:41 ` [PATCH 4/4] Bluetooth: Ignore incoming data after initiating disconnection johan.hedberg
@ 2014-08-17 22:15   ` Marcel Holtmann
  0 siblings, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2014-08-17 22:15 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

> When hci_chan_del is called the disconnection routines get scheduled
> through a workqueue. If there's any incoming ACL data before the
> routines get executed there's a chance that a new hci_chan is created
> and the disconnection never happens. This patch adds a new hci_conn flag
> to indicate that we're in the process of driving the connection down. We
> set the flag in hci_chan_del and check for it in hci_chan_create so that
> no new channels are created for the same connection.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> include/net/bluetooth/hci_core.h | 1 +
> net/bluetooth/hci_conn.c         | 6 ++++++
> 2 files changed, 7 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/4] Bluetooth: Set disc_timeout to 0 when calling hci_chan_del
  2014-08-17 21:41 ` [PATCH 3/4] Bluetooth: Set disc_timeout to 0 when calling hci_chan_del johan.hedberg
@ 2014-08-17 22:15   ` Marcel Holtmann
  0 siblings, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2014-08-17 22:15 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

> The hci_chan_del() function is used in scenarios where we've decided we
> want to get rid of the underlying baseband link. It makes therefore
> sense to force the disc_timeout to 0 so that the disconnection routines
> are immediately scheduled.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/hci_conn.c | 3 +++
> 1 file changed, 3 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/4] Bluetooth: Use zero timeout for immediate scheduling
  2014-08-17 21:41 [PATCH 1/4] Bluetooth: Use zero timeout for immediate scheduling johan.hedberg
                   ` (2 preceding siblings ...)
  2014-08-17 21:41 ` [PATCH 4/4] Bluetooth: Ignore incoming data after initiating disconnection johan.hedberg
@ 2014-08-17 22:15 ` Marcel Holtmann
  3 siblings, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2014-08-17 22:15 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

> There's no point in passing a "small" timeout to queue_delayed_work() to
> try to get the callback faster scheduled. Passing 0 is perfectly valid
> and will cause a shortcut to a direct queue_work().
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> include/net/bluetooth/hci_core.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/4] Bluetooth: Fix hci_conn reference counting with hci_chan
  2014-08-17 21:41 ` [PATCH 2/4] Bluetooth: Fix hci_conn reference counting with hci_chan johan.hedberg
@ 2014-08-17 22:15   ` Marcel Holtmann
  0 siblings, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2014-08-17 22:15 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

> The hci_chan_del() function was doing a hci_conn_drop() but there was no
> matching hci_conn_hold() in the hci_chan_create() function. Furthermore,
> as the hci_chan struct holds a pointer to the hci_conn there should be
> proper use of hci_conn_get/put. This patch fixes both issues so that
> hci_chan does correct reference counting of the hci_conn object.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/hci_conn.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-08-17 22:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-17 21:41 [PATCH 1/4] Bluetooth: Use zero timeout for immediate scheduling johan.hedberg
2014-08-17 21:41 ` [PATCH 2/4] Bluetooth: Fix hci_conn reference counting with hci_chan johan.hedberg
2014-08-17 22:15   ` Marcel Holtmann
2014-08-17 21:41 ` [PATCH 3/4] Bluetooth: Set disc_timeout to 0 when calling hci_chan_del johan.hedberg
2014-08-17 22:15   ` Marcel Holtmann
2014-08-17 21:41 ` [PATCH 4/4] Bluetooth: Ignore incoming data after initiating disconnection johan.hedberg
2014-08-17 22:15   ` Marcel Holtmann
2014-08-17 22:15 ` [PATCH 1/4] Bluetooth: Use zero timeout for immediate scheduling Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox