netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: bareudp: add missing error handling for bareudp_link_config()
@ 2020-12-31  3:44 Jakub Kicinski
  2021-01-02 23:49 ` Cong Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2020-12-31  3:44 UTC (permalink / raw)
  To: davem; +Cc: netdev, martin.varghese, willemb, Jakub Kicinski

.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(-)

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)
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: bareudp: add missing error handling for bareudp_link_config()
  2020-12-31  3:44 [PATCH net] net: bareudp: add missing error handling for bareudp_link_config() Jakub Kicinski
@ 2021-01-02 23:49 ` Cong Wang
  2021-01-04 17:49   ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Cong Wang @ 2021-01-02 23:49 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David Miller, Linux Kernel Network Developers, martin.varghese,
	Willem de Bruijn

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: bareudp: add missing error handling for bareudp_link_config()
  2021-01-02 23:49 ` Cong Wang
@ 2021-01-04 17:49   ` Jakub Kicinski
  2021-01-05  6:22     ` Cong Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2021-01-04 17:49 UTC (permalink / raw)
  To: Cong Wang
  Cc: David Miller, Linux Kernel Network Developers, martin.varghese,
	Willem de Bruijn

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: bareudp: add missing error handling for bareudp_link_config()
  2021-01-04 17:49   ` Jakub Kicinski
@ 2021-01-05  6:22     ` Cong Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Cong Wang @ 2021-01-05  6:22 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David Miller, Linux Kernel Network Developers, martin.varghese,
	Willem de Bruijn

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-05  6:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-31  3:44 [PATCH net] net: bareudp: add missing error handling for bareudp_link_config() Jakub Kicinski
2021-01-02 23:49 ` Cong Wang
2021-01-04 17:49   ` Jakub Kicinski
2021-01-05  6:22     ` Cong Wang

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).