aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeon Romanovsky <leonro@mellanox.com>2018-10-02 04:13:30 -0400
committerDoug Ledford <dledford@redhat.com>2018-10-16 14:36:21 -0400
commit551d315e34a5e6961f8deaf2d6f37ad24fccaa08 (patch)
tree68cc4cf0d25d6c395f3ae55cc02ec85e8ec647fc
parent90f6e41cc03a4055d56e94ad7c97df4b1add7f61 (diff)
RDMA/umad: Use kernel API to allocate umad indexes
Replace custom code to allocate indexes to generic kernel API. Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r--drivers/infiniband/core/user_mad.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c
index 9961859da06a..f55f48f6b272 100644
--- a/drivers/infiniband/core/user_mad.c
+++ b/drivers/infiniband/core/user_mad.c
@@ -138,7 +138,7 @@ static const dev_t base_issm_dev = MKDEV(IB_UMAD_MAJOR, IB_UMAD_MINOR_BASE) +
138static dev_t dynamic_umad_dev; 138static dev_t dynamic_umad_dev;
139static dev_t dynamic_issm_dev; 139static dev_t dynamic_issm_dev;
140 140
141static DECLARE_BITMAP(dev_map, IB_UMAD_MAX_PORTS); 141static DEFINE_IDA(umad_ida);
142 142
143static void ib_umad_add_one(struct ib_device *device); 143static void ib_umad_add_one(struct ib_device *device);
144static void ib_umad_remove_one(struct ib_device *device, void *client_data); 144static void ib_umad_remove_one(struct ib_device *device, void *client_data);
@@ -1159,11 +1159,10 @@ static int ib_umad_init_port(struct ib_device *device, int port_num,
1159 dev_t base_umad; 1159 dev_t base_umad;
1160 dev_t base_issm; 1160 dev_t base_issm;
1161 1161
1162 devnum = find_first_zero_bit(dev_map, IB_UMAD_MAX_PORTS); 1162 devnum = ida_alloc_max(&umad_ida, IB_UMAD_MAX_PORTS - 1, GFP_KERNEL);
1163 if (devnum >= IB_UMAD_MAX_PORTS) 1163 if (devnum < 0)
1164 return -1; 1164 return -1;
1165 port->dev_num = devnum; 1165 port->dev_num = devnum;
1166 set_bit(devnum, dev_map);
1167 if (devnum >= IB_UMAD_NUM_FIXED_MINOR) { 1166 if (devnum >= IB_UMAD_NUM_FIXED_MINOR) {
1168 base_umad = dynamic_umad_dev + devnum - IB_UMAD_NUM_FIXED_MINOR; 1167 base_umad = dynamic_umad_dev + devnum - IB_UMAD_NUM_FIXED_MINOR;
1169 base_issm = dynamic_issm_dev + devnum - IB_UMAD_NUM_FIXED_MINOR; 1168 base_issm = dynamic_issm_dev + devnum - IB_UMAD_NUM_FIXED_MINOR;
@@ -1227,7 +1226,7 @@ err_dev:
1227 1226
1228err_cdev: 1227err_cdev:
1229 cdev_del(&port->cdev); 1228 cdev_del(&port->cdev);
1230 clear_bit(devnum, dev_map); 1229 ida_free(&umad_ida, devnum);
1231 1230
1232 return -1; 1231 return -1;
1233} 1232}
@@ -1261,7 +1260,7 @@ static void ib_umad_kill_port(struct ib_umad_port *port)
1261 } 1260 }
1262 1261
1263 mutex_unlock(&port->file_mutex); 1262 mutex_unlock(&port->file_mutex);
1264 clear_bit(port->dev_num, dev_map); 1263 ida_free(&umad_ida, port->dev_num);
1265} 1264}
1266 1265
1267static void ib_umad_add_one(struct ib_device *device) 1266static void ib_umad_add_one(struct ib_device *device)