networking: introduce and use skb_put_data()
A common pattern with skb_put() is to just want to memcpy() some data into the new space, introduce skb_put_data() for this. An spatch similar to the one for skb_put_zero() converts many of the places using it: @@ identifier p, p2; expression len, skb, data; type t, t2; @@ ( -p = skb_put(skb, len); +p = skb_put_data(skb, data, len); | -p = (t)skb_put(skb, len); +p = skb_put_data(skb, data, len); ) ( p2 = (t2)p; -memcpy(p2, data, len); | -memcpy(p, data, len); ) @@ type t, t2; identifier p, p2; expression skb, data; @@ t *p; ... ( -p = skb_put(skb, sizeof(t)); +p = skb_put_data(skb, data, sizeof(t)); | -p = (t *)skb_put(skb, sizeof(t)); +p = skb_put_data(skb, data, sizeof(t)); ) ( p2 = (t2)p; -memcpy(p2, data, sizeof(*p)); | -memcpy(p, data, sizeof(*p)); ) @@ expression skb, len, data; @@ -memcpy(skb_put(skb, len), data, len); +skb_put_data(skb, data, len); (again, manually post-processed to retain some comments) Reviewed-by: Stephen Hemminger <stephen@networkplumber.org> Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
b080db5853
commit
59ae1d127a
@@ -335,7 +335,7 @@ static inline int bfusb_recv_block(struct bfusb_data *data, int hdr, unsigned ch
|
||||
}
|
||||
|
||||
if (len > 0)
|
||||
memcpy(skb_put(data->reassembly, len), buf, len);
|
||||
skb_put_data(data->reassembly, buf, len);
|
||||
|
||||
if (hdr & 0x08) {
|
||||
hci_recv_frame(data->hdev, data->reassembly);
|
||||
@@ -505,7 +505,7 @@ static int bfusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
|
||||
buf[1] = 0x00;
|
||||
buf[2] = (size == BFUSB_MAX_BLOCK_SIZE) ? 0 : size;
|
||||
|
||||
memcpy(skb_put(nskb, 3), buf, 3);
|
||||
skb_put_data(nskb, buf, 3);
|
||||
skb_copy_from_linear_data_offset(skb, sent, skb_put(nskb, size), size);
|
||||
|
||||
sent += size;
|
||||
@@ -516,7 +516,7 @@ static int bfusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
|
||||
if ((nskb->len % data->bulk_pkt_size) == 0) {
|
||||
buf[0] = 0xdd;
|
||||
buf[1] = 0x00;
|
||||
memcpy(skb_put(nskb, 2), buf, 2);
|
||||
skb_put_data(nskb, buf, 2);
|
||||
}
|
||||
|
||||
read_lock(&data->lock);
|
||||
|
@@ -597,7 +597,7 @@ static int bluecard_hci_set_baud_rate(struct hci_dev *hdev, int baud)
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
|
||||
skb_put_data(skb, cmd, sizeof(cmd));
|
||||
|
||||
skb_queue_tail(&(info->txq), skb);
|
||||
|
||||
|
@@ -194,7 +194,7 @@ static int btmrvl_send_sync_cmd(struct btmrvl_private *priv, u16 opcode,
|
||||
hdr->plen = len;
|
||||
|
||||
if (len)
|
||||
memcpy(skb_put(skb, len), param, len);
|
||||
skb_put_data(skb, param, len);
|
||||
|
||||
hci_skb_pkt_type(skb) = MRVL_VENDOR_PKT;
|
||||
|
||||
|
@@ -43,7 +43,7 @@ static int btqcomsmd_recv(struct hci_dev *hdev, unsigned int type,
|
||||
}
|
||||
|
||||
hci_skb_pkt_type(skb) = type;
|
||||
memcpy(skb_put(skb, count), data, count);
|
||||
skb_put_data(skb, data, count);
|
||||
|
||||
return hci_recv_frame(hdev, skb);
|
||||
}
|
||||
|
@@ -478,7 +478,7 @@ static int btusb_recv_intr(struct btusb_data *data, void *buffer, int count)
|
||||
}
|
||||
|
||||
len = min_t(uint, hci_skb_expect(skb), count);
|
||||
memcpy(skb_put(skb, len), buffer, len);
|
||||
skb_put_data(skb, buffer, len);
|
||||
|
||||
count -= len;
|
||||
buffer += len;
|
||||
@@ -533,7 +533,7 @@ static int btusb_recv_bulk(struct btusb_data *data, void *buffer, int count)
|
||||
}
|
||||
|
||||
len = min_t(uint, hci_skb_expect(skb), count);
|
||||
memcpy(skb_put(skb, len), buffer, len);
|
||||
skb_put_data(skb, buffer, len);
|
||||
|
||||
count -= len;
|
||||
buffer += len;
|
||||
@@ -590,7 +590,7 @@ static int btusb_recv_isoc(struct btusb_data *data, void *buffer, int count)
|
||||
}
|
||||
|
||||
len = min_t(uint, hci_skb_expect(skb), count);
|
||||
memcpy(skb_put(skb, len), buffer, len);
|
||||
skb_put_data(skb, buffer, len);
|
||||
|
||||
count -= len;
|
||||
buffer += len;
|
||||
@@ -934,8 +934,8 @@ static void btusb_diag_complete(struct urb *urb)
|
||||
|
||||
skb = bt_skb_alloc(urb->actual_length, GFP_ATOMIC);
|
||||
if (skb) {
|
||||
memcpy(skb_put(skb, urb->actual_length),
|
||||
urb->transfer_buffer, urb->actual_length);
|
||||
skb_put_data(skb, urb->transfer_buffer,
|
||||
urb->actual_length);
|
||||
hci_recv_diag(hdev, skb);
|
||||
}
|
||||
} else if (urb->status == -ENOENT) {
|
||||
@@ -2395,7 +2395,7 @@ static int marvell_config_oob_wake(struct hci_dev *hdev)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
|
||||
skb_put_data(skb, cmd, sizeof(cmd));
|
||||
hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
|
||||
|
||||
ret = btusb_send_frame(hdev, skb);
|
||||
|
@@ -125,7 +125,7 @@ static void bcsp_slip_msgdelim(struct sk_buff *skb)
|
||||
{
|
||||
const char pkt_delim = 0xc0;
|
||||
|
||||
memcpy(skb_put(skb, 1), &pkt_delim, 1);
|
||||
skb_put_data(skb, &pkt_delim, 1);
|
||||
}
|
||||
|
||||
static void bcsp_slip_one_byte(struct sk_buff *skb, u8 c)
|
||||
@@ -135,13 +135,13 @@ static void bcsp_slip_one_byte(struct sk_buff *skb, u8 c)
|
||||
|
||||
switch (c) {
|
||||
case 0xc0:
|
||||
memcpy(skb_put(skb, 2), &esc_c0, 2);
|
||||
skb_put_data(skb, &esc_c0, 2);
|
||||
break;
|
||||
case 0xdb:
|
||||
memcpy(skb_put(skb, 2), &esc_db, 2);
|
||||
skb_put_data(skb, &esc_db, 2);
|
||||
break;
|
||||
default:
|
||||
memcpy(skb_put(skb, 1), &c, 1);
|
||||
skb_put_data(skb, &c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,7 +423,7 @@ static void bcsp_handle_le_pkt(struct hci_uart *hu)
|
||||
BT_DBG("Found a LE conf pkt");
|
||||
if (!nskb)
|
||||
return;
|
||||
memcpy(skb_put(nskb, 4), conf_rsp_pkt, 4);
|
||||
skb_put_data(nskb, conf_rsp_pkt, 4);
|
||||
hci_skb_pkt_type(nskb) = BCSP_LE_PKT;
|
||||
|
||||
skb_queue_head(&bcsp->unrel, nskb);
|
||||
@@ -447,7 +447,7 @@ static inline void bcsp_unslip_one_byte(struct bcsp_struct *bcsp, unsigned char
|
||||
bcsp->rx_esc_state = BCSP_ESCSTATE_ESC;
|
||||
break;
|
||||
default:
|
||||
memcpy(skb_put(bcsp->rx_skb, 1), &byte, 1);
|
||||
skb_put_data(bcsp->rx_skb, &byte, 1);
|
||||
if ((bcsp->rx_skb->data[0] & 0x40) != 0 &&
|
||||
bcsp->rx_state != BCSP_W4_CRC)
|
||||
bcsp_crc_update(&bcsp->message_crc, byte);
|
||||
@@ -458,7 +458,7 @@ static inline void bcsp_unslip_one_byte(struct bcsp_struct *bcsp, unsigned char
|
||||
case BCSP_ESCSTATE_ESC:
|
||||
switch (byte) {
|
||||
case 0xdc:
|
||||
memcpy(skb_put(bcsp->rx_skb, 1), &c0, 1);
|
||||
skb_put_data(bcsp->rx_skb, &c0, 1);
|
||||
if ((bcsp->rx_skb->data[0] & 0x40) != 0 &&
|
||||
bcsp->rx_state != BCSP_W4_CRC)
|
||||
bcsp_crc_update(&bcsp->message_crc, 0xc0);
|
||||
@@ -467,7 +467,7 @@ static inline void bcsp_unslip_one_byte(struct bcsp_struct *bcsp, unsigned char
|
||||
break;
|
||||
|
||||
case 0xdd:
|
||||
memcpy(skb_put(bcsp->rx_skb, 1), &db, 1);
|
||||
skb_put_data(bcsp->rx_skb, &db, 1);
|
||||
if ((bcsp->rx_skb->data[0] & 0x40) != 0 &&
|
||||
bcsp->rx_state != BCSP_W4_CRC)
|
||||
bcsp_crc_update(&bcsp->message_crc, 0xdb);
|
||||
|
@@ -209,7 +209,7 @@ struct sk_buff *h4_recv_buf(struct hci_dev *hdev, struct sk_buff *skb,
|
||||
}
|
||||
|
||||
len = min_t(uint, hci_skb_expect(skb) - skb->len, count);
|
||||
memcpy(skb_put(skb, len), buffer, len);
|
||||
skb_put_data(skb, buffer, len);
|
||||
|
||||
count -= len;
|
||||
buffer += len;
|
||||
|
@@ -109,7 +109,7 @@ static void h5_link_control(struct hci_uart *hu, const void *data, size_t len)
|
||||
|
||||
hci_skb_pkt_type(nskb) = HCI_3WIRE_LINK_PKT;
|
||||
|
||||
memcpy(skb_put(nskb, len), data, len);
|
||||
skb_put_data(nskb, data, len);
|
||||
|
||||
skb_queue_tail(&h5->unrel, nskb);
|
||||
}
|
||||
@@ -487,7 +487,7 @@ static void h5_unslip_one_byte(struct h5 *h5, unsigned char c)
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(skb_put(h5->rx_skb, 1), byte, 1);
|
||||
skb_put_data(h5->rx_skb, byte, 1);
|
||||
h5->rx_pending--;
|
||||
|
||||
BT_DBG("unsliped 0x%02hhx, rx_pending %zu", *byte, h5->rx_pending);
|
||||
@@ -579,7 +579,7 @@ static void h5_slip_delim(struct sk_buff *skb)
|
||||
{
|
||||
const char delim = SLIP_DELIMITER;
|
||||
|
||||
memcpy(skb_put(skb, 1), &delim, 1);
|
||||
skb_put_data(skb, &delim, 1);
|
||||
}
|
||||
|
||||
static void h5_slip_one_byte(struct sk_buff *skb, u8 c)
|
||||
@@ -589,13 +589,13 @@ static void h5_slip_one_byte(struct sk_buff *skb, u8 c)
|
||||
|
||||
switch (c) {
|
||||
case SLIP_DELIMITER:
|
||||
memcpy(skb_put(skb, 2), &esc_delim, 2);
|
||||
skb_put_data(skb, &esc_delim, 2);
|
||||
break;
|
||||
case SLIP_ESC:
|
||||
memcpy(skb_put(skb, 2), &esc_esc, 2);
|
||||
skb_put_data(skb, &esc_esc, 2);
|
||||
break;
|
||||
default:
|
||||
memcpy(skb_put(skb, 1), &c, 1);
|
||||
skb_put_data(skb, &c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -185,7 +185,7 @@ static int intel_lpm_suspend(struct hci_uart *hu)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(skb_put(skb, sizeof(suspend)), suspend, sizeof(suspend));
|
||||
skb_put_data(skb, suspend, sizeof(suspend));
|
||||
hci_skb_pkt_type(skb) = HCI_LPM_PKT;
|
||||
|
||||
set_bit(STATE_LPM_TRANSACTION, &intel->flags);
|
||||
@@ -270,8 +270,7 @@ static int intel_lpm_host_wake(struct hci_uart *hu)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(skb_put(skb, sizeof(lpm_resume_ack)), lpm_resume_ack,
|
||||
sizeof(lpm_resume_ack));
|
||||
skb_put_data(skb, lpm_resume_ack, sizeof(lpm_resume_ack));
|
||||
hci_skb_pkt_type(skb) = HCI_LPM_PKT;
|
||||
|
||||
/* LPM flow is a priority, enqueue packet at list head */
|
||||
@@ -522,7 +521,7 @@ static int intel_set_baudrate(struct hci_uart *hu, unsigned int speed)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(skb_put(skb, sizeof(speed_cmd)), speed_cmd, sizeof(speed_cmd));
|
||||
skb_put_data(skb, speed_cmd, sizeof(speed_cmd));
|
||||
hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
|
||||
|
||||
hci_uart_set_flow_control(hu, true);
|
||||
|
@@ -413,7 +413,7 @@ static int ll_recv(struct hci_uart *hu, const void *data, int count)
|
||||
while (count) {
|
||||
if (ll->rx_count) {
|
||||
len = min_t(unsigned int, ll->rx_count, count);
|
||||
memcpy(skb_put(ll->rx_skb, len), ptr, len);
|
||||
skb_put_data(ll->rx_skb, ptr, len);
|
||||
ll->rx_count -= len; count -= len; ptr += len;
|
||||
|
||||
if (ll->rx_count)
|
||||
|
@@ -328,7 +328,7 @@ static int mrvl_load_firmware(struct hci_dev *hdev, const char *name)
|
||||
}
|
||||
bt_cb(skb)->pkt_type = MRVL_RAW_DATA;
|
||||
|
||||
memcpy(skb_put(skb, mrvl->tx_len), fw_ptr, mrvl->tx_len);
|
||||
skb_put_data(skb, fw_ptr, mrvl->tx_len);
|
||||
fw_ptr += mrvl->tx_len;
|
||||
|
||||
set_bit(STATE_FW_REQ_PENDING, &mrvl->flags);
|
||||
|
@@ -869,7 +869,7 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
|
||||
}
|
||||
|
||||
/* Assign commands to change baudrate and packet type. */
|
||||
memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
|
||||
skb_put_data(skb, cmd, sizeof(cmd));
|
||||
hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
|
||||
|
||||
skb_queue_tail(&qca->txq, skb);
|
||||
|
Reference in New Issue
Block a user