From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-s390@vger.kernel.org
Cc: Julian Wiedmann <jwi@linux.ibm.com>,
Karsten Graul <kgraul@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Christian Borntraeger <borntraeger@de.ibm.com>,
Thomas Gleixner <tglx@linutronix.de>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: [PATCH 1/6] s390/ctcm: Put struct th_header and th_sweep on stack.
Date: Wed, 18 Nov 2020 11:53:12 +0100 [thread overview]
Message-ID: <20201118105317.605671-2-bigeasy@linutronix.de> (raw)
In-Reply-To: <20201118105317.605671-1-bigeasy@linutronix.de>
The size of struct th_header is 8 byte and the size of struct th_sweep
is 16 byte. The memory for is allocated, initialized, used and
deallocated a few lines later.
It is more efficient to avoid the allocation/free dance and keeping the
variable on stack. Especially since the compiler is smart enough to not
allocate the memory on stack but assign the values directly.
Declare struct th_sweep/th_header on stack and initialize it to zero.
Use the local variable instead of the pointer.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
drivers/s390/net/ctcm_fsms.c | 17 +++++-----------
drivers/s390/net/ctcm_main.c | 39 ++++++++----------------------------
drivers/s390/net/ctcm_mpc.c | 21 ++++---------------
3 files changed, 17 insertions(+), 60 deletions(-)
diff --git a/drivers/s390/net/ctcm_fsms.c b/drivers/s390/net/ctcm_fsms.c
index 661d2a49bce96..d6592d576d1dd 100644
--- a/drivers/s390/net/ctcm_fsms.c
+++ b/drivers/s390/net/ctcm_fsms.c
@@ -1220,7 +1220,7 @@ static void ctcmpc_chx_txdone(fsm_instance *fi, int event, void *arg)
unsigned long duration;
struct sk_buff *peekskb;
int rc;
- struct th_header *header;
+ struct th_header header = {0, };
struct pdu *p_header;
unsigned long done_stamp = jiffies;
@@ -1303,24 +1303,17 @@ static void ctcmpc_chx_txdone(fsm_instance *fi, int event, void *arg)
/* p_header points to the last one we handled */
if (p_header)
p_header->pdu_flag |= PDU_LAST; /*Say it's the last one*/
- header = kzalloc(TH_HEADER_LENGTH, gfp_type());
- if (!header) {
- spin_unlock(&ch->collect_lock);
- fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
- goto done;
- }
- header->th_ch_flag = TH_HAS_PDU; /* Normal data */
+
+ header.th_ch_flag = TH_HAS_PDU; /* Normal data */
ch->th_seq_num++;
- header->th_seq_num = ch->th_seq_num;
+ header.th_seq_num = ch->th_seq_num;
CTCM_PR_DBGDATA("%s: ToVTAM_th_seq= %08x\n" ,
__func__, ch->th_seq_num);
- memcpy(skb_push(ch->trans_skb, TH_HEADER_LENGTH), header,
+ memcpy(skb_push(ch->trans_skb, TH_HEADER_LENGTH), &header,
TH_HEADER_LENGTH); /* put the TH on the packet */
- kfree(header);
-
CTCM_PR_DBGDATA("%s: trans_skb len:%04x \n",
__func__, ch->trans_skb->len);
CTCM_PR_DBGDATA("%s: up-to-50 bytes of trans_skb "
diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
index d06809eac16d3..6c7d6bbd27406 100644
--- a/drivers/s390/net/ctcm_main.c
+++ b/drivers/s390/net/ctcm_main.c
@@ -599,7 +599,7 @@ static void ctcmpc_send_sweep_req(struct channel *rch)
struct net_device *dev = rch->netdev;
struct ctcm_priv *priv;
struct mpc_group *grp;
- struct th_sweep *header;
+ struct th_sweep header = { 0, };
struct sk_buff *sweep_skb;
struct channel *ch;
/* int rc = 0; */
@@ -623,24 +623,10 @@ static void ctcmpc_send_sweep_req(struct channel *rch)
goto nomem;
}
- header = kmalloc(TH_SWEEP_LENGTH, gfp_type());
+ header.th.th_ch_flag = TH_SWEEP_REQ; /* 0x0f */
+ header.sw.th_last_seq = ch->th_seq_num;
- if (!header) {
- dev_kfree_skb_any(sweep_skb);
- /* rc = -ENOMEM; */
- goto nomem;
- }
-
- header->th.th_seg = 0x00 ;
- header->th.th_ch_flag = TH_SWEEP_REQ; /* 0x0f */
- header->th.th_blk_flag = 0x00;
- header->th.th_is_xid = 0x00;
- header->th.th_seq_num = 0x00;
- header->sw.th_last_seq = ch->th_seq_num;
-
- skb_put_data(sweep_skb, header, TH_SWEEP_LENGTH);
-
- kfree(header);
+ skb_put_data(sweep_skb, &header, TH_SWEEP_LENGTH);
netif_trans_update(dev);
skb_queue_tail(&ch->sweep_queue, sweep_skb);
@@ -666,7 +652,7 @@ static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb)
struct net_device *dev = ch->netdev;
struct ctcm_priv *priv = dev->ml_priv;
struct mpc_group *grp = priv->mpcg;
- struct th_header *header;
+ struct th_header header = { 0, };
struct sk_buff *nskb;
int rc = 0;
int ccw_idx;
@@ -768,24 +754,15 @@ static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb)
ch->prof.txlen += skb->len - PDU_HEADER_LENGTH;
- header = kmalloc(TH_HEADER_LENGTH, gfp_type());
- if (!header)
- goto nomem_exit;
-
- header->th_seg = 0x00;
- header->th_ch_flag = TH_HAS_PDU; /* Normal data */
- header->th_blk_flag = 0x00;
- header->th_is_xid = 0x00; /* Just data here */
+ header.th_ch_flag = TH_HAS_PDU; /* Normal data */
ch->th_seq_num++;
- header->th_seq_num = ch->th_seq_num;
+ header.th_seq_num = ch->th_seq_num;
CTCM_PR_DBGDATA("%s(%s) ToVTAM_th_seq= %08x\n" ,
__func__, dev->name, ch->th_seq_num);
/* put the TH on the packet */
- memcpy(skb_push(skb, TH_HEADER_LENGTH), header, TH_HEADER_LENGTH);
-
- kfree(header);
+ memcpy(skb_push(skb, TH_HEADER_LENGTH), &header, TH_HEADER_LENGTH);
CTCM_PR_DBGDATA("%s(%s): skb len: %04x\n - pdu header and data for "
"up to 32 bytes sent to vtam:\n",
diff --git a/drivers/s390/net/ctcm_mpc.c b/drivers/s390/net/ctcm_mpc.c
index 85a1a4533cbeb..04a51cc89e74c 100644
--- a/drivers/s390/net/ctcm_mpc.c
+++ b/drivers/s390/net/ctcm_mpc.c
@@ -641,7 +641,7 @@ static void ctcmpc_send_sweep_resp(struct channel *rch)
struct net_device *dev = rch->netdev;
struct ctcm_priv *priv = dev->ml_priv;
struct mpc_group *grp = priv->mpcg;
- struct th_sweep *header;
+ struct th_sweep header = { 0, };
struct sk_buff *sweep_skb;
struct channel *ch = priv->channel[CTCM_WRITE];
@@ -655,23 +655,10 @@ static void ctcmpc_send_sweep_resp(struct channel *rch)
goto done;
}
- header = kmalloc(sizeof(struct th_sweep), gfp_type());
+ header.th.th_ch_flag = TH_SWEEP_RESP;
+ header.sw.th_last_seq = ch->th_seq_num;
- if (!header) {
- dev_kfree_skb_any(sweep_skb);
- goto done;
- }
-
- header->th.th_seg = 0x00 ;
- header->th.th_ch_flag = TH_SWEEP_RESP;
- header->th.th_blk_flag = 0x00;
- header->th.th_is_xid = 0x00;
- header->th.th_seq_num = 0x00;
- header->sw.th_last_seq = ch->th_seq_num;
-
- skb_put_data(sweep_skb, header, TH_SWEEP_LENGTH);
-
- kfree(header);
+ skb_put_data(sweep_skb, &header, TH_SWEEP_LENGTH);
netif_trans_update(dev);
skb_queue_tail(&ch->sweep_queue, sweep_skb);
--
2.29.2
next prev parent reply other threads:[~2020-11-18 10:54 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-18 10:53 [PATCH 0/6] s390/ctcm: Remove gfp_type() usage Sebastian Andrzej Siewior
2020-11-18 10:53 ` Sebastian Andrzej Siewior [this message]
2020-11-19 7:45 ` [PATCH 1/6] s390/ctcm: Put struct th_header and th_sweep on stack Julian Wiedmann
2020-11-19 8:12 ` Sebastian Andrzej Siewior
2020-11-19 8:16 ` Julian Wiedmann
2020-11-19 9:37 ` Sebastian Andrzej Siewior
2020-11-18 10:53 ` [PATCH 2/6] s390/ctcm: Put struct qllc " Sebastian Andrzej Siewior
2020-11-19 7:56 ` Julian Wiedmann
2020-11-18 10:53 ` [PATCH 3/6] s390/ctcm: Put struct pdu " Sebastian Andrzej Siewior
2020-11-19 7:52 ` Julian Wiedmann
2020-11-18 10:53 ` [PATCH 4/6] s390/ctcm: Use explicit allocation mask in ctcmpc_unpack_skb() Sebastian Andrzej Siewior
2020-11-19 7:28 ` Julian Wiedmann
2020-11-18 10:53 ` [PATCH 5/6] s390/ctcm: Use GFP_KERNEL in add_channel() Sebastian Andrzej Siewior
2020-11-19 7:30 ` Julian Wiedmann
2020-11-18 10:53 ` [PATCH 6/6] s390/ctcm: Use GFP_ATOMIC in ctcmpc_tx() Sebastian Andrzej Siewior
2020-11-19 7:34 ` Julian Wiedmann
2020-11-19 8:01 ` [PATCH 0/6] s390/ctcm: Remove gfp_type() usage Julian Wiedmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201118105317.605671-2-bigeasy@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=borntraeger@de.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=jwi@linux.ibm.com \
--cc=kgraul@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox