diff mbox series

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

Message ID 20201231034417.1570553-1-kuba@kernel.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net] 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: 3 this patch: 3
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, 22 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 3 this patch: 3
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Jakub Kicinski Dec. 31, 2020, 3:44 a.m. UTC
.dellink does not get called after .newlink fails,
bareudp_newlink() must undo what bareudp_configure()
has done if bareudp_link_config() fails.

Fixes: 571912c69f0e ("net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS, IP, NSH etc.")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
Found by code inspection and compile-tested only.

 drivers/net/bareudp.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Cong Wang Jan. 2, 2021, 11:49 p.m. UTC | #1
On Wed, Dec 30, 2020 at 7:46 PM Jakub Kicinski <kuba@kernel.org> wrote:
> @@ -661,9 +662,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;
> +
> +err_unconfig:

I think we can save this goto.

> +       list_del(&bareudp->next);
> +       unregister_netdevice(dev);

Which is bareudp_dellink(dev, NULL). ;)

Thanks.
Jakub Kicinski Jan. 4, 2021, 5:49 p.m. UTC | #2
On Sat, 2 Jan 2021 15:49:54 -0800 Cong Wang wrote:
> On Wed, Dec 30, 2020 at 7:46 PM Jakub Kicinski <kuba@kernel.org> wrote:
> > @@ -661,9 +662,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;
> > +
> > +err_unconfig:  
> 
> I think we can save this goto.

I personally prefer more idiomatic code flow to saving a single LoC.

> > +       list_del(&bareudp->next);
> > +       unregister_netdevice(dev);  
> 
> Which is bareudp_dellink(dev, NULL). ;)

I know, but calling full dellink when only parts of newlink fails felt
weird. And it's not lower LoC, unless called with NULL as second arg,
which again could be surprising to a person changing dellink. 


But I can change both if you feel strongly.
Cong Wang Jan. 5, 2021, 6:22 a.m. UTC | #3
On Mon, Jan 4, 2021 at 9:49 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Sat, 2 Jan 2021 15:49:54 -0800 Cong Wang wrote:
> > On Wed, Dec 30, 2020 at 7:46 PM Jakub Kicinski <kuba@kernel.org> wrote:
> > > @@ -661,9 +662,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;
> > > +
> > > +err_unconfig:
> >
> > I think we can save this goto.
>
> I personally prefer more idiomatic code flow to saving a single LoC.
>
> > > +       list_del(&bareudp->next);
> > > +       unregister_netdevice(dev);
> >
> > Which is bareudp_dellink(dev, NULL). ;)
>
> I know, but calling full dellink when only parts of newlink fails felt
> weird. And it's not lower LoC, unless called with NULL as second arg,
> which again could be surprising to a person changing dellink.

I think calling a function with "bareudp_" prefix is more readable
than interpreting list_del()+unregister_netdevice(). I mean

if (bareudp_*())
  goto err;
...
err:
bareudp_*();

this looks cleaner, right?

Thanks.
diff mbox series

Patch

diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c
index 85ebd2b7e446..7a03a9059ccc 100644
--- a/drivers/net/bareudp.c
+++ b/drivers/net/bareudp.c
@@ -648,6 +648,7 @@  static int bareudp_newlink(struct net *net, struct net_device *dev,
 			   struct nlattr *tb[], struct nlattr *data[],
 			   struct netlink_ext_ack *extack)
 {
+	struct bareudp_dev *bareudp = netdev_priv(dev);
 	struct bareudp_conf conf;
 	int err;
 
@@ -661,9 +662,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;
+
+err_unconfig:
+	list_del(&bareudp->next);
+	unregister_netdevice(dev);
+	return err;
 }
 
 static void bareudp_dellink(struct net_device *dev, struct list_head *head)