]> git.baikalelectronics.ru Git - kernel.git/commitdiff
IB/mlx5: Fix memory leak in clean_mr error path
authorKamal Heib <kamalh@mellanox.com>
Thu, 17 Aug 2017 12:52:31 +0000 (15:52 +0300)
committerDoug Ledford <dledford@redhat.com>
Thu, 24 Aug 2017 21:47:34 +0000 (17:47 -0400)
In clean_mr error path the 'mr' should be freed.

Fixes: e126ba97dba9 ('mlx5: Add driver for Mellanox Connect-IB adapters')
Signed-off-by: Kamal Heib <kamalh@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/hw/mlx5/mr.c

index aa6f71570b77be7e3ca1b5f98e7ec1aa25a0e93c..8cf53eb131482c2e2a8df08d040a1042fc46f7d3 100644 (file)
@@ -1490,19 +1490,19 @@ static int clean_mr(struct mlx5_ib_mr *mr)
        mlx5_free_priv_descs(mr);
 
        if (!allocated_from_cache) {
+               u32 key = mr->mmkey.key;
+
                err = destroy_mkey(dev, mr);
+               kfree(mr);
                if (err) {
                        mlx5_ib_warn(dev, "failed to destroy mkey 0x%x (%d)\n",
-                                    mr->mmkey.key, err);
+                                    key, err);
                        return err;
                }
        } else {
                mlx5_mr_cache_free(dev, mr);
        }
 
-       if (!allocated_from_cache)
-               kfree(mr);
-
        return 0;
 }