You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
networking: add and use skb_put_u8()
Joe and Bjørn suggested that it'd be nicer to not have the
cast in the fairly common case of doing
*(u8 *)skb_put(skb, 1) = c;
Add skb_put_u8() for this case, and use it across the code,
using the following spatch:
@@
expression SKB, C, S;
typedef u8;
identifier fn = {skb_put};
fresh identifier fn2 = fn ## "_u8";
@@
- *(u8 *)fn(SKB, S) = C;
+ fn2(SKB, C);
Note that due to the "S", the spatch isn't perfect, it should
have checked that S is 1, but there's also places that use a
sizeof expression like sizeof(var) or sizeof(u8) etc. Turns
out that nobody ever did something like
*(u8 *)skb_put(skb, 2) = c;
which would be wrong anyway since the second byte wouldn't be
initialized.
Suggested-by: Joe Perches <joe@perches.com>
Suggested-by: Bjørn Mork <bjorn@mork.no>
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
d58ff35122
commit
634fef6107
@@ -448,7 +448,7 @@ static void bluecard_receive(struct bluecard_info *info,
|
||||
|
||||
} else {
|
||||
|
||||
*(u8 *)skb_put(info->rx_skb, 1) = buf[i];
|
||||
skb_put_u8(info->rx_skb, buf[i]);
|
||||
info->rx_count--;
|
||||
|
||||
if (info->rx_count == 0) {
|
||||
|
||||
@@ -282,7 +282,7 @@ static void bt3c_receive(struct bt3c_info *info)
|
||||
|
||||
__u8 x = inb(iobase + DATA_L);
|
||||
|
||||
*(u8 *)skb_put(info->rx_skb, 1) = x;
|
||||
skb_put_u8(info->rx_skb, x);
|
||||
inb(iobase + DATA_H);
|
||||
info->rx_count--;
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ static void btuart_receive(struct btuart_info *info)
|
||||
|
||||
} else {
|
||||
|
||||
*(u8 *)skb_put(info->rx_skb, 1) = inb(iobase + UART_RX);
|
||||
skb_put_u8(info->rx_skb, inb(iobase + UART_RX));
|
||||
info->rx_count--;
|
||||
|
||||
if (info->rx_count == 0) {
|
||||
|
||||
@@ -1844,7 +1844,7 @@ static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode)
|
||||
evt->ncmd = 0x01;
|
||||
evt->opcode = cpu_to_le16(opcode);
|
||||
|
||||
*(u8 *)skb_put(skb, 1) = 0x00;
|
||||
skb_put_u8(skb, 0x00);
|
||||
|
||||
hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
|
||||
|
||||
@@ -2767,8 +2767,8 @@ static struct urb *alloc_diag_urb(struct hci_dev *hdev, bool enable)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
}
|
||||
|
||||
*(u8 *)skb_put(skb, 1) = 0xf0;
|
||||
*(u8 *)skb_put(skb, 1) = enable;
|
||||
skb_put_u8(skb, 0xf0);
|
||||
skb_put_u8(skb, enable);
|
||||
|
||||
pipe = usb_sndbulkpipe(data->udev, data->diag_tx_ep->bEndpointAddress);
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ static void dtl1_receive(struct dtl1_info *info)
|
||||
}
|
||||
}
|
||||
|
||||
*(u8 *)skb_put(info->rx_skb, 1) = inb(iobase + UART_RX);
|
||||
skb_put_u8(info->rx_skb, inb(iobase + UART_RX));
|
||||
nsh = (struct nsh *)info->rx_skb->data;
|
||||
|
||||
info->rx_count--;
|
||||
@@ -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)
|
||||
*(u8 *)skb_put(s, 1) = 0; /* PAD */
|
||||
skb_put_u8(s, 0); /* PAD */
|
||||
|
||||
/* Prepend skb with Nokia frame header and queue */
|
||||
memcpy(skb_push(s, NSHL), &nsh, NSHL);
|
||||
|
||||
@@ -262,9 +262,9 @@ static int bcm_set_diag(struct hci_dev *hdev, bool enable)
|
||||
if (!skb)
|
||||
return -ENOMEM;
|
||||
|
||||
*(u8 *)skb_put(skb, 1) = BCM_LM_DIAG_PKT;
|
||||
*(u8 *)skb_put(skb, 1) = 0xf0;
|
||||
*(u8 *)skb_put(skb, 1) = enable;
|
||||
skb_put_u8(skb, BCM_LM_DIAG_PKT);
|
||||
skb_put_u8(skb, 0xf0);
|
||||
skb_put_u8(skb, enable);
|
||||
|
||||
skb_queue_tail(&bcm->txq, skb);
|
||||
hci_uart_tx_wakeup(hu);
|
||||
|
||||
@@ -470,7 +470,7 @@ static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode)
|
||||
evt->ncmd = 0x01;
|
||||
evt->opcode = cpu_to_le16(opcode);
|
||||
|
||||
*(u8 *)skb_put(skb, 1) = 0x00;
|
||||
skb_put_u8(skb, 0x00);
|
||||
|
||||
hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
|
||||
|
||||
|
||||
@@ -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;
|
||||
*(u8 *)skb_put(skb, 1) = 0x00;
|
||||
skb_put_u8(skb, 0x00);
|
||||
}
|
||||
|
||||
skb_queue_tail(&btdev->txq, skb);
|
||||
|
||||
@@ -215,7 +215,7 @@ static int send_hci_ibs_cmd(u8 cmd, struct hci_uart *hu)
|
||||
}
|
||||
|
||||
/* Assign HCI_IBS type */
|
||||
*(u8 *)skb_put(skb, 1) = cmd;
|
||||
skb_put_u8(skb, cmd);
|
||||
|
||||
skb_queue_tail(&qca->txq, skb);
|
||||
|
||||
|
||||
@@ -146,8 +146,8 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
|
||||
|
||||
hci_skb_pkt_type(skb) = HCI_VENDOR_PKT;
|
||||
|
||||
*(u8 *)skb_put(skb, 1) = 0xff;
|
||||
*(u8 *)skb_put(skb, 1) = opcode;
|
||||
skb_put_u8(skb, 0xff);
|
||||
skb_put_u8(skb, opcode);
|
||||
put_unaligned_le16(hdev->id, skb_put(skb, 2));
|
||||
skb_queue_tail(&data->readq, skb);
|
||||
|
||||
|
||||
@@ -1082,7 +1082,7 @@ static int capinc_tty_put_char(struct tty_struct *tty, unsigned char ch)
|
||||
skb = mp->outskb;
|
||||
if (skb) {
|
||||
if (skb_tailroom(skb) > 0) {
|
||||
*(u8 *)skb_put(skb, 1) = ch;
|
||||
skb_put_u8(skb, ch);
|
||||
goto unlock_out;
|
||||
}
|
||||
mp->outskb = NULL;
|
||||
@@ -1094,7 +1094,7 @@ static int capinc_tty_put_char(struct tty_struct *tty, unsigned char ch)
|
||||
skb = alloc_skb(CAPI_DATA_B3_REQ_LEN + CAPI_MAX_BLKSIZE, GFP_ATOMIC);
|
||||
if (skb) {
|
||||
skb_reserve(skb, CAPI_DATA_B3_REQ_LEN);
|
||||
*(u8 *)skb_put(skb, 1) = ch;
|
||||
skb_put_u8(skb, ch);
|
||||
mp->outskb = skb;
|
||||
} else {
|
||||
printk(KERN_ERR "capinc_put_char: char %u lost\n", ch);
|
||||
|
||||
@@ -492,33 +492,33 @@ static struct sk_buff *HDLC_Encode(struct sk_buff *skb)
|
||||
hdlc_skb->mac_len = skb->mac_len;
|
||||
|
||||
/* Add flag sequence in front of everything.. */
|
||||
*(u8 *)skb_put(hdlc_skb, 1) = PPP_FLAG;
|
||||
skb_put_u8(hdlc_skb, PPP_FLAG);
|
||||
|
||||
/* Perform byte stuffing while copying data. */
|
||||
while (skb->len--) {
|
||||
if (muststuff(*skb->data)) {
|
||||
*(u8 *)skb_put(hdlc_skb, 1) = PPP_ESCAPE;
|
||||
*(u8 *)skb_put(hdlc_skb, 1) = (*skb->data++) ^ PPP_TRANS;
|
||||
skb_put_u8(hdlc_skb, PPP_ESCAPE);
|
||||
skb_put_u8(hdlc_skb, (*skb->data++) ^ PPP_TRANS);
|
||||
} else
|
||||
*(u8 *)skb_put(hdlc_skb, 1) = *skb->data++;
|
||||
skb_put_u8(hdlc_skb, *skb->data++);
|
||||
}
|
||||
|
||||
/* Finally add FCS (byte stuffed) and flag sequence */
|
||||
c = (fcs & 0x00ff); /* least significant byte first */
|
||||
if (muststuff(c)) {
|
||||
*(u8 *)skb_put(hdlc_skb, 1) = PPP_ESCAPE;
|
||||
skb_put_u8(hdlc_skb, PPP_ESCAPE);
|
||||
c ^= PPP_TRANS;
|
||||
}
|
||||
*(u8 *)skb_put(hdlc_skb, 1) = c;
|
||||
skb_put_u8(hdlc_skb, c);
|
||||
|
||||
c = ((fcs >> 8) & 0x00ff);
|
||||
if (muststuff(c)) {
|
||||
*(u8 *)skb_put(hdlc_skb, 1) = PPP_ESCAPE;
|
||||
skb_put_u8(hdlc_skb, PPP_ESCAPE);
|
||||
c ^= PPP_TRANS;
|
||||
}
|
||||
*(u8 *)skb_put(hdlc_skb, 1) = c;
|
||||
skb_put_u8(hdlc_skb, c);
|
||||
|
||||
*(u8 *)skb_put(hdlc_skb, 1) = PPP_FLAG;
|
||||
skb_put_u8(hdlc_skb, PPP_FLAG);
|
||||
|
||||
dev_kfree_skb_any(skb);
|
||||
return hdlc_skb;
|
||||
@@ -561,8 +561,8 @@ static struct sk_buff *iraw_encode(struct sk_buff *skb)
|
||||
while (len--) {
|
||||
c = bitrev8(*cp++);
|
||||
if (c == DLE_FLAG)
|
||||
*(u8 *)skb_put(iraw_skb, 1) = c;
|
||||
*(u8 *)skb_put(iraw_skb, 1) = c;
|
||||
skb_put_u8(iraw_skb, c);
|
||||
skb_put_u8(iraw_skb, c);
|
||||
}
|
||||
dev_kfree_skb_any(skb);
|
||||
return iraw_skb;
|
||||
|
||||
@@ -602,7 +602,8 @@ static int bsd_compress(void *state, struct sk_buff *skb_in, struct sk_buff *skb
|
||||
* Do not emit a completely useless byte of ones.
|
||||
*/
|
||||
if (bitno < 32 && skb_out && skb_tailroom(skb_out) > 0)
|
||||
*(u8 *)skb_put(skb_out, 1) = (unsigned char)((accm | (0xff << (bitno - 8))) >> 24);
|
||||
skb_put_u8(skb_out,
|
||||
(unsigned char)((accm | (0xff << (bitno - 8))) >> 24));
|
||||
|
||||
/*
|
||||
* Increase code size if we would have without the packet
|
||||
@@ -698,7 +699,7 @@ static int bsd_decompress(void *state, struct sk_buff *skb_in, struct sk_buff *s
|
||||
db->bytes_out += ilen;
|
||||
|
||||
if (skb_tailroom(skb_out) > 0)
|
||||
*(u8 *)skb_put(skb_out, 1) = 0;
|
||||
skb_put_u8(skb_out, 0);
|
||||
else
|
||||
return DECOMP_ERR_NOMEM;
|
||||
|
||||
@@ -816,7 +817,7 @@ static int bsd_decompress(void *state, struct sk_buff *skb_in, struct sk_buff *s
|
||||
#endif
|
||||
|
||||
if (extra) /* the KwKwK case again */
|
||||
*(u8 *)skb_put(skb_out, 1) = finchar;
|
||||
skb_put_u8(skb_out, finchar);
|
||||
|
||||
/*
|
||||
* If not first code in a packet, and
|
||||
|
||||
@@ -224,7 +224,7 @@ static int isdn_x25iface_connect_ind(struct concap_proto *cprot)
|
||||
|
||||
skb = dev_alloc_skb(1);
|
||||
if (skb) {
|
||||
*(u8 *)skb_put(skb, 1) = X25_IFACE_CONNECT;
|
||||
skb_put_u8(skb, X25_IFACE_CONNECT);
|
||||
skb->protocol = x25_type_trans(skb, cprot->net_dev);
|
||||
netif_rx(skb);
|
||||
return 0;
|
||||
@@ -253,7 +253,7 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *cprot)
|
||||
*state_p = WAN_DISCONNECTED;
|
||||
skb = dev_alloc_skb(1);
|
||||
if (skb) {
|
||||
*(u8 *)skb_put(skb, 1) = X25_IFACE_DISCONNECT;
|
||||
skb_put_u8(skb, X25_IFACE_DISCONNECT);
|
||||
skb->protocol = x25_type_trans(skb, cprot->net_dev);
|
||||
netif_rx(skb);
|
||||
return 0;
|
||||
|
||||
@@ -540,7 +540,7 @@ static inline void scc_rxint(struct scc_channel *scc)
|
||||
}
|
||||
|
||||
scc->rx_buff = skb;
|
||||
*(u8 *)skb_put(skb, 1) = 0; /* KISS data */
|
||||
skb_put_u8(skb, 0); /* KISS data */
|
||||
}
|
||||
|
||||
if (skb->len >= scc->stat.bufsize)
|
||||
@@ -555,7 +555,7 @@ static inline void scc_rxint(struct scc_channel *scc)
|
||||
return;
|
||||
}
|
||||
|
||||
*(u8 *)skb_put(skb, 1) = Inb(scc->data);
|
||||
skb_put_u8(skb, Inb(scc->data));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1250,7 +1250,7 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
|
||||
skb_put_zero(skb_out, padding_count);
|
||||
} else if (skb_out->len < ctx->tx_max &&
|
||||
(skb_out->len % dev->maxpacket) == 0) {
|
||||
*(u8 *)skb_put(skb_out, 1) = 0; /* force short packet */
|
||||
skb_put_u8(skb_out, 0); /* force short packet */
|
||||
}
|
||||
|
||||
/* set final frame length */
|
||||
|
||||
@@ -473,7 +473,7 @@ encapsulate:
|
||||
|
||||
/* maybe pad; then trailer */
|
||||
if (!((skb->len + sizeof *trailer) & 0x01))
|
||||
*(u8 *)skb_put(skb, 1) = PAD_BYTE;
|
||||
skb_put_u8(skb, PAD_BYTE);
|
||||
trailer = skb_put(skb, sizeof *trailer);
|
||||
put_unaligned(header->packet_id, &trailer->packet_id);
|
||||
#if 0
|
||||
|
||||
@@ -74,10 +74,10 @@ done:
|
||||
fcs = crc32_le(~0, skb->data, skb->len);
|
||||
fcs = ~fcs;
|
||||
|
||||
*(u8 *)skb_put(skb, 1) = fcs & 0xff;
|
||||
*(u8 *)skb_put(skb, 1) = (fcs>> 8) & 0xff;
|
||||
*(u8 *)skb_put(skb, 1) = (fcs>>16) & 0xff;
|
||||
*(u8 *)skb_put(skb, 1) = (fcs>>24) & 0xff;
|
||||
skb_put_u8(skb, fcs & 0xff);
|
||||
skb_put_u8(skb, (fcs >> 8) & 0xff);
|
||||
skb_put_u8(skb, (fcs >> 16) & 0xff);
|
||||
skb_put_u8(skb, (fcs >> 24) & 0xff);
|
||||
}
|
||||
return skb;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ static void fdp_nci_i2c_add_len_lrc(struct sk_buff *skb)
|
||||
for (i = 0; i < len + 2; i++)
|
||||
lrc ^= skb->data[i];
|
||||
|
||||
*(u8 *)skb_put(skb, 1) = lrc;
|
||||
skb_put_u8(skb, lrc);
|
||||
}
|
||||
|
||||
static void fdp_nci_i2c_remove_len_lrc(struct sk_buff *skb)
|
||||
|
||||
@@ -75,7 +75,7 @@ static void microread_i2c_add_len_crc(struct sk_buff *skb)
|
||||
for (i = 0; i < skb->len; i++)
|
||||
crc = crc ^ skb->data[i];
|
||||
|
||||
*(u8 *)skb_put(skb, 1) = crc;
|
||||
skb_put_u8(skb, crc);
|
||||
}
|
||||
|
||||
static void microread_i2c_remove_len_crc(struct sk_buff *skb)
|
||||
@@ -173,7 +173,7 @@ static int microread_i2c_read(struct microread_i2c_phy *phy,
|
||||
goto flush;
|
||||
}
|
||||
|
||||
*(u8 *)skb_put(*skb, 1) = len;
|
||||
skb_put_u8(*skb, len);
|
||||
|
||||
r = i2c_master_recv(client, skb_put(*skb, len), len);
|
||||
if (r != len) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user