Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb,
struct brcmf_pub *drvr = ifp->drvr;
struct ethhdr *eh;
int head_delta;
unsigned int tx_bytes = skb->len;

brcmf_dbg(DATA, "Enter, bsscfgidx=%d\n", ifp->bsscfgidx);

Expand Down Expand Up @@ -254,7 +255,7 @@ static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb,
ndev->stats.tx_dropped++;
} else {
ndev->stats.tx_packets++;
ndev->stats.tx_bytes += skb->len;
ndev->stats.tx_bytes += tx_bytes;
}

/* Return ok: we always eat the packet */
Expand Down
1 change: 1 addition & 0 deletions include/net/bluetooth/l2cap.h
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ enum {
};

void l2cap_chan_hold(struct l2cap_chan *c);
struct l2cap_chan *l2cap_chan_hold_unless_zero(struct l2cap_chan *c);
void l2cap_chan_put(struct l2cap_chan *c);

static inline void l2cap_chan_lock(struct l2cap_chan *chan)
Expand Down
77 changes: 62 additions & 15 deletions net/bluetooth/l2cap_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,28 @@ static struct l2cap_chan *__l2cap_get_chan_by_scid(struct l2cap_conn *conn,
}

/* Find channel with given SCID.
* Returns locked channel. */
* Returns a reference locked channel.
*/
static struct l2cap_chan *l2cap_get_chan_by_scid(struct l2cap_conn *conn,
u16 cid)
{
struct l2cap_chan *c;

mutex_lock(&conn->chan_lock);
c = __l2cap_get_chan_by_scid(conn, cid);
if (c)
l2cap_chan_lock(c);
if (c) {
/* Only lock if chan reference is not 0 */
c = l2cap_chan_hold_unless_zero(c);
if (c)
l2cap_chan_lock(c);
}
mutex_unlock(&conn->chan_lock);

return c;
}

/* Find channel with given DCID.
* Returns locked channel.
* Returns a reference locked channel.
*/
static struct l2cap_chan *l2cap_get_chan_by_dcid(struct l2cap_conn *conn,
u16 cid)
Expand All @@ -139,8 +144,12 @@ static struct l2cap_chan *l2cap_get_chan_by_dcid(struct l2cap_conn *conn,

mutex_lock(&conn->chan_lock);
c = __l2cap_get_chan_by_dcid(conn, cid);
if (c)
l2cap_chan_lock(c);
if (c) {
/* Only lock if chan reference is not 0 */
c = l2cap_chan_hold_unless_zero(c);
if (c)
l2cap_chan_lock(c);
}
mutex_unlock(&conn->chan_lock);

return c;
Expand All @@ -165,8 +174,12 @@ static struct l2cap_chan *l2cap_get_chan_by_ident(struct l2cap_conn *conn,

mutex_lock(&conn->chan_lock);
c = __l2cap_get_chan_by_ident(conn, ident);
if (c)
l2cap_chan_lock(c);
if (c) {
/* Only lock if chan reference is not 0 */
c = l2cap_chan_hold_unless_zero(c);
if (c)
l2cap_chan_lock(c);
}
mutex_unlock(&conn->chan_lock);

return c;
Expand Down Expand Up @@ -487,6 +500,16 @@ void l2cap_chan_hold(struct l2cap_chan *c)
kref_get(&c->kref);
}

struct l2cap_chan *l2cap_chan_hold_unless_zero(struct l2cap_chan *c)
{
BT_DBG("chan %p orig refcnt %u", c, kref_read(&c->kref));

if (!kref_get_unless_zero(&c->kref))
return NULL;

return c;
}

void l2cap_chan_put(struct l2cap_chan *c)
{
BT_DBG("chan %p orig refcnt %d", c, kref_read(&c->kref));
Expand Down Expand Up @@ -1778,11 +1801,11 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm,
bdaddr_t *dst,
u8 link_type)
{
struct l2cap_chan *c, *c1 = NULL;
struct l2cap_chan *c, *tmp, *c1 = NULL;

read_lock(&chan_list_lock);

list_for_each_entry(c, &chan_list, global_l) {
list_for_each_entry_safe(c, tmp, &chan_list, global_l) {
if (state && c->state != state)
continue;

Expand All @@ -1800,7 +1823,9 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm,
src_match = !bacmp(&c->src, src);
dst_match = !bacmp(&c->dst, dst);
if (src_match && dst_match) {
l2cap_chan_hold(c);
if (!l2cap_chan_hold_unless_zero(c))
continue;

read_unlock(&chan_list_lock);
return c;
}
Expand All @@ -1815,7 +1840,7 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm,
}

if (c1)
l2cap_chan_hold(c1);
c1 = l2cap_chan_hold_unless_zero(c1);

read_unlock(&chan_list_lock);

Expand Down Expand Up @@ -4007,6 +4032,12 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn,
}
}

chan = l2cap_chan_hold_unless_zero(chan);
if (!chan) {
err = -EBADSLT;
goto unlock;
}

err = 0;

l2cap_chan_lock(chan);
Expand Down Expand Up @@ -4037,6 +4068,7 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn,
}

l2cap_chan_unlock(chan);
l2cap_chan_put(chan);

unlock:
mutex_unlock(&conn->chan_lock);
Expand Down Expand Up @@ -4190,6 +4222,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,

unlock:
l2cap_chan_unlock(chan);
l2cap_chan_put(chan);
return err;
}

Expand Down Expand Up @@ -4302,6 +4335,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn,

done:
l2cap_chan_unlock(chan);
l2cap_chan_put(chan);
return err;
}

Expand Down Expand Up @@ -5026,6 +5060,7 @@ static inline int l2cap_move_channel_req(struct l2cap_conn *conn,
l2cap_send_move_chan_rsp(chan, result);

l2cap_chan_unlock(chan);
l2cap_chan_put(chan);

return 0;
}
Expand Down Expand Up @@ -5118,6 +5153,7 @@ static void l2cap_move_continue(struct l2cap_conn *conn, u16 icid, u16 result)
}

l2cap_chan_unlock(chan);
l2cap_chan_put(chan);
}

static void l2cap_move_fail(struct l2cap_conn *conn, u8 ident, u16 icid,
Expand Down Expand Up @@ -5147,6 +5183,7 @@ static void l2cap_move_fail(struct l2cap_conn *conn, u8 ident, u16 icid,
l2cap_send_move_chan_cfm(chan, L2CAP_MC_UNCONFIRMED);

l2cap_chan_unlock(chan);
l2cap_chan_put(chan);
}

static int l2cap_move_channel_rsp(struct l2cap_conn *conn,
Expand Down Expand Up @@ -5210,6 +5247,7 @@ static int l2cap_move_channel_confirm(struct l2cap_conn *conn,
l2cap_send_move_chan_cfm_rsp(conn, cmd->ident, icid);

l2cap_chan_unlock(chan);
l2cap_chan_put(chan);

return 0;
}
Expand Down Expand Up @@ -5245,6 +5283,7 @@ static inline int l2cap_move_channel_confirm_rsp(struct l2cap_conn *conn,
}

l2cap_chan_unlock(chan);
l2cap_chan_put(chan);

return 0;
}
Expand Down Expand Up @@ -5630,12 +5669,11 @@ static inline int l2cap_le_credits(struct l2cap_conn *conn,
if (credits > max_credits) {
BT_ERR("LE credits overflow");
l2cap_send_disconn_req(chan, ECONNRESET);
l2cap_chan_unlock(chan);

/* Return 0 so that we don't trigger an unnecessary
* command reject packet.
*/
return 0;
goto unlock;
}

chan->tx_credits += credits;
Expand All @@ -5648,7 +5686,9 @@ static inline int l2cap_le_credits(struct l2cap_conn *conn,
if (chan->tx_credits)
chan->ops->resume(chan);

unlock:
l2cap_chan_unlock(chan);
l2cap_chan_put(chan);

return 0;
}
Expand All @@ -5669,9 +5709,14 @@ static inline int l2cap_le_command_rej(struct l2cap_conn *conn,
if (!chan)
goto done;

chan = l2cap_chan_hold_unless_zero(chan);
if (!chan)
goto done;

l2cap_chan_lock(chan);
l2cap_chan_del(chan, ECONNREFUSED);
l2cap_chan_unlock(chan);
l2cap_chan_put(chan);

done:
mutex_unlock(&conn->chan_lock);
Expand Down Expand Up @@ -6912,6 +6957,7 @@ static void l2cap_data_channel(struct l2cap_conn *conn, u16 cid,
return;
}

l2cap_chan_hold(chan);
l2cap_chan_lock(chan);
} else {
BT_DBG("unknown cid 0x%4.4x", cid);
Expand Down Expand Up @@ -6970,6 +7016,7 @@ static void l2cap_data_channel(struct l2cap_conn *conn, u16 cid,

done:
l2cap_chan_unlock(chan);
l2cap_chan_put(chan);
}

static void l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm,
Expand Down Expand Up @@ -7374,7 +7421,7 @@ static struct l2cap_chan *l2cap_global_fixed_chan(struct l2cap_chan *c,
if (src_type != c->src_type)
continue;

l2cap_chan_hold(c);
c = l2cap_chan_hold_unless_zero(c);
read_unlock(&chan_list_lock);
return c;
}
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/ip6mr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ static int ip6mr_cache_report(struct mr6_table *mrt, struct sk_buff *pkt,
And all this only to mangle msg->im6_msgtype and
to set msg->im6_mbz to "mbz" :-)
*/
skb_push(skb, -skb_network_offset(pkt));
__skb_pull(skb, skb_network_offset(pkt));

skb_push(skb, sizeof(*msg));
skb_reset_transport_header(skb);
Expand Down