RDMA/cm: Fix checking for allowed duplicate listens
authorJason Gunthorpe <jgg@mellanox.com>
Tue, 10 Mar 2020 09:25:32 +0000 (11:25 +0200)
committerJason Gunthorpe <jgg@mellanox.com>
Tue, 17 Mar 2020 20:05:51 +0000 (17:05 -0300)
The test here typod the cm_id_priv to use, it used the one that was
freshly allocated. By definition the allocated one has the matching
cm_handler and zero context, so the condition was always true.

Instead check that the existing listening ID is compatible with the
proposed handler so that it can be shared, as was originally intended.

Fixes: 067b171b8679 ("IB/cm: Share listening CM IDs")
Link: https://lore.kernel.org/r/20200310092545.251365-3-leon@kernel.org
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/core/cm.c

index db627fa3cd3976fb547dbb9c5dd05f46cb73f7b6..ba35cad951e6b6a0e88aac1b14dd8a5cf83b401e 100644 (file)
@@ -1181,7 +1181,8 @@ struct ib_cm_id *ib_cm_insert_listen(struct ib_device *device,
        /* Find an existing ID */
        cm_id_priv = cm_find_listen(device, service_id);
        if (cm_id_priv) {
-               if (cm_id->cm_handler != cm_handler || cm_id->context) {
+               if (cm_id_priv->id.cm_handler != cm_handler ||
+                   cm_id_priv->id.context) {
                        /* Sharing an ib_cm_id with different handlers is not
                         * supported */
                        spin_unlock_irqrestore(&cm.lock, flags);