public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
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 2/6] s390/ctcm: Put struct qllc on stack.
Date: Wed, 18 Nov 2020 11:53:13 +0100	[thread overview]
Message-ID: <20201118105317.605671-3-bigeasy@linutronix.de> (raw)
In-Reply-To: <20201118105317.605671-1-bigeasy@linutronix.de>

The size of struct qllc is 2 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.

Rename `qllcptr' to `qllc' and use it on stack.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/s390/net/ctcm_mpc.c | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/drivers/s390/net/ctcm_mpc.c b/drivers/s390/net/ctcm_mpc.c
index 04a51cc89e74c..4ff51af44d338 100644
--- a/drivers/s390/net/ctcm_mpc.c
+++ b/drivers/s390/net/ctcm_mpc.c
@@ -2049,11 +2049,10 @@ static void mpc_action_rcvd_xid7(fsm_instance *fsm, int event, void *arg)
  */
 static int mpc_send_qllc_discontact(struct net_device *dev)
 {
-	__u32	new_len	= 0;
 	struct sk_buff   *skb;
-	struct qllc      *qllcptr;
 	struct ctcm_priv *priv = dev->ml_priv;
 	struct mpc_group *grp = priv->mpcg;
+	struct qllc	qllc;
 
 	CTCM_PR_DEBUG("%s: GROUP STATE: %s\n",
 		__func__, mpcg_state_names[grp->saved_state]);
@@ -2080,31 +2079,20 @@ static int mpc_send_qllc_discontact(struct net_device *dev)
 	case MPCG_STATE_FLOWC:
 	case MPCG_STATE_READY:
 		grp->send_qllc_disc = 2;
-		new_len = sizeof(struct qllc);
-		qllcptr = kzalloc(new_len, gfp_type() | GFP_DMA);
-		if (qllcptr == NULL) {
-			CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
-				"%s(%s): qllcptr allocation error",
-						CTCM_FUNTAIL, dev->name);
-			return -ENOMEM;
-		}
-
-		qllcptr->qllc_address = 0xcc;
-		qllcptr->qllc_commands = 0x03;
-
-		skb = __dev_alloc_skb(new_len, GFP_ATOMIC);
 
+		skb = __dev_alloc_skb(sizeof(struct qllc), GFP_ATOMIC);
 		if (skb == NULL) {
 			CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
 				"%s(%s): skb allocation error",
 						CTCM_FUNTAIL, dev->name);
 			priv->stats.rx_dropped++;
-			kfree(qllcptr);
 			return -ENOMEM;
 		}
 
-		skb_put_data(skb, qllcptr, new_len);
-		kfree(qllcptr);
+		qllc.qllc_address = 0xcc;
+		qllc.qllc_commands = 0x03;
+
+		skb_put_data(skb, &qllc, sizeof(struct qllc));
 
 		if (skb_headroom(skb) < 4) {
 			CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
-- 
2.29.2

  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 ` [PATCH 1/6] s390/ctcm: Put struct th_header and th_sweep on stack Sebastian Andrzej Siewior
2020-11-19  7:45   ` 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 ` Sebastian Andrzej Siewior [this message]
2020-11-19  7:56   ` [PATCH 2/6] s390/ctcm: Put struct qllc " 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-3-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