public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Leon Romanovsky <leonro-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Subject: [rdma-rc 08/11] IB/ipoib: Clean error paths in add port
Date: Wed, 26 Jul 2017 21:12:29 +0300	[thread overview]
Message-ID: <20170726181232.7363-9-leon@kernel.org> (raw)
In-Reply-To: <20170726181232.7363-1-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>

From: Leon Romanovsky <leonro-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>

Refactor error paths in ipoib_add_port() function. The code flow
ensures that the function terminates on every error flow and it makes
redundant all "else" cases.

The functions are called during the flow are returning "result < 0", in
case of error, so there is no need to check it explicitly.

Fixes: 58e9cc90cda7 ("IB/IPoIB: Fix bad error flow in ipoib_add_port()")
Signed-off-by: Leon Romanovsky <leonro-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Signed-off-by: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 drivers/infiniband/ulp/ipoib/ipoib_main.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 24fa87fe0952..6c77df34869d 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -2175,14 +2175,14 @@ static struct net_device *ipoib_add_port(const char *format,
 	priv->dev->dev_id = port - 1;
 
 	result = ib_query_port(hca, port, &attr);
-	if (!result)
-		priv->max_ib_mtu = ib_mtu_enum_to_int(attr.max_mtu);
-	else {
+	if (result) {
 		printk(KERN_WARNING "%s: ib_query_port %d failed\n",
 		       hca->name, port);
 		goto device_init_failed;
 	}
 
+	priv->max_ib_mtu = ib_mtu_enum_to_int(attr.max_mtu);
+
 	/* MTU will be reset when mcast join happens */
 	priv->dev->mtu  = IPOIB_UD_MTU(priv->max_ib_mtu);
 	priv->mcast_mtu  = priv->admin_mtu = priv->dev->mtu;
@@ -2213,12 +2213,14 @@ static struct net_device *ipoib_add_port(const char *format,
 		printk(KERN_WARNING "%s: ib_query_gid port %d failed (ret = %d)\n",
 		       hca->name, port, result);
 		goto device_init_failed;
-	} else
-		memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid));
+	}
+
+	memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw,
+	       sizeof(union ib_gid));
 	set_bit(IPOIB_FLAG_DEV_ADDR_SET, &priv->flags);
 
 	result = ipoib_dev_init(priv->dev, hca, port);
-	if (result < 0) {
+	if (result) {
 		printk(KERN_WARNING "%s: failed to initialize port %d (ret = %d)\n",
 		       hca->name, port, result);
 		goto device_init_failed;
-- 
2.13.3

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

  parent reply	other threads:[~2017-07-26 18:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-26 18:12 [pull request][rdma-rc 00/11] IPoIB fixes for 4.13 Leon Romanovsky
     [not found] ` <20170726181232.7363-1-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-07-26 18:12   ` [rdma-rc 01/11] IB/ipoib: Fix race between light events and interface restart Leon Romanovsky
2017-07-26 18:12   ` [rdma-rc 02/11] IB/ipoib: Use cancel_delayed_work_sync when needed Leon Romanovsky
2017-07-26 18:12   ` [rdma-rc 03/11] IB/ipoib: Make sure no in-flight joins while leaving that mcast Leon Romanovsky
2017-07-26 18:12   ` [rdma-rc 04/11] IB/ipoib: Prevent setting negative values to max_nonsrq_conn_qp Leon Romanovsky
2017-07-26 18:12   ` [rdma-rc 05/11] IB/ipoib: Set IPOIB_NEIGH_TBL_FLUSH after flushed completion initialization Leon Romanovsky
2017-07-26 18:12   ` [rdma-rc 06/11] IB/ipoib: Add multicast packets statistics Leon Romanovsky
2017-07-26 18:12   ` [rdma-rc 07/11] IB/ipoib: Add get statistics support to SRIOV VF Leon Romanovsky
2017-07-26 18:12   ` Leon Romanovsky [this message]
2017-07-26 18:12   ` [rdma-rc 09/11] IB/ipoib: Remove double pointer assigning Leon Romanovsky
2017-07-26 18:12   ` [rdma-rc 10/11] Revert "IB/core: Allow QP state transition from reset to error" Leon Romanovsky
     [not found]     ` <20170726181232.7363-11-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-07-27 14:52       ` Dennis Dalessandro
     [not found]         ` <49fe625b-cd44-137e-c001-1d85297f4e62-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-07-27 14:57           ` Dennis Dalessandro
     [not found]             ` <fcacf34e-d16f-3d66-2877-be5b5993f296-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-07-30  5:17               ` Leon Romanovsky
2017-07-26 18:12   ` [rdma-rc 11/11] IB/ipoib: Notify on modify QP failure only when relevant Leon Romanovsky
     [not found]     ` <20170726181232.7363-12-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-07-27 14:59       ` Dennis Dalessandro
2017-07-27 15:05   ` [pull request][rdma-rc 00/11] IPoIB fixes for 4.13 Dennis Dalessandro
     [not found]     ` <2679977c-6258-ed15-a234-3682b8be65f3-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-07-27 15:06       ` Dennis Dalessandro
     [not found]         ` <3eb7d0e3-b1ef-533e-56ae-9cc6b65ddfc5-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-07-30  5:23           ` Leon Romanovsky
2017-08-07 17:35           ` Doug Ledford
2017-08-06  8:20   ` Leon Romanovsky
     [not found]     ` <20170806082018.GD3636-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>
2017-08-07 15:58       ` Doug Ledford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170726181232.7363-9-leon@kernel.org \
    --to=leon-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=leonro-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox