From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
Jesse Brandeburg <jesse.brandeburg@intel.com>,
Tony Nguyen <anthony.l.nguyen@intel.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: <linux-kernel@vger.kernel.org>, <kernel-janitors@vger.kernel.org>,
<intel-wired-lan@lists.osuosl.org>, <netdev@vger.kernel.org>
Subject: Re: [PATCH net-next] iavf: Avoid a memory allocation in iavf_print_link_message()
Date: Mon, 25 Sep 2023 10:11:22 +0200 [thread overview]
Message-ID: <ba7040d4-337f-56a1-0f87-cc6dd70228ec@intel.com> (raw)
In-Reply-To: <966968bda15a7128a381b589329184dfea3e0548.1695471387.git.christophe.jaillet@wanadoo.fr>
On 9/23/23 14:17, Christophe JAILLET wrote:
> IAVF_MAX_SPEED_STRLEN is only 13 and 'speed' is allocated and freed within
> iavf_print_link_message().
>
> 'speed' is only used with some snprintf() and netdev_info() calls.
>
> So there is no real use to kzalloc()/free() it. Use the stack instead.
> This saves a memory allocation.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> drivers/net/ethernet/intel/iavf/iavf_virtchnl.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c b/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
> index 8ce6389b5815..980dc69d7fbe 100644
> --- a/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
> +++ b/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
> @@ -1389,18 +1389,14 @@ void iavf_disable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
> static void iavf_print_link_message(struct iavf_adapter *adapter)
> {
> struct net_device *netdev = adapter->netdev;
> + char speed[IAVF_MAX_SPEED_STRLEN];
> int link_speed_mbps;
> - char *speed;
>
> if (!adapter->link_up) {
> netdev_info(netdev, "NIC Link is Down\n");
> return;
> }
>
> - speed = kzalloc(IAVF_MAX_SPEED_STRLEN, GFP_KERNEL);
> - if (!speed)
> - return;
> -
> if (ADV_LINK_SUPPORT(adapter)) {
> link_speed_mbps = adapter->link_speed_mbps;
> goto print_link_msg;
> @@ -1452,7 +1448,6 @@ static void iavf_print_link_message(struct iavf_adapter *adapter)
> }
>
> netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed);
> - kfree(speed);
> }
>
> /**
Looks fine, thanks!
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
I know that Jesse is fixing snprintf() calls currently,
but I bet it's not conflicting.
next prev parent reply other threads:[~2023-09-25 8:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-23 12:17 Christophe JAILLET
2023-09-25 8:11 ` Przemek Kitszel [this message]
2023-10-03 17:14 ` Jesse Brandeburg
2023-10-03 20:33 ` Christophe JAILLET
2023-10-03 23:01 ` Jesse Brandeburg
2023-10-04 8:04 ` Dan Carpenter
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=ba7040d4-337f-56a1-0f87-cc6dd70228ec@intel.com \
--to=przemyslaw.kitszel@intel.com \
--cc=anthony.l.nguyen@intel.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=jesse.brandeburg@intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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
all inboxes | Powered by JetHome®