Skip to content

Commit

Permalink
[SK_BUFF]: Introduce skb_copy_to_linear_data{_offset}
Browse files Browse the repository at this point in the history
To clearly state the intent of copying to linear sk_buffs, _offset being a
overly long variant but interesting for the sake of saving some bytes.

Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
Arnaldo Carvalho de Melo authored and David S. Miller committed Apr 26, 2007
1 parent 3dbad80 commit 27d7ff4
Show file tree
Hide file tree
Showing 63 changed files with 185 additions and 127 deletions.
2 changes: 1 addition & 1 deletion arch/ia64/hp/sim/simeth.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ simeth_rx(struct net_device *dev)
* XXX Fix me
* Should really do a csum+copy here
*/
memcpy(skb->data, frame, len);
skb_copy_to_linear_data(skb, frame, len);
#endif
skb->protocol = eth_type_trans(skb, dev);

Expand Down
2 changes: 1 addition & 1 deletion arch/ia64/sn/kernel/xpnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ xpnet_receive(partid_t partid, int channel, struct xpnet_message *msg)
"%lu)\n", skb->data, &msg->data,
(size_t) msg->embedded_bytes);

memcpy(skb->data, &msg->data, (size_t) msg->embedded_bytes);
skb_copy_to_linear_data(skb, &msg->data, (size_t)msg->embedded_bytes);
} else {
dev_dbg(xpnet, "transferring buffer to the skb->data area;\n\t"
"bte_copy(0x%p, 0x%p, %hu)\n", (void *)msg->buf_pa,
Expand Down
3 changes: 2 additions & 1 deletion drivers/isdn/hysdn/hycapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ static u16 hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb)
if (_len > 22) {
_len2 = _len - 22;
skb_copy_from_linear_data(skb, msghead, 22);
memcpy(skb->data + _len2, msghead, 22);
skb_copy_to_linear_data_offset(skb, _len2,
msghead, 22);
skb_pull(skb, _len2);
CAPIMSG_SETLEN(skb->data, 22);
retval = capilib_data_b3_req(&cinfo->ncci_head,
Expand Down
6 changes: 3 additions & 3 deletions drivers/net/8139too.c
Original file line number Diff line number Diff line change
Expand Up @@ -1904,10 +1904,10 @@ static __inline__ void wrap_copy(struct sk_buff *skb, const unsigned char *ring,
u32 left = RX_BUF_LEN - offset;

if (size > left) {
memcpy(skb->data, ring + offset, left);
memcpy(skb->data+left, ring, size - left);
skb_copy_to_linear_data(skb, ring + offset, left);
skb_copy_to_linear_data_offset(skb, left, ring, size - left);
} else
memcpy(skb->data, ring + offset, size);
skb_copy_to_linear_data(skb, ring + offset, size);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/appletalk/ltpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ static int sendup_buffer (struct net_device *dev)
skb_pull(skb,3);

/* copy ddp(s,e)hdr + contents */
memcpy(skb->data,(void*)ltdmabuf,len);
skb_copy_to_linear_data(skb, ltdmabuf, len);

skb_reset_transport_header(skb);

Expand Down
3 changes: 2 additions & 1 deletion drivers/net/atari_bionet.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ bionet_poll_rx(struct net_device *dev) {

/* 'skb->data' points to the start of sk_buff data area.
*/
memcpy(skb->data, nic_packet->buffer, pkt_len);
skb_copy_to_linear_data(skb, nic_packet->buffer,
pkt_len);
skb->protocol = eth_type_trans( skb, dev );
netif_rx(skb);
dev->last_rx = jiffies;
Expand Down
3 changes: 2 additions & 1 deletion drivers/net/atari_pamsnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,8 @@ pamsnet_poll_rx(struct net_device *dev) {

/* 'skb->data' points to the start of sk_buff data area.
*/
memcpy(skb->data, nic_packet->buffer, pkt_len);
skb_copy_to_linear_data(skb, nic_packet->buffer,
pkt_len);
netif_rx(skb);
dev->last_rx = jiffies;
lp->stats.rx_packets++;
Expand Down
24 changes: 16 additions & 8 deletions drivers/net/chelsio/sge.c
Original file line number Diff line number Diff line change
Expand Up @@ -2095,10 +2095,14 @@ static void espibug_workaround_t204(unsigned long data)
0x0, 0x7, 0x43, 0x0, 0x0, 0x0
};

memcpy(skb->data + sizeof(struct cpl_tx_pkt),
ch_mac_addr, ETH_ALEN);
memcpy(skb->data + skb->len - 10,
ch_mac_addr, ETH_ALEN);
skb_copy_to_linear_data_offset(skb,
sizeof(struct cpl_tx_pkt),
ch_mac_addr,
ETH_ALEN);
skb_copy_to_linear_data_offset(skb,
skb->len - 10,
ch_mac_addr,
ETH_ALEN);
skb->cb[0] = 0xff;
}

Expand All @@ -2125,10 +2129,14 @@ static void espibug_workaround(unsigned long data)
if (!skb->cb[0]) {
u8 ch_mac_addr[ETH_ALEN] =
{0x0, 0x7, 0x43, 0x0, 0x0, 0x0};
memcpy(skb->data + sizeof(struct cpl_tx_pkt),
ch_mac_addr, ETH_ALEN);
memcpy(skb->data + skb->len - 10, ch_mac_addr,
ETH_ALEN);
skb_copy_to_linear_data_offset(skb,
sizeof(struct cpl_tx_pkt),
ch_mac_addr,
ETH_ALEN);
skb_copy_to_linear_data_offset(skb,
skb->len - 10,
ch_mac_addr,
ETH_ALEN);
skb->cb[0] = 0xff;
}

Expand Down
6 changes: 3 additions & 3 deletions drivers/net/cxgb3/sge.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ static inline struct sk_buff *get_imm_packet(const struct rsp_desc *resp)

if (skb) {
__skb_put(skb, IMMED_PKT_SIZE);
memcpy(skb->data, resp->imm_data, IMMED_PKT_SIZE);
skb_copy_to_linear_data(skb, resp->imm_data, IMMED_PKT_SIZE);
}
return skb;
}
Expand Down Expand Up @@ -1722,11 +1722,11 @@ static void skb_data_init(struct sk_buff *skb, struct sge_fl_page *p,
{
skb->len = len;
if (len <= SKB_DATA_SIZE) {
memcpy(skb->data, p->va, len);
skb_copy_to_linear_data(skb, p->va, len);
skb->tail += len;
put_page(p->frag.page);
} else {
memcpy(skb->data, p->va, SKB_DATA_SIZE);
skb_copy_to_linear_data(skb, p->va, SKB_DATA_SIZE);
skb_shinfo(skb)->frags[0].page = p->frag.page;
skb_shinfo(skb)->frags[0].page_offset =
p->frag.page_offset + SKB_DATA_SIZE;
Expand Down
4 changes: 3 additions & 1 deletion drivers/net/defxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -3091,7 +3091,9 @@ static void dfx_rcv_queue_process(
{
/* Receive buffer allocated, pass receive packet up */

memcpy(skb->data, p_buff + RCV_BUFF_K_PADDING, pkt_len+3);
skb_copy_to_linear_data(skb,
p_buff + RCV_BUFF_K_PADDING,
pkt_len + 3);
}

skb_reserve(skb,3); /* adjust data field so that it points to FC byte */
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/e100.c
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,7 @@ static int e100_rx_alloc_skb(struct nic *nic, struct rx *rx)

/* Align, init, and map the RFD. */
skb_reserve(rx->skb, NET_IP_ALIGN);
memcpy(rx->skb->data, &nic->blank_rfd, sizeof(struct rfd));
skb_copy_to_linear_data(rx->skb, &nic->blank_rfd, sizeof(struct rfd));
rx->dma_addr = pci_map_single(nic->pdev, rx->skb->data,
RFD_BUF_LEN, PCI_DMA_BIDIRECTIONAL);

Expand Down
9 changes: 6 additions & 3 deletions drivers/net/e1000/e1000_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4224,9 +4224,12 @@ e1000_clean_rx_irq(struct e1000_adapter *adapter,
netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
if (new_skb) {
skb_reserve(new_skb, NET_IP_ALIGN);
memcpy(new_skb->data - NET_IP_ALIGN,
skb->data - NET_IP_ALIGN,
length + NET_IP_ALIGN);
skb_copy_to_linear_data_offset(new_skb,
-NET_IP_ALIGN,
(skb->data -
NET_IP_ALIGN),
(length +
NET_IP_ALIGN));
/* save the skb in buffer_info as good */
buffer_info->skb = skb;
skb = new_skb;
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/ehea/ehea_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ static int ehea_poll(struct net_device *dev, int *budget)
if (!skb)
break;
}
memcpy(skb->data, ((char*)cqe) + 64,
cqe->num_bytes_transfered - 4);
skb_copy_to_linear_data(skb, ((char*)cqe) + 64,
cqe->num_bytes_transfered - 4);
ehea_fill_skb(dev, skb, cqe);
} else if (rq == 2) { /* RQ2 */
skb = get_skb_by_index(skb_arr_rq2,
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/irda/ali-ircc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ static int ali_ircc_dma_receive_complete(struct ali_ircc_cb *self)

/* Copy frame without CRC, CRC is removed by hardware*/
skb_put(skb, len);
memcpy(skb->data, self->rx_buff.data, len);
skb_copy_to_linear_data(skb, self->rx_buff.data, len);

/* Move to next frame */
self->rx_buff.data += len;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/irda/au1k_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ static int au1k_irda_rx(struct net_device *dev)
skb_put(skb, count);
else
skb_put(skb, count-2);
memcpy(skb->data, (void *)pDB->vaddr, count-2);
skb_copy_to_linear_data(skb, pDB->vaddr, count - 2);
skb->dev = dev;
skb_reset_mac_header(skb);
skb->protocol = htons(ETH_P_IRDA);
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/irda/donauboe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1282,8 +1282,8 @@ dumpbufs(self->rx_bufs[self->rxs],len,'<');
skb_reserve (skb, 1);

skb_put (skb, len);
memcpy (skb->data, self->rx_bufs[self->rxs], len);

skb_copy_to_linear_data(skb, self->rx_bufs[self->rxs],
len);
self->stats.rx_packets++;
skb->dev = self->netdev;
skb_reset_mac_header(skb);
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/irda/mcs7780.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ static void mcs_unwrap_mir(struct mcs_cb *mcs, __u8 *buf, int len)
}

skb_reserve(skb, 1);
memcpy(skb->data, buf, new_len);
skb_copy_to_linear_data(skb, buf, new_len);
skb_put(skb, new_len);
skb_reset_mac_header(skb);
skb->protocol = htons(ETH_P_IRDA);
Expand Down Expand Up @@ -479,7 +479,7 @@ static void mcs_unwrap_fir(struct mcs_cb *mcs, __u8 *buf, int len)
}

skb_reserve(skb, 1);
memcpy(skb->data, buf, new_len);
skb_copy_to_linear_data(skb, buf, new_len);
skb_put(skb, new_len);
skb_reset_mac_header(skb);
skb->protocol = htons(ETH_P_IRDA);
Expand Down
8 changes: 6 additions & 2 deletions drivers/net/irda/nsc-ircc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1868,10 +1868,14 @@ static int nsc_ircc_dma_receive_complete(struct nsc_ircc_cb *self, int iobase)
/* Copy frame without CRC */
if (self->io.speed < 4000000) {
skb_put(skb, len-2);
memcpy(skb->data, self->rx_buff.data, len-2);
skb_copy_to_linear_data(skb,
self->rx_buff.data,
len - 2);
} else {
skb_put(skb, len-4);
memcpy(skb->data, self->rx_buff.data, len-4);
skb_copy_to_linear_data(skb,
self->rx_buff.data,
len - 4);
}

/* Move to next frame */
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/irda/pxaficp_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ static void pxa_irda_fir_irq_eif(struct pxa_irda *si, struct net_device *dev, in

/* Align IP header to 20 bytes */
skb_reserve(skb, 1);
memcpy(skb->data, si->dma_rx_buff, len);
skb_copy_to_linear_data(skb, si->dma_rx_buff, len);
skb_put(skb, len);

/* Feed it to IrLAP */
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/irda/stir4200.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static void fir_eof(struct stir_cb *stir)
}
skb_reserve(nskb, 1);
skb = nskb;
memcpy(nskb->data, rx_buff->data, len);
skb_copy_to_linear_data(nskb, rx_buff->data, len);
} else {
nskb = dev_alloc_skb(rx_buff->truesize);
if (unlikely(!nskb)) {
Expand Down
6 changes: 3 additions & 3 deletions drivers/net/irda/via-ircc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ F01_E */
skb_reserve(skb, 1);
skb_put(skb, len - 4);

memcpy(skb->data, self->rx_buff.data, len - 4);
skb_copy_to_linear_data(skb, self->rx_buff.data, len - 4);
IRDA_DEBUG(2, "%s(): len=%x.rx_buff=%p\n", __FUNCTION__,
len - 4, self->rx_buff.data);

Expand Down Expand Up @@ -1234,7 +1234,7 @@ static int upload_rxdata(struct via_ircc_cb *self, int iobase)
}
skb_reserve(skb, 1);
skb_put(skb, len - 4 + 1);
memcpy(skb->data, self->rx_buff.data, len - 4 + 1);
skb_copy_to_linear_data(skb, self->rx_buff.data, len - 4 + 1);
st_fifo->tail++;
st_fifo->len++;
if (st_fifo->tail > MAX_RX_WINDOW)
Expand Down Expand Up @@ -1303,7 +1303,7 @@ static int RxTimerHandler(struct via_ircc_cb *self, int iobase)
}
skb_reserve(skb, 1);
skb_put(skb, len - 4);
memcpy(skb->data, self->rx_buff.data, len - 4);
skb_copy_to_linear_data(skb, self->rx_buff.data, len - 4);

IRDA_DEBUG(2, "%s(): len=%x.head=%x\n", __FUNCTION__,
len - 4, st_fifo->head);
Expand Down
8 changes: 6 additions & 2 deletions drivers/net/irda/w83977af_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,10 +908,14 @@ int w83977af_dma_receive_complete(struct w83977af_ir *self)
/* Copy frame without CRC */
if (self->io.speed < 4000000) {
skb_put(skb, len-2);
memcpy(skb->data, self->rx_buff.data, len-2);
skb_copy_to_linear_data(skb,
self->rx_buff.data,
len - 2);
} else {
skb_put(skb, len-4);
memcpy(skb->data, self->rx_buff.data, len-4);
skb_copy_to_linear_data(skb,
self->rx_buff.data,
len - 4);
}

/* Move to next frame */
Expand Down
9 changes: 6 additions & 3 deletions drivers/net/ixgb/ixgb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2017,9 +2017,12 @@ ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
if (new_skb) {
skb_reserve(new_skb, NET_IP_ALIGN);
memcpy(new_skb->data - NET_IP_ALIGN,
skb->data - NET_IP_ALIGN,
length + NET_IP_ALIGN);
skb_copy_to_linear_data_offset(new_skb,
-NET_IP_ALIGN,
(skb->data -
NET_IP_ALIGN),
(length +
NET_IP_ALIGN));
/* save the skb in buffer_info as good */
buffer_info->skb = skb;
skb = new_skb;
Expand Down
3 changes: 2 additions & 1 deletion drivers/net/loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ static void emulate_large_send_offload(struct sk_buff *skb)
skb_set_mac_header(nskb, -ETH_HLEN);
skb_reset_network_header(nskb);
iph = ip_hdr(nskb);
memcpy(nskb->data, skb_network_header(skb), doffset);
skb_copy_to_linear_data(nskb, skb_network_header(skb),
doffset);
if (skb_copy_bits(skb,
doffset + offset,
nskb->data + doffset,
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/macb.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,10 @@ static int macb_rx_frame(struct macb *bp, unsigned int first_frag,
BUG_ON(frag != last_frag);
frag_len = len - offset;
}
memcpy(skb->data + offset,
bp->rx_buffers + (RX_BUFFER_SIZE * frag),
frag_len);
skb_copy_to_linear_data_offset(skb, offset,
(bp->rx_buffers +
(RX_BUFFER_SIZE * frag)),
frag_len);
offset += RX_BUFFER_SIZE;
bp->rx_ring[frag].addr &= ~MACB_BIT(RX_USED);
wmb();
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/myri10ge/myri10ge.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ myri10ge_rx_skb_build(struct sk_buff *skb, u8 * va,
* skb_pull() (for ether_pad and eth_type_trans()) requires
* the beginning of the packet in skb_headlen(), move it
* manually */
memcpy(skb->data, va, hlen);
skb_copy_to_linear_data(skb, va, hlen);
skb_shinfo(skb)->frags[0].page_offset += hlen;
skb_shinfo(skb)->frags[0].size -= hlen;
skb->data_len -= hlen;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/sk98lin/skge.c
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ SK_U64 PhysAddr;
(dma_addr_t) PhysAddr,
FrameLength,
PCI_DMA_FROMDEVICE);
memcpy(pNewMsg->data, pMsg, FrameLength);
skb_copy_to_linear_data(pNewMsg, pMsg, FrameLength);

pci_dma_sync_single_for_device(pAC->PciDev,
(dma_addr_t) PhysAddr,
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/skfp/skfddi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ int mac_drv_rx_init(struct s_smc *smc, int len, int fc,
}
skb_reserve(skb, 3);
skb_put(skb, len);
memcpy(skb->data, look_ahead, len);
skb_copy_to_linear_data(skb, look_ahead, len);

// deliver frame to system
skb->protocol = fddi_type_trans(skb, smc->os.dev);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/sun3lance.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ static int lance_rx( struct net_device *dev )

skb_reserve( skb, 2 ); /* 16 byte align */
skb_put( skb, pkt_len ); /* Make room */
// memcpy( skb->data, PKTBUF_ADDR(head), pkt_len );
// skb_copy_to_linear_data(skb, PKTBUF_ADDR(head), pkt_len);
eth_copy_and_sum(skb,
PKTBUF_ADDR(head),
pkt_len, 0);
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/tokenring/smctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3889,7 +3889,7 @@ static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,

/* Slide data into a sleek skb. */
skb_put(skb, skb->len);
memcpy(skb->data, rmf, skb->len);
skb_copy_to_linear_data(skb, rmf, skb->len);

/* Update Counters */
tp->MacStat.rx_packets++;
Expand Down Expand Up @@ -4475,7 +4475,7 @@ static int smctr_rx_frame(struct net_device *dev)
if (skb) {
skb_put(skb, rx_size);

memcpy(skb->data, pbuff, rx_size);
skb_copy_to_linear_data(skb, pbuff, rx_size);

/* Update Counters */
tp->MacStat.rx_packets++;
Expand Down
Loading

0 comments on commit 27d7ff4

Please sign in to comment.