public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yajun Deng <yajun.deng@linux.dev>
To: davem@davemloft.net, kuba@kernel.org, andriin@fb.com,
	atenart@kernel.org, alobakin@pm.me, ast@kernel.org,
	edumazet@google.com, daniel@iogearbox.net, weiwan@google.com,
	ap420073@gmail.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yajun Deng <yajun.deng@linux.dev>
Subject: [PATCH] net: core: Modify alloc_size in alloc_netdev_mqs()
Date: Wed, 30 Jun 2021 13:11:18 +0800	[thread overview]
Message-ID: <20210630051118.2212-1-yajun.deng@linux.dev> (raw)

Use ALIGN for 'struct net_device', and remove the unneeded
'NETDEV_ALIGN - 1'. This can save a few bytes. and modify
the pr_err content when txqs < 1.

Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
 net/core/dev.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index c253c2aafe97..c42a682a624d 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10789,7 +10789,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
 	BUG_ON(strlen(name) >= sizeof(dev->name));
 
 	if (txqs < 1) {
-		pr_err("alloc_netdev: Unable to allocate device with zero queues\n");
+		pr_err("alloc_netdev: Unable to allocate device with zero TX queues\n");
 		return NULL;
 	}
 
@@ -10798,14 +10798,12 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
 		return NULL;
 	}
 
-	alloc_size = sizeof(struct net_device);
+	/* ensure 32-byte alignment of struct net_device*/
+	alloc_size = ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
 	if (sizeof_priv) {
 		/* ensure 32-byte alignment of private area */
-		alloc_size = ALIGN(alloc_size, NETDEV_ALIGN);
-		alloc_size += sizeof_priv;
+		alloc_size += ALIGN(sizeof_priv, NETDEV_ALIGN);
 	}
-	/* ensure 32-byte alignment of whole construct */
-	alloc_size += NETDEV_ALIGN - 1;
 
 	p = kvzalloc(alloc_size, GFP_KERNEL | __GFP_RETRY_MAYFAIL);
 	if (!p)
-- 
2.32.0


             reply	other threads:[~2021-06-30  5:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-30  5:11 Yajun Deng [this message]
2021-06-30 11:02 ` [PATCH] net: core: Modify alloc_size in alloc_netdev_mqs() Eric Dumazet

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=20210630051118.2212-1-yajun.deng@linux.dev \
    --to=yajun.deng@linux.dev \
    --cc=alobakin@pm.me \
    --cc=andriin@fb.com \
    --cc=ap420073@gmail.com \
    --cc=ast@kernel.org \
    --cc=atenart@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=weiwan@google.com \
    /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