* [PATCH/RFC] mlx4_core: Clean up error flow in mlx4_register_mac()
@ 2011-09-20 7:53 Roland Dreier
[not found] ` <1316505227-6031-1-git-send-email-roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Roland Dreier @ 2011-09-20 7:53 UTC (permalink / raw)
To: Yevgeny Petrilin, linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Roland Dreier
From: Roland Dreier <roland-BHEL68pLQRGGvPXPguhicg@public.gmane.org>
Fix a leak of entry if radix_tree_insert() fails.
Also, reduce the indentation and make the flow easier to read by
sticking to the conventional
err = do_something();
if (err)
return err;
err = do_another();
if (err)
return err;
rather than mixing the direction of the test as
err = do_something();
if (!err) {
err = do_another();
if (err)
return err;
} else
return err;
Signed-off-by: Roland Dreier <roland-BHEL68pLQRGGvPXPguhicg@public.gmane.org>
---
drivers/net/mlx4/port.c | 30 +++++++++++++++++-------------
1 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/drivers/net/mlx4/port.c b/drivers/net/mlx4/port.c
index 609e0ec..ef10113 100644
--- a/drivers/net/mlx4/port.c
+++ b/drivers/net/mlx4/port.c
@@ -148,22 +148,26 @@ int mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac, int *qpn, u8 wrap)
if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER) {
err = mlx4_uc_steer_add(dev, port, mac, qpn, 1);
- if (!err) {
- entry = kmalloc(sizeof *entry, GFP_KERNEL);
- if (!entry) {
- mlx4_uc_steer_release(dev, port, mac, *qpn, 1);
- return -ENOMEM;
- }
- entry->mac = mac;
- err = radix_tree_insert(&info->mac_tree, *qpn, entry);
- if (err) {
- mlx4_uc_steer_release(dev, port, mac, *qpn, 1);
- return err;
- }
- } else
+ if (err)
return err;
+
+ entry = kmalloc(sizeof *entry, GFP_KERNEL);
+ if (!entry) {
+ mlx4_uc_steer_release(dev, port, mac, *qpn, 1);
+ return -ENOMEM;
+ }
+
+ entry->mac = mac;
+ err = radix_tree_insert(&info->mac_tree, *qpn, entry);
+ if (err) {
+ kfree(entry);
+ mlx4_uc_steer_release(dev, port, mac, *qpn, 1);
+ return err;
+ }
}
+
mlx4_dbg(dev, "Registering MAC: 0x%llx\n", (unsigned long long) mac);
+
mutex_lock(&table->mutex);
for (i = 0; i < MLX4_MAX_MAC_NUM - 1; i++) {
if (free < 0 && !table->refs[i]) {
--
1.7.5.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH/RFC] mlx4_core: Clean up error flow in mlx4_register_mac()
[not found] ` <1316505227-6031-1-git-send-email-roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
@ 2011-09-21 15:16 ` Or Gerlitz
[not found] ` <4E79FFBA.2090004-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Or Gerlitz @ 2011-09-21 15:16 UTC (permalink / raw)
To: Roland Dreier
Cc: Yevgeny Petrilin, linux-rdma-u79uwXL29TY76Z2rM5mHXA,
Roland Dreier
On 9/20/2011 10:53 AM, Roland Dreier wrote:
> Fix a leak of entry if radix_tree_insert() fails.
> Also, reduce the indentation and make the flow easier to read
Looks fine to me
Acked-by: Or Gerlitz <ogerlitz-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Yevgeny?
Or.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH/RFC] mlx4_core: Clean up error flow in mlx4_register_mac()
[not found] ` <4E79FFBA.2090004-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
@ 2011-09-21 15:25 ` Yevgeny Petrilin
0 siblings, 0 replies; 3+ messages in thread
From: Yevgeny Petrilin @ 2011-09-21 15:25 UTC (permalink / raw)
To: Or Gerlitz, Roland Dreier
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Roland Dreier
> > Fix a leak of entry if radix_tree_insert() fails.
> > Also, reduce the indentation and make the flow easier to read
>
> Looks fine to me
>
> Acked-by: Or Gerlitz <ogerlitz-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
>
> Yevgeny?
>
The fix is OK.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-09-21 15:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-20 7:53 [PATCH/RFC] mlx4_core: Clean up error flow in mlx4_register_mac() Roland Dreier
[not found] ` <1316505227-6031-1-git-send-email-roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2011-09-21 15:16 ` Or Gerlitz
[not found] ` <4E79FFBA.2090004-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2011-09-21 15:25 ` Yevgeny Petrilin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox