Skip to content

Commit

Permalink
networking: make skb_put & friends return void pointers
Browse files Browse the repository at this point in the history
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.

Make these functions (skb_put, __skb_put and pskb_put) return void *
and remove all the casts across the tree, adding a (u8 *) cast only
where the unsigned char pointer was used directly, all done with the
following spatch:

    @@
    expression SKB, LEN;
    typedef u8;
    identifier fn = { skb_put, __skb_put };
    @@
    - *(fn(SKB, LEN))
    + *(u8 *)fn(SKB, LEN)

    @@
    expression E, SKB, LEN;
    identifier fn = { skb_put, __skb_put };
    type T;
    @@
    - E = ((T *)(fn(SKB, LEN)))
    + E = fn(SKB, LEN)

which actually doesn't cover pskb_put since there are only three
users overall.

A handful of stragglers were converted manually, notably a macro in
drivers/isdn/i4l/isdn_bsdcomp.c and, oddly enough, one of the many
instances in net/bluetooth/hci_sock.c. In the former file, I also
had to fix one whitespace problem spatch introduced.

Signed-off-by: Johannes Berg <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
jmberg-intel authored and davem330 committed Jun 16, 2017
1 parent 59ae1d1 commit 4df864c
Show file tree
Hide file tree
Showing 145 changed files with 486 additions and 547 deletions.
4 changes: 2 additions & 2 deletions drivers/atm/atmtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static int atmtcp_send_control(struct atm_vcc *vcc,int type,
return -EUNATCH;
}
atm_force_charge(out_vcc,skb->truesize);
new_msg = (struct atmtcp_control *) skb_put(skb,sizeof(*new_msg));
new_msg = skb_put(skb, sizeof(*new_msg));
*new_msg = *msg;
new_msg->hdr.length = ATMTCP_HDR_MAGIC;
new_msg->type = type;
Expand Down Expand Up @@ -217,7 +217,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
atomic_inc(&vcc->stats->tx_err);
return -ENOBUFS;
}
hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
hdr = skb_put(new_skb, sizeof(struct atmtcp_hdr));
hdr->vpi = htons(vcc->vpi);
hdr->vci = htons(vcc->vci);
hdr->length = htonl(skb->len);
Expand Down
12 changes: 6 additions & 6 deletions drivers/atm/solos-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static ssize_t solos_param_show(struct device *dev, struct device_attribute *att
return -ENOMEM;
}

header = (void *)skb_put(skb, sizeof(*header));
header = skb_put(skb, sizeof(*header));

buflen = snprintf((void *)&header[1], buflen - 1,
"L%05d\n%s\n", current->pid, attr->attr.name);
Expand Down Expand Up @@ -261,7 +261,7 @@ static ssize_t solos_param_store(struct device *dev, struct device_attribute *at
return -ENOMEM;
}

header = (void *)skb_put(skb, sizeof(*header));
header = skb_put(skb, sizeof(*header));

buflen = snprintf((void *)&header[1], buflen - 1,
"L%05d\n%s\n%s\n", current->pid, attr->attr.name, buf);
Expand Down Expand Up @@ -486,7 +486,7 @@ static int send_command(struct solos_card *card, int dev, const char *buf, size_
return 0;
}

header = (void *)skb_put(skb, sizeof(*header));
header = skb_put(skb, sizeof(*header));

header->size = cpu_to_le16(size);
header->vpi = cpu_to_le16(0);
Expand Down Expand Up @@ -945,7 +945,7 @@ static int popen(struct atm_vcc *vcc)
dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
return -ENOMEM;
}
header = (void *)skb_put(skb, sizeof(*header));
header = skb_put(skb, sizeof(*header));

header->size = cpu_to_le16(0);
header->vpi = cpu_to_le16(vcc->vpi);
Expand Down Expand Up @@ -982,7 +982,7 @@ static void pclose(struct atm_vcc *vcc)
dev_warn(&card->dev->dev, "Failed to allocate sk_buff in pclose()\n");
return;
}
header = (void *)skb_put(skb, sizeof(*header));
header = skb_put(skb, sizeof(*header));

header->size = cpu_to_le16(0);
header->vpi = cpu_to_le16(vcc->vpi);
Expand Down Expand Up @@ -1398,7 +1398,7 @@ static int atm_init(struct solos_card *card, struct device *parent)
continue;
}

header = (void *)skb_put(skb, sizeof(*header));
header = skb_put(skb, sizeof(*header));

header->size = cpu_to_le16(0);
header->vpi = cpu_to_le16(0);
Expand Down
2 changes: 1 addition & 1 deletion drivers/bluetooth/bluecard_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ static void bluecard_receive(struct bluecard_info *info,

} else {

*skb_put(info->rx_skb, 1) = buf[i];
*(u8 *)skb_put(info->rx_skb, 1) = buf[i];
info->rx_count--;

if (info->rx_count == 0) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/bluetooth/bt3c_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static void bt3c_receive(struct bt3c_info *info)

__u8 x = inb(iobase + DATA_L);

*skb_put(info->rx_skb, 1) = x;
*(u8 *)skb_put(info->rx_skb, 1) = x;
inb(iobase + DATA_H);
info->rx_count--;

Expand Down
2 changes: 1 addition & 1 deletion drivers/bluetooth/btmrvl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static int btmrvl_send_sync_cmd(struct btmrvl_private *priv, u16 opcode,
return -ENOMEM;
}

hdr = (struct hci_command_hdr *)skb_put(skb, HCI_COMMAND_HDR_SIZE);
hdr = skb_put(skb, HCI_COMMAND_HDR_SIZE);
hdr->opcode = cpu_to_le16(opcode);
hdr->plen = len;

Expand Down
2 changes: 1 addition & 1 deletion drivers/bluetooth/btuart_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static void btuart_receive(struct btuart_info *info)

} else {

*skb_put(info->rx_skb, 1) = inb(iobase + UART_RX);
*(u8 *)skb_put(info->rx_skb, 1) = inb(iobase + UART_RX);
info->rx_count--;

if (info->rx_count == 0) {
Expand Down
10 changes: 5 additions & 5 deletions drivers/bluetooth/btusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1836,15 +1836,15 @@ static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode)
if (!skb)
return -ENOMEM;

hdr = (struct hci_event_hdr *)skb_put(skb, sizeof(*hdr));
hdr = skb_put(skb, sizeof(*hdr));
hdr->evt = HCI_EV_CMD_COMPLETE;
hdr->plen = sizeof(*evt) + 1;

evt = (struct hci_ev_cmd_complete *)skb_put(skb, sizeof(*evt));
evt = skb_put(skb, sizeof(*evt));
evt->ncmd = 0x01;
evt->opcode = cpu_to_le16(opcode);

*skb_put(skb, 1) = 0x00;
*(u8 *)skb_put(skb, 1) = 0x00;

hci_skb_pkt_type(skb) = HCI_EVENT_PKT;

Expand Down Expand Up @@ -2767,8 +2767,8 @@ static struct urb *alloc_diag_urb(struct hci_dev *hdev, bool enable)
return ERR_PTR(-ENOMEM);
}

*skb_put(skb, 1) = 0xf0;
*skb_put(skb, 1) = enable;
*(u8 *)skb_put(skb, 1) = 0xf0;
*(u8 *)skb_put(skb, 1) = enable;

pipe = usb_sndbulkpipe(data->udev, data->diag_tx_ep->bEndpointAddress);

Expand Down
4 changes: 2 additions & 2 deletions drivers/bluetooth/dtl1_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static void dtl1_receive(struct dtl1_info *info)
}
}

*skb_put(info->rx_skb, 1) = inb(iobase + UART_RX);
*(u8 *)skb_put(info->rx_skb, 1) = inb(iobase + UART_RX);
nsh = (struct nsh *)info->rx_skb->data;

info->rx_count--;
Expand Down Expand Up @@ -414,7 +414,7 @@ static int dtl1_hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
skb_reserve(s, NSHL);
skb_copy_from_linear_data(skb, skb_put(s, skb->len), skb->len);
if (skb->len & 0x0001)
*skb_put(s, 1) = 0; /* PAD */
*(u8 *)skb_put(s, 1) = 0; /* PAD */

/* Prepend skb with Nokia frame header and queue */
memcpy(skb_push(s, NSHL), &nsh, NSHL);
Expand Down
6 changes: 3 additions & 3 deletions drivers/bluetooth/hci_bcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ static int bcm_set_diag(struct hci_dev *hdev, bool enable)
if (!skb)
return -ENOMEM;

*skb_put(skb, 1) = BCM_LM_DIAG_PKT;
*skb_put(skb, 1) = 0xf0;
*skb_put(skb, 1) = enable;
*(u8 *)skb_put(skb, 1) = BCM_LM_DIAG_PKT;
*(u8 *)skb_put(skb, 1) = 0xf0;
*(u8 *)skb_put(skb, 1) = enable;

skb_queue_tail(&bcm->txq, skb);
hci_uart_tx_wakeup(hu);
Expand Down
6 changes: 3 additions & 3 deletions drivers/bluetooth/hci_intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,15 +462,15 @@ static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode)
if (!skb)
return -ENOMEM;

hdr = (struct hci_event_hdr *)skb_put(skb, sizeof(*hdr));
hdr = skb_put(skb, sizeof(*hdr));
hdr->evt = HCI_EV_CMD_COMPLETE;
hdr->plen = sizeof(*evt) + 1;

evt = (struct hci_ev_cmd_complete *)skb_put(skb, sizeof(*evt));
evt = skb_put(skb, sizeof(*evt));
evt->ncmd = 0x01;
evt->opcode = cpu_to_le16(opcode);

*skb_put(skb, 1) = 0x00;
*(u8 *)skb_put(skb, 1) = 0x00;

hci_skb_pkt_type(skb) = HCI_EVENT_PKT;

Expand Down
2 changes: 1 addition & 1 deletion drivers/bluetooth/hci_ll.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static int send_hcill_cmd(u8 cmd, struct hci_uart *hu)
}

/* prepare packet */
hcill_packet = (struct hcill_cmd *) skb_put(skb, 1);
hcill_packet = skb_put(skb, 1);
hcill_packet->cmd = cmd;

/* send packet */
Expand Down
10 changes: 5 additions & 5 deletions drivers/bluetooth/hci_nokia.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ static int nokia_send_alive_packet(struct hci_uart *hu)
hci_skb_pkt_type(skb) = HCI_NOKIA_ALIVE_PKT;
memset(skb->data, 0x00, len);

hdr = (struct hci_nokia_alive_hdr *)skb_put(skb, sizeof(*hdr));
hdr = skb_put(skb, sizeof(*hdr));
hdr->dlen = sizeof(*pkt);
pkt = (struct hci_nokia_alive_pkt *)skb_put(skb, sizeof(*pkt));
pkt = skb_put(skb, sizeof(*pkt));
pkt->mid = NOKIA_ALIVE_REQ;

nokia_enqueue(hu, skb);
Expand Down Expand Up @@ -285,10 +285,10 @@ static int nokia_send_negotiation(struct hci_uart *hu)

hci_skb_pkt_type(skb) = HCI_NOKIA_NEG_PKT;

neg_hdr = (struct hci_nokia_neg_hdr *)skb_put(skb, sizeof(*neg_hdr));
neg_hdr = skb_put(skb, sizeof(*neg_hdr));
neg_hdr->dlen = sizeof(*neg_cmd);

neg_cmd = (struct hci_nokia_neg_cmd *)skb_put(skb, sizeof(*neg_cmd));
neg_cmd = skb_put(skb, sizeof(*neg_cmd));
neg_cmd->ack = NOKIA_NEG_REQ;
neg_cmd->baud = cpu_to_le16(baud);
neg_cmd->unused1 = 0x0000;
Expand Down Expand Up @@ -532,7 +532,7 @@ static int nokia_enqueue(struct hci_uart *hu, struct sk_buff *skb)
err = skb_pad(skb, 1);
if (err)
return err;
*skb_put(skb, 1) = 0x00;
*(u8 *)skb_put(skb, 1) = 0x00;
}

skb_queue_tail(&btdev->txq, skb);
Expand Down
2 changes: 1 addition & 1 deletion drivers/bluetooth/hci_qca.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static int send_hci_ibs_cmd(u8 cmd, struct hci_uart *hu)
}

/* Assign HCI_IBS type */
*skb_put(skb, 1) = cmd;
*(u8 *)skb_put(skb, 1) = cmd;

skb_queue_tail(&qca->txq, skb);

Expand Down
4 changes: 2 additions & 2 deletions drivers/bluetooth/hci_vhci.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode)

hci_skb_pkt_type(skb) = HCI_VENDOR_PKT;

*skb_put(skb, 1) = 0xff;
*skb_put(skb, 1) = opcode;
*(u8 *)skb_put(skb, 1) = 0xff;
*(u8 *)skb_put(skb, 1) = opcode;
put_unaligned_le16(hdev->id, skb_put(skb, 2));
skb_queue_tail(&data->readq, skb);

Expand Down
10 changes: 5 additions & 5 deletions drivers/crypto/chelsio/chcr_algo.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ static struct sk_buff
if (!skb)
return ERR_PTR(-ENOMEM);
skb_reserve(skb, sizeof(struct sge_opaque_hdr));
chcr_req = (struct chcr_wr *)__skb_put(skb, transhdr_len);
chcr_req = __skb_put(skb, transhdr_len);
memset(chcr_req, 0, transhdr_len);
chcr_req->sec_cpl.op_ivinsrtofst =
FILL_SEC_CPL_OP_IVINSR(ctx->dev->rx_channel_id, 2, 1);
Expand Down Expand Up @@ -881,7 +881,7 @@ static struct sk_buff *create_hash_wr(struct ahash_request *req,
return skb;

skb_reserve(skb, sizeof(struct sge_opaque_hdr));
chcr_req = (struct chcr_wr *)__skb_put(skb, transhdr_len);
chcr_req = __skb_put(skb, transhdr_len);
memset(chcr_req, 0, transhdr_len);

chcr_req->sec_cpl.op_ivinsrtofst =
Expand Down Expand Up @@ -1447,7 +1447,7 @@ static struct sk_buff *create_authenc_wr(struct aead_request *req,
skb_reserve(skb, sizeof(struct sge_opaque_hdr));

/* Write WR */
chcr_req = (struct chcr_wr *) __skb_put(skb, transhdr_len);
chcr_req = __skb_put(skb, transhdr_len);
memset(chcr_req, 0, transhdr_len);

stop_offset = (op_type == CHCR_ENCRYPT_OP) ? 0 : authsize;
Expand Down Expand Up @@ -1779,7 +1779,7 @@ static struct sk_buff *create_aead_ccm_wr(struct aead_request *req,

skb_reserve(skb, sizeof(struct sge_opaque_hdr));

chcr_req = (struct chcr_wr *) __skb_put(skb, transhdr_len);
chcr_req = __skb_put(skb, transhdr_len);
memset(chcr_req, 0, transhdr_len);

fill_sec_cpl_for_aead(&chcr_req->sec_cpl, dst_size, req, op_type, ctx);
Expand Down Expand Up @@ -1892,7 +1892,7 @@ static struct sk_buff *create_gcm_wr(struct aead_request *req,
/* NIC driver is going to write the sge hdr. */
skb_reserve(skb, sizeof(struct sge_opaque_hdr));

chcr_req = (struct chcr_wr *)__skb_put(skb, transhdr_len);
chcr_req = __skb_put(skb, transhdr_len);
memset(chcr_req, 0, transhdr_len);

if (get_aead_subtype(tfm) == CRYPTO_ALG_SUB_TYPE_AEAD_RFC4106)
Expand Down
3 changes: 1 addition & 2 deletions drivers/infiniband/core/addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ static int ib_nl_ip_send_msg(struct rdma_dev_addr *dev_addr,
}

/* Construct the family header first */
header = (struct rdma_ls_ip_resolve_header *)
skb_put(skb, NLMSG_ALIGN(sizeof(*header)));
header = skb_put(skb, NLMSG_ALIGN(sizeof(*header)));
header->ifindex = dev_addr->bound_dev_if;
nla_put(skb, attrtype, size, daddr);

Expand Down
3 changes: 1 addition & 2 deletions drivers/infiniband/core/sa_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,7 @@ static void ib_nl_set_path_rec_attrs(struct sk_buff *skb,
query->mad_buf->context[1] = NULL;

/* Construct the family header first */
header = (struct rdma_ls_resolve_header *)
skb_put(skb, NLMSG_ALIGN(sizeof(*header)));
header = skb_put(skb, NLMSG_ALIGN(sizeof(*header)));
memcpy(header->device_name, query->port->agent->device->name,
LS_DEVICE_NAME_MAX);
header->port_num = query->port->port_num;
Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/hw/cxgb3/cxio_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ int cxio_rdma_init(struct cxio_rdev *rdev_p, struct t3_rdma_init_attr *attr)
if (!skb)
return -ENOMEM;
pr_debug("%s rdev_p %p\n", __func__, rdev_p);
wqe = (struct t3_rdma_init_wr *) __skb_put(skb, sizeof(*wqe));
wqe = __skb_put(skb, sizeof(*wqe));
wqe->wrh.op_seop_flags = cpu_to_be32(V_FW_RIWR_OP(T3_WR_INIT));
wqe->wrh.gen_tid_len = cpu_to_be32(V_FW_RIWR_TID(attr->tid) |
V_FW_RIWR_LEN(sizeof(*wqe) >> 3));
Expand Down
Loading

0 comments on commit 4df864c

Please sign in to comment.