[PATCH AUTOSEL for 4.9 018/190] Bluetooth: 6lowpan: fix delay work init in add_peer_chan()

2018-03-07 Thread Sasha Levin
From: Michael Scott 

[ Upstream commit d2891c4d071d807f01cc911dc42a68f4568d65cf ]

When adding 6lowpan devices very rapidly we sometimes see a crash:
[23122.306615] CPU: 2 PID: 0 Comm: swapper/2 Not tainted 4.9.0-43-arm64 #1 
Debian 4.9.9.linaro.43-1
[23122.315400] Hardware name: HiKey Development Board (DT)
[23122.320623] task: 800075443080 task.stack: 800075484000
[23122.326551] PC is at expire_timers+0x70/0x150
[23122.330907] LR is at run_timer_softirq+0xa0/0x1a0
[23122.335616] pc : [] lr : [] pstate: 
61c5

This was due to add_peer_chan() unconditionally initializing the
lowpan_btle_dev->notify_peers delayed work structure, even if the
lowpan_btle_dev passed into add_peer_chan() had previously been
initialized.

Normally, this would go unnoticed as the delayed work timer is set for
100 msec, however when calling add_peer_chan() faster than 100 msec it
clears out a previously queued delay work causing the crash above.

To fix this, let add_peer_chan() know when a new lowpan_btle_dev is passed
in so that it only performs the delay work initialization when needed.

Signed-off-by: Michael Scott 
Acked-by: Jukka Rissanen 
Signed-off-by: Marcel Holtmann 
Signed-off-by: Sasha Levin 
---
 net/bluetooth/6lowpan.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index 1904a93f47d5..de7b82ece499 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -755,7 +755,8 @@ static void set_ip_addr_bits(u8 addr_type, u8 *addr)
 }
 
 static struct l2cap_chan *add_peer_chan(struct l2cap_chan *chan,
-   struct lowpan_btle_dev *dev)
+   struct lowpan_btle_dev *dev,
+   bool new_netdev)
 {
struct lowpan_peer *peer;
 
@@ -786,7 +787,8 @@ static struct l2cap_chan *add_peer_chan(struct l2cap_chan 
*chan,
spin_unlock(_lock);
 
/* Notifying peers about us needs to be done without locks held */
-   INIT_DELAYED_WORK(>notify_peers, do_notify_peers);
+   if (new_netdev)
+   INIT_DELAYED_WORK(>notify_peers, do_notify_peers);
schedule_delayed_work(>notify_peers, msecs_to_jiffies(100));
 
return peer->chan;
@@ -843,6 +845,7 @@ static int setup_netdev(struct l2cap_chan *chan, struct 
lowpan_btle_dev **dev)
 static inline void chan_ready_cb(struct l2cap_chan *chan)
 {
struct lowpan_btle_dev *dev;
+   bool new_netdev = false;
 
dev = lookup_dev(chan->conn);
 
@@ -853,12 +856,13 @@ static inline void chan_ready_cb(struct l2cap_chan *chan)
l2cap_chan_del(chan, -ENOENT);
return;
}
+   new_netdev = true;
}
 
if (!try_module_get(THIS_MODULE))
return;
 
-   add_peer_chan(chan, dev);
+   add_peer_chan(chan, dev, new_netdev);
ifup(dev->netdev);
 }
 
-- 
2.14.1


[PATCH AUTOSEL for 4.9 018/190] Bluetooth: 6lowpan: fix delay work init in add_peer_chan()

2018-03-07 Thread Sasha Levin
From: Michael Scott 

[ Upstream commit d2891c4d071d807f01cc911dc42a68f4568d65cf ]

When adding 6lowpan devices very rapidly we sometimes see a crash:
[23122.306615] CPU: 2 PID: 0 Comm: swapper/2 Not tainted 4.9.0-43-arm64 #1 
Debian 4.9.9.linaro.43-1
[23122.315400] Hardware name: HiKey Development Board (DT)
[23122.320623] task: 800075443080 task.stack: 800075484000
[23122.326551] PC is at expire_timers+0x70/0x150
[23122.330907] LR is at run_timer_softirq+0xa0/0x1a0
[23122.335616] pc : [] lr : [] pstate: 
61c5

This was due to add_peer_chan() unconditionally initializing the
lowpan_btle_dev->notify_peers delayed work structure, even if the
lowpan_btle_dev passed into add_peer_chan() had previously been
initialized.

Normally, this would go unnoticed as the delayed work timer is set for
100 msec, however when calling add_peer_chan() faster than 100 msec it
clears out a previously queued delay work causing the crash above.

To fix this, let add_peer_chan() know when a new lowpan_btle_dev is passed
in so that it only performs the delay work initialization when needed.

Signed-off-by: Michael Scott 
Acked-by: Jukka Rissanen 
Signed-off-by: Marcel Holtmann 
Signed-off-by: Sasha Levin 
---
 net/bluetooth/6lowpan.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index 1904a93f47d5..de7b82ece499 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -755,7 +755,8 @@ static void set_ip_addr_bits(u8 addr_type, u8 *addr)
 }
 
 static struct l2cap_chan *add_peer_chan(struct l2cap_chan *chan,
-   struct lowpan_btle_dev *dev)
+   struct lowpan_btle_dev *dev,
+   bool new_netdev)
 {
struct lowpan_peer *peer;
 
@@ -786,7 +787,8 @@ static struct l2cap_chan *add_peer_chan(struct l2cap_chan 
*chan,
spin_unlock(_lock);
 
/* Notifying peers about us needs to be done without locks held */
-   INIT_DELAYED_WORK(>notify_peers, do_notify_peers);
+   if (new_netdev)
+   INIT_DELAYED_WORK(>notify_peers, do_notify_peers);
schedule_delayed_work(>notify_peers, msecs_to_jiffies(100));
 
return peer->chan;
@@ -843,6 +845,7 @@ static int setup_netdev(struct l2cap_chan *chan, struct 
lowpan_btle_dev **dev)
 static inline void chan_ready_cb(struct l2cap_chan *chan)
 {
struct lowpan_btle_dev *dev;
+   bool new_netdev = false;
 
dev = lookup_dev(chan->conn);
 
@@ -853,12 +856,13 @@ static inline void chan_ready_cb(struct l2cap_chan *chan)
l2cap_chan_del(chan, -ENOENT);
return;
}
+   new_netdev = true;
}
 
if (!try_module_get(THIS_MODULE))
return;
 
-   add_peer_chan(chan, dev);
+   add_peer_chan(chan, dev, new_netdev);
ifup(dev->netdev);
 }
 
-- 
2.14.1