linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RDMA/iw_cgxb4: Fix an error handling path in 'c4iw_connect()'
@ 2019-09-23 19:07 Christophe JAILLET
  2019-10-01  9:02 ` Dan Carpenter
  2019-11-15 21:00 ` Jason Gunthorpe
  0 siblings, 2 replies; 4+ messages in thread
From: Christophe JAILLET @ 2019-09-23 19:07 UTC (permalink / raw)
  To: bharat, dledford, jgg
  Cc: linux-rdma, linux-kernel, kernel-janitors, Christophe JAILLET

We should jump to fail3 in order to undo the 'xa_insert_irq()' call.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Not sure which Fixes tag to use because of the many refactorings in this
area. So I've choosen to use none :).
The issue was already there in 4a740838bf44c. This commit has renamed
all labels because a new fail1 was introduced. I've not searched further.

Naming of error labels should be improved. Having nowadays a fail5
between fail2 and fail3 (because fail5 was the last
error handling path added) is not that readable.
However, it goes beyong the purpose of this patch.

Maybe, just using a fail2a, just as already done in 9f5a9632e412 (which
introduced fail5) would be enough.
---
 drivers/infiniband/hw/cxgb4/cm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index e87fc0408470..81440eaf0a00 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -3381,7 +3381,7 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
 		if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
 			err = pick_local_ipaddrs(dev, cm_id);
 			if (err)
-				goto fail2;
+				goto fail3;
 		}
 
 		/* find a route */
@@ -3403,7 +3403,7 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
 		if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
 			err = pick_local_ip6addrs(dev, cm_id);
 			if (err)
-				goto fail2;
+				goto fail3;
 		}
 
 		/* find a route */
-- 
2.20.1


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

* Re: [PATCH] RDMA/iw_cgxb4: Fix an error handling path in 'c4iw_connect()'
  2019-09-23 19:07 [PATCH] RDMA/iw_cgxb4: Fix an error handling path in 'c4iw_connect()' Christophe JAILLET
@ 2019-10-01  9:02 ` Dan Carpenter
  2019-11-15 21:00 ` Jason Gunthorpe
  1 sibling, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2019-10-01  9:02 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: bharat, dledford, jgg, linux-rdma, linux-kernel, kernel-janitors

On Mon, Sep 23, 2019 at 09:07:46PM +0200, Christophe JAILLET wrote:
> We should jump to fail3 in order to undo the 'xa_insert_irq()' call.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Not sure which Fixes tag to use because of the many refactorings in this
> area. So I've choosen to use none :).
> The issue was already there in 4a740838bf44c. This commit has renamed
> all labels because a new fail1 was introduced. I've not searched further.
> 
> Naming of error labels should be improved. Having nowadays a fail5
> between fail2 and fail3 (because fail5 was the last
> error handling path added) is not that readable.
> However, it goes beyong the purpose of this patch.
> 
> Maybe, just using a fail2a, just as already done in 9f5a9632e412 (which
> introduced fail5) would be enough.

I think/hope that you're joking.  Anyway, these are GW-BASIC style
labels.  The other anti-pattern that we sometimes see is come-from
labels where the code does:

	foo = kmalloc();
	if (!foo)
		goto kmalloc_failed;

We've no clue what the goto does.  And another anti-pattern is generic
names where we have "goto out;" instead of a better label name which
says what the goto does "goto unlock;".  Otherwise we have to scroll
down every time we encounter a goto.

Imagine if we used the same anti patterns for naming functions:

	called_from_frob_1();
	called_from_frob_2();

And with a string of error lables like this if we name the error labels
after what the label frees then it makes auditing the function very
easy.

	one = alloc();
	if (!one)
		return -ENOMEM;

	two = alloc();
	if (!two) {
		ret = -ENOMEM;
		goto free_one;
	}

	three = alloc();
	if (!three) {
		ret = -ENOMEM;
		goto free_two;
	}

We only need to remember the most recently allocated resource.  And if
we need to update the function later then the patch is minimal because
we only need to change the one goto and the error label.  No need to
re-number everything.  You can audit a patch with properly named labels
from directly within your email client instead of needing to re-review
the whole function in the source.

regards,
dan carpenter

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

* Re: [PATCH] RDMA/iw_cgxb4: Fix an error handling path in 'c4iw_connect()'
  2019-09-23 19:07 [PATCH] RDMA/iw_cgxb4: Fix an error handling path in 'c4iw_connect()' Christophe JAILLET
  2019-10-01  9:02 ` Dan Carpenter
@ 2019-11-15 21:00 ` Jason Gunthorpe
  2019-11-18 17:39   ` Steve Wise
  1 sibling, 1 reply; 4+ messages in thread
From: Jason Gunthorpe @ 2019-11-15 21:00 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: bharat, dledford, linux-rdma, linux-kernel, kernel-janitors

On Mon, Sep 23, 2019 at 09:07:46PM +0200, Christophe JAILLET wrote:
> We should jump to fail3 in order to undo the 'xa_insert_irq()' call.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Not sure which Fixes tag to use because of the many refactorings in this
> area. So I've choosen to use none :).
> The issue was already there in 4a740838bf44c. This commit has renamed
> all labels because a new fail1 was introduced. I've not searched further.
> 
> Naming of error labels should be improved. Having nowadays a fail5
> between fail2 and fail3 (because fail5 was the last
> error handling path added) is not that readable.
> However, it goes beyong the purpose of this patch.
> 
> Maybe, just using a fail2a, just as already done in 9f5a9632e412 (which
> introduced fail5) would be enough.
> ---
>  drivers/infiniband/hw/cxgb4/cm.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

The disaster of the error label aside, this does fix the bug, so
applied to for-next

Thanks,
Jason

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

* Re: [PATCH] RDMA/iw_cgxb4: Fix an error handling path in 'c4iw_connect()'
  2019-11-15 21:00 ` Jason Gunthorpe
@ 2019-11-18 17:39   ` Steve Wise
  0 siblings, 0 replies; 4+ messages in thread
From: Steve Wise @ 2019-11-18 17:39 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Christophe JAILLET, Potnuri Bharat Teja, Doug Ledford,
	linux-rdma, linux-kernel, kernel-janitors

Those horrible error labels in cxgb* are my bad.  :(   I now always
use descriptive labels.

Stevo

On Fri, Nov 15, 2019 at 3:01 PM Jason Gunthorpe <jgg@ziepe.ca> wrote:
>
> On Mon, Sep 23, 2019 at 09:07:46PM +0200, Christophe JAILLET wrote:
> > We should jump to fail3 in order to undo the 'xa_insert_irq()' call.
> >
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > ---
> > Not sure which Fixes tag to use because of the many refactorings in this
> > area. So I've choosen to use none :).
> > The issue was already there in 4a740838bf44c. This commit has renamed
> > all labels because a new fail1 was introduced. I've not searched further.
> >
> > Naming of error labels should be improved. Having nowadays a fail5
> > between fail2 and fail3 (because fail5 was the last
> > error handling path added) is not that readable.
> > However, it goes beyong the purpose of this patch.
> >
> > Maybe, just using a fail2a, just as already done in 9f5a9632e412 (which
> > introduced fail5) would be enough.
> > ---
> >  drivers/infiniband/hw/cxgb4/cm.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
>
> The disaster of the error label aside, this does fix the bug, so
> applied to for-next
>
> Thanks,
> Jason

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

end of thread, other threads:[~2019-11-18 17:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-23 19:07 [PATCH] RDMA/iw_cgxb4: Fix an error handling path in 'c4iw_connect()' Christophe JAILLET
2019-10-01  9:02 ` Dan Carpenter
2019-11-15 21:00 ` Jason Gunthorpe
2019-11-18 17:39   ` Steve Wise

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