diff mbox series

[net,v2] net: bareudp: add missing error handling for bareudp_link_config()

Message ID 20210105190725.1736246-1-kuba@kernel.org (mailing list archive)
State Accepted
Commit 94bcfdbff0c210b17b27615f4952cc6ece7d5f5f
Delegated to: Netdev Maintainers
Headers show
Series [net,v2] net: bareudp: add missing error handling for bareudp_link_config() | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 46 this patch: 46
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 42 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 38 this patch: 38
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Jakub Kicinski Jan. 5, 2021, 7:07 p.m. UTC
.dellink does not get called after .newlink fails,
bareudp_newlink() must undo what bareudp_configure()
has done if bareudp_link_config() fails.

v2: call bareudp_dellink(), like bareudp_dev_create() does

Fixes: 571912c69f0e ("net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS, IP, NSH etc.")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 drivers/net/bareudp.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

Comments

Cong Wang Jan. 5, 2021, 8:38 p.m. UTC | #1
On Tue, Jan 5, 2021 at 11:07 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> .dellink does not get called after .newlink fails,
> bareudp_newlink() must undo what bareudp_configure()
> has done if bareudp_link_config() fails.
>
> v2: call bareudp_dellink(), like bareudp_dev_create() does

Thanks for the update. Just one question below.

>
> Fixes: 571912c69f0e ("net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS, IP, NSH etc.")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
>  drivers/net/bareudp.c | 22 ++++++++++++++--------
>  1 file changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c
> index 708171c0d628..85de5f96c02b 100644
> --- a/drivers/net/bareudp.c
> +++ b/drivers/net/bareudp.c
> @@ -645,11 +645,20 @@ static int bareudp_link_config(struct net_device *dev,
>         return 0;
>  }
>
> +static void bareudp_dellink(struct net_device *dev, struct list_head *head)
> +{
> +       struct bareudp_dev *bareudp = netdev_priv(dev);
> +
> +       list_del(&bareudp->next);
> +       unregister_netdevice_queue(dev, head);
> +}
> +
>  static int bareudp_newlink(struct net *net, struct net_device *dev,
>                            struct nlattr *tb[], struct nlattr *data[],
>                            struct netlink_ext_ack *extack)
>  {
>         struct bareudp_conf conf;
> +       LIST_HEAD(list_kill);
>         int err;
>
>         err = bareudp2info(data, &conf, extack);
> @@ -662,17 +671,14 @@ static int bareudp_newlink(struct net *net, struct net_device *dev,
>
>         err = bareudp_link_config(dev, tb);
>         if (err)
> -               return err;
> +               goto err_unconfig;
>
>         return 0;
> -}
> -
> -static void bareudp_dellink(struct net_device *dev, struct list_head *head)
> -{
> -       struct bareudp_dev *bareudp = netdev_priv(dev);
>
> -       list_del(&bareudp->next);
> -       unregister_netdevice_queue(dev, head);
> +err_unconfig:
> +       bareudp_dellink(dev, &list_kill);
> +       unregister_netdevice_many(&list_kill);

Why do we need unregister_netdevice_many() here? I think
bareudp_dellink(dev, NULL) is sufficient as we always have
one instance to unregister?

(For the same reason, bareudp_dev_create() does not need it
either.)

Thanks.
Jakub Kicinski Jan. 5, 2021, 10:39 p.m. UTC | #2
On Tue, 5 Jan 2021 12:38:54 -0800 Cong Wang wrote:
> On Tue, Jan 5, 2021 at 11:07 AM Jakub Kicinski <kuba@kernel.org> wrote:
> > +static void bareudp_dellink(struct net_device *dev, struct list_head *head)
> > +{
> > +       struct bareudp_dev *bareudp = netdev_priv(dev);
> > +
> > +       list_del(&bareudp->next);
> > +       unregister_netdevice_queue(dev, head);
> > +}
> > +
> >  static int bareudp_newlink(struct net *net, struct net_device *dev,
> >                            struct nlattr *tb[], struct nlattr *data[],
> >                            struct netlink_ext_ack *extack)
> >  {
> >         struct bareudp_conf conf;
> > +       LIST_HEAD(list_kill);
> >         int err;
> >
> >         err = bareudp2info(data, &conf, extack);
> > @@ -662,17 +671,14 @@ static int bareudp_newlink(struct net *net, struct net_device *dev,
> >
> >         err = bareudp_link_config(dev, tb);
> >         if (err)
> > -               return err;
> > +               goto err_unconfig;
> >
> >         return 0;
> > -}
> > -
> > -static void bareudp_dellink(struct net_device *dev, struct list_head *head)
> > -{
> > -       struct bareudp_dev *bareudp = netdev_priv(dev);
> >
> > -       list_del(&bareudp->next);
> > -       unregister_netdevice_queue(dev, head);
> > +err_unconfig:
> > +       bareudp_dellink(dev, &list_kill);
> > +       unregister_netdevice_many(&list_kill);  
> 
> Why do we need unregister_netdevice_many() here? I think
> bareudp_dellink(dev, NULL) is sufficient as we always have
> one instance to unregister?
> 
> (For the same reason, bareudp_dev_create() does not need it
> either.)

Ack, I'm following how bareudp_dev_create() is written. 

I can follow up in net-next and change both, sounds good?
Cong Wang Jan. 5, 2021, 11:36 p.m. UTC | #3
On Tue, Jan 5, 2021 at 2:39 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Tue, 5 Jan 2021 12:38:54 -0800 Cong Wang wrote:
> > On Tue, Jan 5, 2021 at 11:07 AM Jakub Kicinski <kuba@kernel.org> wrote:
> > > +static void bareudp_dellink(struct net_device *dev, struct list_head *head)
> > > +{
> > > +       struct bareudp_dev *bareudp = netdev_priv(dev);
> > > +
> > > +       list_del(&bareudp->next);
> > > +       unregister_netdevice_queue(dev, head);
> > > +}
> > > +
> > >  static int bareudp_newlink(struct net *net, struct net_device *dev,
> > >                            struct nlattr *tb[], struct nlattr *data[],
> > >                            struct netlink_ext_ack *extack)
> > >  {
> > >         struct bareudp_conf conf;
> > > +       LIST_HEAD(list_kill);
> > >         int err;
> > >
> > >         err = bareudp2info(data, &conf, extack);
> > > @@ -662,17 +671,14 @@ static int bareudp_newlink(struct net *net, struct net_device *dev,
> > >
> > >         err = bareudp_link_config(dev, tb);
> > >         if (err)
> > > -               return err;
> > > +               goto err_unconfig;
> > >
> > >         return 0;
> > > -}
> > > -
> > > -static void bareudp_dellink(struct net_device *dev, struct list_head *head)
> > > -{
> > > -       struct bareudp_dev *bareudp = netdev_priv(dev);
> > >
> > > -       list_del(&bareudp->next);
> > > -       unregister_netdevice_queue(dev, head);
> > > +err_unconfig:
> > > +       bareudp_dellink(dev, &list_kill);
> > > +       unregister_netdevice_many(&list_kill);
> >
> > Why do we need unregister_netdevice_many() here? I think
> > bareudp_dellink(dev, NULL) is sufficient as we always have
> > one instance to unregister?
> >
> > (For the same reason, bareudp_dev_create() does not need it
> > either.)
>
> Ack, I'm following how bareudp_dev_create() is written.
>
> I can follow up in net-next and change both, sounds good?

Yes, either way is fine.

Thanks.
patchwork-bot+netdevbpf@kernel.org Jan. 7, 2021, midnight UTC | #4
Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Tue,  5 Jan 2021 11:07:25 -0800 you wrote:
> .dellink does not get called after .newlink fails,
> bareudp_newlink() must undo what bareudp_configure()
> has done if bareudp_link_config() fails.
> 
> v2: call bareudp_dellink(), like bareudp_dev_create() does
> 
> Fixes: 571912c69f0e ("net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS, IP, NSH etc.")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> 
> [...]

Here is the summary with links:
  - [net,v2] net: bareudp: add missing error handling for bareudp_link_config()
    https://git.kernel.org/netdev/net/c/94bcfdbff0c2

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c
index 708171c0d628..85de5f96c02b 100644
--- a/drivers/net/bareudp.c
+++ b/drivers/net/bareudp.c
@@ -645,11 +645,20 @@  static int bareudp_link_config(struct net_device *dev,
 	return 0;
 }
 
+static void bareudp_dellink(struct net_device *dev, struct list_head *head)
+{
+	struct bareudp_dev *bareudp = netdev_priv(dev);
+
+	list_del(&bareudp->next);
+	unregister_netdevice_queue(dev, head);
+}
+
 static int bareudp_newlink(struct net *net, struct net_device *dev,
 			   struct nlattr *tb[], struct nlattr *data[],
 			   struct netlink_ext_ack *extack)
 {
 	struct bareudp_conf conf;
+	LIST_HEAD(list_kill);
 	int err;
 
 	err = bareudp2info(data, &conf, extack);
@@ -662,17 +671,14 @@  static int bareudp_newlink(struct net *net, struct net_device *dev,
 
 	err = bareudp_link_config(dev, tb);
 	if (err)
-		return err;
+		goto err_unconfig;
 
 	return 0;
-}
-
-static void bareudp_dellink(struct net_device *dev, struct list_head *head)
-{
-	struct bareudp_dev *bareudp = netdev_priv(dev);
 
-	list_del(&bareudp->next);
-	unregister_netdevice_queue(dev, head);
+err_unconfig:
+	bareudp_dellink(dev, &list_kill);
+	unregister_netdevice_many(&list_kill);
+	return err;
 }
 
 static size_t bareudp_get_size(const struct net_device *dev)