diff options
author | Jason Gunthorpe | 2019-02-13 05:12:55 +0100 |
---|---|---|
committer | Jason Gunthorpe | 2019-02-20 04:52:18 +0100 |
commit | 6cc2c8e535ec19153714cee62e11e4d9ac2ea953 (patch) | |
tree | 0c9f07b2e1b2e1249d6bbafda3d9557a6074ee49 /drivers/infiniband/core | |
parent | RDMA/rxe: Use driver_unregister and new unregistration API (diff) | |
download | kernel-qcow2-linux-6cc2c8e535ec19153714cee62e11e4d9ac2ea953.tar.gz kernel-qcow2-linux-6cc2c8e535ec19153714cee62e11e4d9ac2ea953.tar.xz kernel-qcow2-linux-6cc2c8e535ec19153714cee62e11e4d9ac2ea953.zip |
RDMA/rxe: Add ib_device_get_by_name() and use it in rxe
rxe has an open coded version of this that is not as safe as the core
version. This lets us eliminate the internal device list entirely from
rxe.
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Diffstat (limited to 'drivers/infiniband/core')
-rw-r--r-- | drivers/infiniband/core/device.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index e470fa651961..2a7d54794ee3 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -240,6 +240,34 @@ static struct ib_device *__ib_device_get_by_name(const char *name) return NULL; } +/** + * ib_device_get_by_name - Find an IB device by name + * @name: The name to look for + * @driver_id: The driver ID that must match (RDMA_DRIVER_UNKNOWN matches all) + * + * Find and hold an ib_device by its name. The caller must call + * ib_device_put() on the returned pointer. + */ +struct ib_device *ib_device_get_by_name(const char *name, + enum rdma_driver_id driver_id) +{ + struct ib_device *device; + + down_read(&devices_rwsem); + device = __ib_device_get_by_name(name); + if (device && driver_id != RDMA_DRIVER_UNKNOWN && + device->driver_id != driver_id) + device = NULL; + + if (device) { + if (!ib_device_try_get(device)) + device = NULL; + } + up_read(&devices_rwsem); + return device; +} +EXPORT_SYMBOL(ib_device_get_by_name); + int ib_device_rename(struct ib_device *ibdev, const char *name) { int ret; |