IB/ipoib: Set device connection mode only when needed
authorFeras Daoud <ferasda@mellanox.com>
Wed, 28 Dec 2016 12:47:21 +0000 (14:47 +0200)
committerBen Hutchings <ben@decadent.org.uk>
Mon, 5 Jun 2017 20:13:41 +0000 (21:13 +0100)
commit 80b5b35aba62232521b31440f0a3cf6caa033849 upstream.

When changing the connection mode, the ipoib_set_mode function
did not check if the previous connection mode equals to the
new one. This commit adds the required check and return 0 if the new
mode equals to the previous one.

Fixes: 839fcaba355a ("IPoIB: Connected mode experimental support")
Signed-off-by: Feras Daoud <ferasda@mellanox.com>
Signed-off-by: Erez Shitrit <erezsh@mellanox.com>
Reviewed-by: Alex Vesker <valex@mellanox.com>
Reviewed-by: Yuval Shaia <yuval.shaia@oracle.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[bwh: Backported to 3.2:
 - Adjust filename
 - Unlock RTNL lock before returning]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/infiniband/ulp/ipoib/ipoib_cm.c

index 0bbe030..2630797 100644 (file)
@@ -1480,6 +1480,14 @@ static ssize_t set_mode(struct device *d, struct device_attribute *attr,
        if (!rtnl_trylock())
                return restart_syscall();
 
+       if ((test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags) &&
+            !strcmp(buf, "connected\n")) ||
+            (!test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags) &&
+            !strcmp(buf, "datagram\n"))) {
+               rtnl_unlock();
+               return 0;
+       }
+
        /* flush paths if we switch modes so that connections are restarted */
        if (IPOIB_CM_SUPPORTED(dev->dev_addr) && !strcmp(buf, "connected\n")) {
                set_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);