Skip to content

Commit

Permalink
Bluetooth: Provide hdev parameter to hci_recv_frame() driver callback
Browse files Browse the repository at this point in the history
To avoid casting skb->dev into hdev, just let the drivers provide
the hdev directly when calling hci_recv_frame() function.

This patch also fixes up all drivers to provide the hdev.

Signed-off-by: Marcel Holtmann <[email protected]>
Signed-off-by: Johan Hedberg <[email protected]>
  • Loading branch information
holtmann authored and Johan Hedberg committed Oct 11, 2013
1 parent 8909f6d commit e1a2617
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 41 deletions.
3 changes: 1 addition & 2 deletions drivers/bluetooth/bfusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ static inline int bfusb_recv_block(struct bfusb_data *data, int hdr, unsigned ch
return -ENOMEM;
}

skb->dev = (void *) data->hdev;
bt_cb(skb)->pkt_type = pkt_type;

data->reassembly = skb;
Expand All @@ -333,7 +332,7 @@ static inline int bfusb_recv_block(struct bfusb_data *data, int hdr, unsigned ch
memcpy(skb_put(data->reassembly, len), buf, len);

if (hdr & 0x08) {
hci_recv_frame(data->reassembly);
hci_recv_frame(data->hdev, data->reassembly);
data->reassembly = NULL;
}

Expand Down
3 changes: 1 addition & 2 deletions drivers/bluetooth/bluecard_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ static void bluecard_receive(bluecard_info_t *info, unsigned int offset)

if (info->rx_state == RECV_WAIT_PACKET_TYPE) {

info->rx_skb->dev = (void *) info->hdev;
bt_cb(info->rx_skb)->pkt_type = buf[i];

switch (bt_cb(info->rx_skb)->pkt_type) {
Expand Down Expand Up @@ -477,7 +476,7 @@ static void bluecard_receive(bluecard_info_t *info, unsigned int offset)
break;

case RECV_WAIT_DATA:
hci_recv_frame(info->rx_skb);
hci_recv_frame(info->hdev, info->rx_skb);
info->rx_skb = NULL;
break;

Expand Down
4 changes: 1 addition & 3 deletions drivers/bluetooth/bpa10x.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ static int bpa10x_recv(struct hci_dev *hdev, int queue, void *buf, int count)
return -ENOMEM;
}

skb->dev = (void *) hdev;

data->rx_skb[queue] = skb;

scb = (void *) skb->cb;
Expand All @@ -155,7 +153,7 @@ static int bpa10x_recv(struct hci_dev *hdev, int queue, void *buf, int count)
data->rx_skb[queue] = NULL;

bt_cb(skb)->pkt_type = scb->type;
hci_recv_frame(skb);
hci_recv_frame(hdev, skb);
}

count -= len; buf += len;
Expand Down
3 changes: 1 addition & 2 deletions drivers/bluetooth/bt3c_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ static void bt3c_receive(bt3c_info_t *info)

if (info->rx_state == RECV_WAIT_PACKET_TYPE) {

info->rx_skb->dev = (void *) info->hdev;
bt_cb(info->rx_skb)->pkt_type = inb(iobase + DATA_L);
inb(iobase + DATA_H);
//printk("bt3c: PACKET_TYPE=%02x\n", bt_cb(info->rx_skb)->pkt_type);
Expand Down Expand Up @@ -318,7 +317,7 @@ static void bt3c_receive(bt3c_info_t *info)
break;

case RECV_WAIT_DATA:
hci_recv_frame(info->rx_skb);
hci_recv_frame(info->hdev, info->rx_skb);
info->rx_skb = NULL;
break;

Expand Down
8 changes: 3 additions & 5 deletions drivers/bluetooth/btmrvl_sdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,28 +600,26 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
case HCI_SCODATA_PKT:
case HCI_EVENT_PKT:
bt_cb(skb)->pkt_type = type;
skb->dev = (void *)hdev;
skb_put(skb, buf_len);
skb_pull(skb, SDIO_HEADER_LEN);

if (type == HCI_EVENT_PKT) {
if (btmrvl_check_evtpkt(priv, skb))
hci_recv_frame(skb);
hci_recv_frame(hdev, skb);
} else {
hci_recv_frame(skb);
hci_recv_frame(hdev, skb);
}

hdev->stat.byte_rx += buf_len;
break;

case MRVL_VENDOR_PKT:
bt_cb(skb)->pkt_type = HCI_VENDOR_PKT;
skb->dev = (void *)hdev;
skb_put(skb, buf_len);
skb_pull(skb, SDIO_HEADER_LEN);

if (btmrvl_process_event(priv, skb))
hci_recv_frame(skb);
hci_recv_frame(hdev, skb);

hdev->stat.byte_rx += buf_len;
break;
Expand Down
3 changes: 1 addition & 2 deletions drivers/bluetooth/btsdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@ static int btsdio_rx_packet(struct btsdio_data *data)

data->hdev->stat.byte_rx += len;

skb->dev = (void *) data->hdev;
bt_cb(skb)->pkt_type = hdr[3];

err = hci_recv_frame(skb);
err = hci_recv_frame(data->hdev, skb);
if (err < 0)
return err;

Expand Down
3 changes: 1 addition & 2 deletions drivers/bluetooth/btuart_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ static void btuart_receive(btuart_info_t *info)

if (info->rx_state == RECV_WAIT_PACKET_TYPE) {

info->rx_skb->dev = (void *) info->hdev;
bt_cb(info->rx_skb)->pkt_type = inb(iobase + UART_RX);

switch (bt_cb(info->rx_skb)->pkt_type) {
Expand Down Expand Up @@ -265,7 +264,7 @@ static void btuart_receive(btuart_info_t *info)
break;

case RECV_WAIT_DATA:
hci_recv_frame(info->rx_skb);
hci_recv_frame(info->hdev, info->rx_skb);
info->rx_skb = NULL;
break;

Expand Down
4 changes: 1 addition & 3 deletions drivers/bluetooth/btwilink.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ static long st_receive(void *priv_data, struct sk_buff *skb)
return -EFAULT;
}

skb->dev = (void *) lhst->hdev;

/* Forward skb to HCI core layer */
err = hci_recv_frame(skb);
err = hci_recv_frame(lhst->hdev, skb);
if (err < 0) {
BT_ERR("Unable to push skb to HCI core(%d)", err);
return err;
Expand Down
3 changes: 1 addition & 2 deletions drivers/bluetooth/dtl1_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,8 @@ static void dtl1_receive(dtl1_info_t *info)
case 0x83:
case 0x84:
/* send frame to the HCI layer */
info->rx_skb->dev = (void *) info->hdev;
bt_cb(info->rx_skb)->pkt_type &= 0x0f;
hci_recv_frame(info->rx_skb);
hci_recv_frame(info->hdev, info->rx_skb);
break;
default:
/* unknown packet */
Expand Down
5 changes: 2 additions & 3 deletions drivers/bluetooth/hci_bcsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ static void bcsp_complete_rx_pkt(struct hci_uart *hu)
memcpy(skb_push(bcsp->rx_skb, HCI_EVENT_HDR_SIZE), &hdr, HCI_EVENT_HDR_SIZE);
bt_cb(bcsp->rx_skb)->pkt_type = HCI_EVENT_PKT;

hci_recv_frame(bcsp->rx_skb);
hci_recv_frame(hu->hdev, bcsp->rx_skb);
} else {
BT_ERR ("Packet for unknown channel (%u %s)",
bcsp->rx_skb->data[1] & 0x0f,
Expand All @@ -536,7 +536,7 @@ static void bcsp_complete_rx_pkt(struct hci_uart *hu)
/* Pull out BCSP hdr */
skb_pull(bcsp->rx_skb, 4);

hci_recv_frame(bcsp->rx_skb);
hci_recv_frame(hu->hdev, bcsp->rx_skb);
}

bcsp->rx_state = BCSP_W4_PKT_DELIMITER;
Expand Down Expand Up @@ -655,7 +655,6 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
bcsp->rx_count = 0;
return 0;
}
bcsp->rx_skb->dev = (void *) hu->hdev;
break;
}
break;
Expand Down
2 changes: 1 addition & 1 deletion drivers/bluetooth/hci_h5.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static void h5_complete_rx_pkt(struct hci_uart *hu)
/* Remove Three-wire header */
skb_pull(h5->rx_skb, 4);

hci_recv_frame(h5->rx_skb);
hci_recv_frame(hu->hdev, h5->rx_skb);
h5->rx_skb = NULL;

break;
Expand Down
13 changes: 6 additions & 7 deletions drivers/bluetooth/hci_ll.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,14 @@ static int ll_enqueue(struct hci_uart *hu, struct sk_buff *skb)
return 0;
}

static inline int ll_check_data_len(struct ll_struct *ll, int len)
static inline int ll_check_data_len(struct hci_dev *hdev, struct ll_struct *ll, int len)
{
int room = skb_tailroom(ll->rx_skb);

BT_DBG("len %d room %d", len, room);

if (!len) {
hci_recv_frame(ll->rx_skb);
hci_recv_frame(hdev, ll->rx_skb);
} else if (len > room) {
BT_ERR("Data length is too large");
kfree_skb(ll->rx_skb);
Expand Down Expand Up @@ -395,7 +395,7 @@ static int ll_recv(struct hci_uart *hu, void *data, int count)
switch (ll->rx_state) {
case HCILL_W4_DATA:
BT_DBG("Complete data");
hci_recv_frame(ll->rx_skb);
hci_recv_frame(hu->hdev, ll->rx_skb);

ll->rx_state = HCILL_W4_PACKET_TYPE;
ll->rx_skb = NULL;
Expand All @@ -406,7 +406,7 @@ static int ll_recv(struct hci_uart *hu, void *data, int count)

BT_DBG("Event header: evt 0x%2.2x plen %d", eh->evt, eh->plen);

ll_check_data_len(ll, eh->plen);
ll_check_data_len(hu->hdev, ll, eh->plen);
continue;

case HCILL_W4_ACL_HDR:
Expand All @@ -415,15 +415,15 @@ static int ll_recv(struct hci_uart *hu, void *data, int count)

BT_DBG("ACL header: dlen %d", dlen);

ll_check_data_len(ll, dlen);
ll_check_data_len(hu->hdev, ll, dlen);
continue;

case HCILL_W4_SCO_HDR:
sh = hci_sco_hdr(ll->rx_skb);

BT_DBG("SCO header: dlen %d", sh->dlen);

ll_check_data_len(ll, sh->dlen);
ll_check_data_len(hu->hdev, ll, sh->dlen);
continue;
}
}
Expand Down Expand Up @@ -494,7 +494,6 @@ static int ll_recv(struct hci_uart *hu, void *data, int count)
return -ENOMEM;
}

ll->rx_skb->dev = (void *) hu->hdev;
bt_cb(ll->rx_skb)->pkt_type = type;
}

Expand Down
3 changes: 1 addition & 2 deletions drivers/bluetooth/hci_vhci.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,9 @@ static inline ssize_t vhci_get_user(struct vhci_data *data,
return -ENODEV;
}

skb->dev = (void *) data->hdev;
bt_cb(skb)->pkt_type = pkt_type;

ret = hci_recv_frame(skb);
ret = hci_recv_frame(data->hdev, skb);
break;

case HCI_VENDOR_PKT:
Expand Down
2 changes: 1 addition & 1 deletion include/net/bluetooth/hci_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);

void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);

int hci_recv_frame(struct sk_buff *skb);
int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb);
int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count);
int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count);

Expand Down
6 changes: 2 additions & 4 deletions net/bluetooth/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2485,9 +2485,8 @@ int hci_resume_dev(struct hci_dev *hdev)
EXPORT_SYMBOL(hci_resume_dev);

/* Receive frame from HCI drivers */
int hci_recv_frame(struct sk_buff *skb)
int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb)
{
struct hci_dev *hdev = (struct hci_dev *) skb->dev;
if (!hdev || (!test_bit(HCI_UP, &hdev->flags)
&& !test_bit(HCI_INIT, &hdev->flags))) {
kfree_skb(skb);
Expand Down Expand Up @@ -2546,7 +2545,6 @@ static int hci_reassembly(struct hci_dev *hdev, int type, void *data,
scb->expect = hlen;
scb->pkt_type = type;

skb->dev = (void *) hdev;
hdev->reassembly[index] = skb;
}

Expand Down Expand Up @@ -2606,7 +2604,7 @@ static int hci_reassembly(struct hci_dev *hdev, int type, void *data,
/* Complete frame */

bt_cb(skb)->pkt_type = type;
hci_recv_frame(skb);
hci_recv_frame(hdev, skb);

hdev->reassembly[index] = NULL;
return remain;
Expand Down

0 comments on commit e1a2617

Please sign in to comment.