Commit ca738f5a authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Jakub Kicinski

s390/ctcm: Avoid temporary allocation of struct pdu.

The size of struct pdu is 8 byte. The memory is allocated, initialized,
used and deallocated a few lines later.

It is more efficient to avoid the allocation/free dance and assign the
values directly to skb's data part instead of using memcpy() for it.

Avoid an allocation of struct pdu and use the resulting skb pointer
instead.
Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
[jwi: Fix-up the pdu_offset, adjust skb->len for the pushed length.
      Reflow the commit msg.]
Signed-off-by: default avatarJulian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d38aa396
...@@ -665,24 +665,16 @@ static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb) ...@@ -665,24 +665,16 @@ static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb)
if ((fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) || grp->in_sweep) { if ((fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) || grp->in_sweep) {
spin_lock_irqsave(&ch->collect_lock, saveflags); spin_lock_irqsave(&ch->collect_lock, saveflags);
refcount_inc(&skb->users); refcount_inc(&skb->users);
p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type());
if (!p_header) { p_header = skb_push(skb, PDU_HEADER_LENGTH);
spin_unlock_irqrestore(&ch->collect_lock, saveflags); p_header->pdu_offset = skb->len - PDU_HEADER_LENGTH;
goto nomem_exit;
}
p_header->pdu_offset = skb->len;
p_header->pdu_proto = 0x01; p_header->pdu_proto = 0x01;
p_header->pdu_flag = 0x00;
if (be16_to_cpu(skb->protocol) == ETH_P_SNAP) { if (be16_to_cpu(skb->protocol) == ETH_P_SNAP) {
p_header->pdu_flag |= PDU_FIRST | PDU_CNTL; p_header->pdu_flag = PDU_FIRST | PDU_CNTL;
} else { } else {
p_header->pdu_flag |= PDU_FIRST; p_header->pdu_flag = PDU_FIRST;
} }
p_header->pdu_seq = 0; p_header->pdu_seq = 0;
memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header,
PDU_HEADER_LENGTH);
CTCM_PR_DEBUG("%s(%s): Put on collect_q - skb len: %04x \n" CTCM_PR_DEBUG("%s(%s): Put on collect_q - skb len: %04x \n"
"pdu header and data for up to 32 bytes:\n", "pdu header and data for up to 32 bytes:\n",
...@@ -691,7 +683,6 @@ static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb) ...@@ -691,7 +683,6 @@ static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb)
skb_queue_tail(&ch->collect_queue, skb); skb_queue_tail(&ch->collect_queue, skb);
ch->collect_len += skb->len; ch->collect_len += skb->len;
kfree(p_header);
spin_unlock_irqrestore(&ch->collect_lock, saveflags); spin_unlock_irqrestore(&ch->collect_lock, saveflags);
goto done; goto done;
...@@ -721,23 +712,15 @@ static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb) ...@@ -721,23 +712,15 @@ static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb)
} }
} }
p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type()); p_header = skb_push(skb, PDU_HEADER_LENGTH);
p_header->pdu_offset = skb->len - PDU_HEADER_LENGTH;
if (!p_header)
goto nomem_exit;
p_header->pdu_offset = skb->len;
p_header->pdu_proto = 0x01; p_header->pdu_proto = 0x01;
p_header->pdu_flag = 0x00;
p_header->pdu_seq = 0; p_header->pdu_seq = 0;
if (be16_to_cpu(skb->protocol) == ETH_P_SNAP) { if (be16_to_cpu(skb->protocol) == ETH_P_SNAP) {
p_header->pdu_flag |= PDU_FIRST | PDU_CNTL; p_header->pdu_flag = PDU_FIRST | PDU_CNTL;
} else { } else {
p_header->pdu_flag |= PDU_FIRST; p_header->pdu_flag = PDU_FIRST;
} }
memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header, PDU_HEADER_LENGTH);
kfree(p_header);
if (ch->collect_len > 0) { if (ch->collect_len > 0) {
spin_lock_irqsave(&ch->collect_lock, saveflags); spin_lock_irqsave(&ch->collect_lock, saveflags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment