netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
To: "Ignacy Gawędzki" <ignacy.gawedzki@green-communications.fr>,
	netdev@vger.kernel.org
Subject: Re: [PATCH net 1/2] gen_stats.c: Duplicate xstats buffer for later use
Date: Thu, 08 Jan 2015 16:07:58 +0300	[thread overview]
Message-ID: <54AE812E.4070508@cogentembedded.com> (raw)
In-Reply-To: <20150108103518.GA7214@zenon.in.qult.net>

Hello.

On 1/8/2015 1:35 PM, Ignacy Gawędzki wrote:

> The gnet_stats_copy_app() function gets called, more often than not, with its
> second argument a pointer to an automatic variable in the caller's stack.
> Therefore, to avoid copying garbage afterwards when calling
> gnet_stats_finish_copy(), this data is better copied to a dynamically allocated
> memory that gets freed after use.

> Signed-off-by: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
> ---
>   net/core/gen_stats.c | 17 ++++++++++++++---
>   1 file changed, 14 insertions(+), 3 deletions(-)

> diff --git a/net/core/gen_stats.c b/net/core/gen_stats.c
> index 0c08062..5770a0e 100644
> --- a/net/core/gen_stats.c
> +++ b/net/core/gen_stats.c
> @@ -305,7 +305,10 @@ int
>   gnet_stats_copy_app(struct gnet_dump *d, void *st, int len)
>   {
>   	if (d->compat_xstats) {
> -		d->xstats = st;
> +		d->xstats = kmalloc(len, GFP_KERNEL);
> +		if (!d->xstats)
> +			goto kmalloc_failure;
> +		memcpy(d->xstats, st, len);

    Please use kmemdup() instead of kmalloc()/memcpy().

[...]

WBR, Sergei

      parent reply	other threads:[~2015-01-08 13:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-08 10:35 [PATCH net 1/2] gen_stats.c: Duplicate xstats buffer for later use Ignacy Gawędzki
2015-01-08 11:05 ` David Laight
2015-01-08 12:02   ` 'Ignacy Gawedzki'
2015-01-08 12:26 ` David Laight
2015-01-08 12:32   ` 'Ignacy Gawedzki'
2015-01-08 13:07 ` Sergei Shtylyov [this message]

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=54AE812E.4070508@cogentembedded.com \
    --to=sergei.shtylyov@cogentembedded.com \
    --cc=ignacy.gawedzki@green-communications.fr \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).