mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Zheng Yongjun <zhengyongjun3@huawei.com>,
	davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next] vxlan: Return the correct errno code
Date: Mon, 07 Jun 2021 07:50:19 -0700	[thread overview]
Message-ID: <3d1c10d4632451fb270a847acb320acefe2d019f.camel@perches.com> (raw)
In-Reply-To: <20210607144422.2848809-1-zhengyongjun3@huawei.com>

On Mon, 2021-06-07 at 22:44 +0800, Zheng Yongjun wrote:
> When kalloc or kmemdup failed, should return ENOMEM rather than ENOBUFS.

Why?  Where in the call chain does it matter?
Have you inspected the entire call chain and their return value tests?

> diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
[]
> @@ -711,11 +711,11 @@ static int vxlan_fdb_append(struct vxlan_fdb *f,
>  
> 
>  	rd = kmalloc(sizeof(*rd), GFP_ATOMIC);

And this should probably use kzalloc to avoid possible uninitialized members.

>  	if (rd == NULL)
> -		return -ENOBUFS;
> +		return -ENOMEM;
>  
>  	if (dst_cache_init(&rd->dst_cache, GFP_ATOMIC)) {
>  		kfree(rd);
> -		return -ENOBUFS;
> +		return -ENOMEM;
>  	}
>  
>  	rd->remote_ip = *ip;

The struct is:

include/net/vxlan.h:struct vxlan_rdst {
include/net/vxlan.h-    union vxlan_addr         remote_ip;
include/net/vxlan.h-    __be16                   remote_port;
include/net/vxlan.h-    u8                       offloaded:1;
include/net/vxlan.h-    __be32                   remote_vni;
include/net/vxlan.h-    u32                      remote_ifindex;
include/net/vxlan.h-    struct net_device        *remote_dev;
include/net/vxlan.h-    struct list_head         list;
include/net/vxlan.h-    struct rcu_head          rcu;
include/net/vxlan.h-    struct dst_cache         dst_cache;
include/net/vxlan.h-};

And the code is:

	if (dst_cache_init(&rd->dst_cache, GFP_ATOMIC)) {
		kfree(rd);
		return -ENOBUFS;
	}

	rd->remote_ip = *ip;
	rd->remote_port = port;
	rd->offloaded = false;
	rd->remote_vni = vni;
	rd->remote_ifindex = ifindex;

	list_add_tail_rcu(&rd->list, &f->remotes);

	*rdp = rd;

So it appears as if rd->remote_dev and rd->rcu are uninitialized.
I don't know if that matters, but it seems poor form.



      reply	other threads:[~2021-06-07 14:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-07 14:44 Zheng Yongjun
2021-06-07 14:50 ` Joe Perches [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=3d1c10d4632451fb270a847acb320acefe2d019f.camel@perches.com \
    --to=joe@perches.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=zhengyongjun3@huawei.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®