Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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/20220727193415.1583860-3-bvanassche@acm.org
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

authored by

Bart Van Assche and committed by
Jason Gunthorpe
aa7dfbb4 b03b1ae2

+17 -2
+15 -2
drivers/infiniband/ulp/srpt/ib_srpt.c
··· 3104 3104 return ret; 3105 3105 } 3106 3106 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 + 3107 3119 /** 3108 3120 * srpt_add_one - InfiniBand device addition callback function 3109 3121 * @device: Describes a HCA. ··· 3134 3122 if (!sdev) 3135 3123 return -ENOMEM; 3136 3124 3125 + kref_init(&sdev->refcnt); 3137 3126 sdev->device = device; 3138 3127 mutex_init(&sdev->sdev_mutex); 3139 3128 ··· 3230 3217 srpt_free_srq(sdev); 3231 3218 ib_dealloc_pd(sdev->pd); 3232 3219 free_dev: 3233 - kfree(sdev); 3220 + srpt_sdev_put(sdev); 3234 3221 pr_info("%s(%s) failed.\n", __func__, dev_name(&device->dev)); 3235 3222 return ret; 3236 3223 } ··· 3274 3261 3275 3262 ib_dealloc_pd(sdev->pd); 3276 3263 3277 - kfree(sdev); 3264 + srpt_sdev_put(sdev); 3278 3265 } 3279 3266 3280 3267 static struct ib_client srpt_client = {
+2
drivers/infiniband/ulp/srpt/ib_srpt.h
··· 434 434 435 435 /** 436 436 * struct srpt_device - information associated by SRPT with a single HCA 437 + * @refcnt: Reference count for this device. 437 438 * @device: Backpointer to the struct ib_device managed by the IB core. 438 439 * @pd: IB protection domain. 439 440 * @lkey: L_Key (local key) with write access to all local memory. ··· 450 449 * @port: Information about the ports owned by this HCA. 451 450 */ 452 451 struct srpt_device { 452 + struct kref refcnt; 453 453 struct ib_device *device; 454 454 struct ib_pd *pd; 455 455 u32 lkey;