Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Lobakin <aleksander.lobakin@intel.com>
To: Kunwu Chan <chentao@kylinos.cn>
Cc: kunwu.chan@hotmail.com, netdev@vger.kernel.org,
	jesse.brandeburg@intel.com, linux-kernel@vger.kernel.org,
	edumazet@google.com, intel-wired-lan@lists.osuosl.org,
	jeffrey.t.kirsher@intel.com, horms@kernel.org, kuba@kernel.org,
	anthony.l.nguyen@intel.com, pabeni@redhat.com,
	davem@davemloft.net, shannon.nelson@amd.com
Subject: Re: [Intel-wired-lan] [PATCH iwl-next] i40e: Use correct buffer size
Date: Mon, 20 Nov 2023 12:41:51 +0100	[thread overview]
Message-ID: <2c61c232-1bbb-4cae-bb7f-92a7f2298e97@intel.com> (raw)
In-Reply-To: <4b551600-f1a3-4efe-b3e9-99cb4536f487@kylinos.cn>

From: Kunwu Chan <chentao@kylinos.cn>
Date: Sun, 19 Nov 2023 23:12:09 +0800

> Hi Alexander,
> Thank you so much for your reply, I looked at the modification you
> mentioned, it's really cool. I'll definitely try it next time.
> 
> But when using it, will it be easy to forget to free up memory?

You have a kfree() at the end of the function.

Generally speaking, 'ka' stands for "[kernel] allocate" and you also
need to pass GPF_ as the second argument. Enough hints that you need to
free the pointer after using it I would say.

> Although 'kmalloc_track_caller' is used, according to my understanding,
> it is also necessary to release the memory at the end of use.
> 
> On 2023/11/15 23:39, Alexander Lobakin wrote:
>> From: Kunwu Chan <chentao@kylinos.cn>
>> Date: Wed, 15 Nov 2023 11:14:44 +0800
>>
>>> The size of "i40e_dbg_command_buf" is 256, the size of "name"
>>> depends on "IFNAMSIZ", plus a null character and format size,
>>> the total size is more than 256, fix it.
>>>
>>> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
>>> Suggested-by: Simon Horman <horms@kernel.org>
>>> ---
>>>   drivers/net/ethernet/intel/i40e/i40e_debugfs.c | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c
>>> b/drivers/net/ethernet/intel/i40e/i40e_debugfs.c
>>> index 999c9708def5..e3b939c67cfe 100644
>>> --- a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c
>>> +++ b/drivers/net/ethernet/intel/i40e/i40e_debugfs.c
>>> @@ -72,7 +72,7 @@ static ssize_t i40e_dbg_command_read(struct file
>>> *filp, char __user *buffer,
>>>   {
>>>       struct i40e_pf *pf = filp->private_data;
>>>       int bytes_not_copied;
>>> -    int buf_size = 256;
>>> +    int buf_size = IFNAMSIZ + sizeof(i40e_dbg_command_buf) + 4;
>>
>> Reverse Christmas Tree style? Should be the first one in the declaration
>> list.
>>
>>>       char *buf;
>>>       int len;
>>
>> You can fix it in a different way. Given that there's a kzalloc() either
>> way, why not allocate the precise required amount of bytes by using
>> kasprintf() instead of kzalloc() + snprintf()? You wouldn't need to
>> calculate any buffer sizes etc. this way.
>>
>> Thanks,
>> Olek

Thanks,
Olek
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

  reply	other threads:[~2023-11-20 11:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-12 11:01 [Intel-wired-lan] [PATCH] i40e: Use correct buffer size Kunwu Chan
2023-11-13  9:31 ` Simon Horman
2023-11-15  3:10   ` Kunwu Chan
2023-11-15  3:14   ` [Intel-wired-lan] [PATCH iwl-next] " Kunwu Chan
2023-11-15  9:21     ` Simon Horman
2023-11-15 15:39     ` Alexander Lobakin
2023-11-19 15:12       ` Kunwu Chan
2023-11-20 11:41         ` Alexander Lobakin [this message]
2023-11-21  2:12           ` Kunwu Chan
2023-11-21 11:15             ` Alexander Lobakin
2023-11-22  6:57               ` Kunwu Chan

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=2c61c232-1bbb-4cae-bb7f-92a7f2298e97@intel.com \
    --to=aleksander.lobakin@intel.com \
    --cc=anthony.l.nguyen@intel.com \
    --cc=chentao@kylinos.cn \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=kuba@kernel.org \
    --cc=kunwu.chan@hotmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shannon.nelson@amd.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