Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 634fef61 authored by Johannes Berg's avatar Johannes Berg Committed by David S. Miller
Browse files

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: default avatarJoe Perches <joe@perches.com>
Suggested-by: default avatarBjørn Mork <bjorn@mork.no>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d58ff351
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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) {
+1 −1
Original line number Diff line number Diff line
@@ -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--;

+1 −1
Original line number Diff line number Diff line
@@ -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) {
+3 −3
Original line number Diff line number Diff line
@@ -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);

+2 −2
Original line number Diff line number Diff line
@@ -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);
Loading