Skip to content

Commit aa7dfbb

Browse files
bvanasschejgunthorpe
authored andcommitted
RDMA/srpt: Introduce a reference count in struct srpt_device
This will be used to keep struct srpt_device around as long as either the RDMA port exists or a LIO target port is associated with the struct srpt_device. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent b03b1ae commit aa7dfbb

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

drivers/infiniband/ulp/srpt/ib_srpt.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,6 +3104,18 @@ static int srpt_use_srq(struct srpt_device *sdev, bool use_srq)
31043104
return ret;
31053105
}
31063106

3107+
static void srpt_free_sdev(struct kref *refcnt)
3108+
{
3109+
struct srpt_device *sdev = container_of(refcnt, typeof(*sdev), refcnt);
3110+
3111+
kfree(sdev);
3112+
}
3113+
3114+
static void srpt_sdev_put(struct srpt_device *sdev)
3115+
{
3116+
kref_put(&sdev->refcnt, srpt_free_sdev);
3117+
}
3118+
31073119
/**
31083120
* srpt_add_one - InfiniBand device addition callback function
31093121
* @device: Describes a HCA.
@@ -3122,6 +3134,7 @@ static int srpt_add_one(struct ib_device *device)
31223134
if (!sdev)
31233135
return -ENOMEM;
31243136

3137+
kref_init(&sdev->refcnt);
31253138
sdev->device = device;
31263139
mutex_init(&sdev->sdev_mutex);
31273140

@@ -3217,7 +3230,7 @@ static int srpt_add_one(struct ib_device *device)
32173230
srpt_free_srq(sdev);
32183231
ib_dealloc_pd(sdev->pd);
32193232
free_dev:
3220-
kfree(sdev);
3233+
srpt_sdev_put(sdev);
32213234
pr_info("%s(%s) failed.\n", __func__, dev_name(&device->dev));
32223235
return ret;
32233236
}
@@ -3261,7 +3274,7 @@ static void srpt_remove_one(struct ib_device *device, void *client_data)
32613274

32623275
ib_dealloc_pd(sdev->pd);
32633276

3264-
kfree(sdev);
3277+
srpt_sdev_put(sdev);
32653278
}
32663279

32673280
static struct ib_client srpt_client = {

drivers/infiniband/ulp/srpt/ib_srpt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ struct srpt_port {
434434

435435
/**
436436
* struct srpt_device - information associated by SRPT with a single HCA
437+
* @refcnt: Reference count for this device.
437438
* @device: Backpointer to the struct ib_device managed by the IB core.
438439
* @pd: IB protection domain.
439440
* @lkey: L_Key (local key) with write access to all local memory.
@@ -449,6 +450,7 @@ struct srpt_port {
449450
* @port: Information about the ports owned by this HCA.
450451
*/
451452
struct srpt_device {
453+
struct kref refcnt;
452454
struct ib_device *device;
453455
struct ib_pd *pd;
454456
u32 lkey;

0 commit comments

Comments
 (0)