mirror of
https://github.com/Dasharo/linux.git
synced 2026-03-06 15:25:10 -08:00
locking/atomic, kref: Add kref_read()
Since we need to change the implementation, stop exposing internals. Provide kref_read() to read the current reference count; typically used for debug messages. Kills two anti-patterns: atomic_read(&kref->refcount) kref->refcount.counter Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
committed by
Ingo Molnar
parent
1e24edca05
commit
2c935bc572
@@ -520,7 +520,7 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m,
|
||||
/* Completion does it's own kref_put. If we are going to
|
||||
* kref_sub below, we need req to be still around then. */
|
||||
int at_least = k_put + !!c_put;
|
||||
int refcount = atomic_read(&req->kref.refcount);
|
||||
int refcount = kref_read(&req->kref);
|
||||
if (refcount < at_least)
|
||||
drbd_err(device,
|
||||
"mod_rq_state: Logic BUG: %x -> %x: refcount = %d, should be >= %d\n",
|
||||
|
||||
@@ -1535,7 +1535,7 @@ static bool obj_request_overlaps_parent(struct rbd_obj_request *obj_request)
|
||||
static void rbd_obj_request_get(struct rbd_obj_request *obj_request)
|
||||
{
|
||||
dout("%s: obj %p (was %d)\n", __func__, obj_request,
|
||||
atomic_read(&obj_request->kref.refcount));
|
||||
kref_read(&obj_request->kref));
|
||||
kref_get(&obj_request->kref);
|
||||
}
|
||||
|
||||
@@ -1544,14 +1544,14 @@ static void rbd_obj_request_put(struct rbd_obj_request *obj_request)
|
||||
{
|
||||
rbd_assert(obj_request != NULL);
|
||||
dout("%s: obj %p (was %d)\n", __func__, obj_request,
|
||||
atomic_read(&obj_request->kref.refcount));
|
||||
kref_read(&obj_request->kref));
|
||||
kref_put(&obj_request->kref, rbd_obj_request_destroy);
|
||||
}
|
||||
|
||||
static void rbd_img_request_get(struct rbd_img_request *img_request)
|
||||
{
|
||||
dout("%s: img %p (was %d)\n", __func__, img_request,
|
||||
atomic_read(&img_request->kref.refcount));
|
||||
kref_read(&img_request->kref));
|
||||
kref_get(&img_request->kref);
|
||||
}
|
||||
|
||||
@@ -1562,7 +1562,7 @@ static void rbd_img_request_put(struct rbd_img_request *img_request)
|
||||
{
|
||||
rbd_assert(img_request != NULL);
|
||||
dout("%s: img %p (was %d)\n", __func__, img_request,
|
||||
atomic_read(&img_request->kref.refcount));
|
||||
kref_read(&img_request->kref));
|
||||
if (img_request_child_test(img_request))
|
||||
kref_put(&img_request->kref, rbd_parent_request_destroy);
|
||||
else
|
||||
|
||||
@@ -767,7 +767,7 @@ static void virtblk_remove(struct virtio_device *vdev)
|
||||
/* Stop all the virtqueues. */
|
||||
vdev->config->reset(vdev);
|
||||
|
||||
refc = atomic_read(&disk_to_dev(vblk->disk)->kobj.kref.refcount);
|
||||
refc = kref_read(&disk_to_dev(vblk->disk)->kobj.kref);
|
||||
put_disk(vblk->disk);
|
||||
vdev->config->del_vqs(vdev);
|
||||
kfree(vblk->vqs);
|
||||
|
||||
@@ -376,7 +376,7 @@ void drm_gem_cma_describe(struct drm_gem_cma_object *cma_obj,
|
||||
off = drm_vma_node_start(&obj->vma_node);
|
||||
|
||||
seq_printf(m, "%2d (%2d) %08llx %pad %p %zu",
|
||||
obj->name, obj->refcount.refcount.counter,
|
||||
obj->name, kref_read(&obj->refcount),
|
||||
off, &cma_obj->paddr, cma_obj->vaddr, obj->size);
|
||||
|
||||
seq_printf(m, "\n");
|
||||
|
||||
@@ -118,7 +118,7 @@ static int drm_gem_one_name_info(int id, void *ptr, void *data)
|
||||
seq_printf(m, "%6d %8zd %7d %8d\n",
|
||||
obj->name, obj->size,
|
||||
obj->handle_count,
|
||||
atomic_read(&obj->refcount.refcount));
|
||||
kref_read(&obj->refcount));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ EXPORT_SYMBOL(drm_mode_object_find);
|
||||
void drm_mode_object_unreference(struct drm_mode_object *obj)
|
||||
{
|
||||
if (obj->free_cb) {
|
||||
DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount));
|
||||
DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, kref_read(&obj->refcount));
|
||||
kref_put(&obj->refcount, obj->free_cb);
|
||||
}
|
||||
}
|
||||
@@ -176,7 +176,7 @@ EXPORT_SYMBOL(drm_mode_object_unreference);
|
||||
void drm_mode_object_reference(struct drm_mode_object *obj)
|
||||
{
|
||||
if (obj->free_cb) {
|
||||
DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount));
|
||||
DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, kref_read(&obj->refcount));
|
||||
kref_get(&obj->refcount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,7 +486,7 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m)
|
||||
|
||||
seq_printf(m, "%08x: %c %2d (%2d) %08lx %p %zd\n",
|
||||
etnaviv_obj->flags, is_active(etnaviv_obj) ? 'A' : 'I',
|
||||
obj->name, obj->refcount.refcount.counter,
|
||||
obj->name, kref_read(&obj->refcount),
|
||||
off, etnaviv_obj->vaddr, obj->size);
|
||||
|
||||
rcu_read_lock();
|
||||
|
||||
@@ -256,7 +256,7 @@ extern void drm_gem_object_unreference_unlocked(struct drm_gem_object *);
|
||||
static inline bool
|
||||
i915_gem_object_is_dead(const struct drm_i915_gem_object *obj)
|
||||
{
|
||||
return atomic_read(&obj->base.refcount.refcount) == 0;
|
||||
return kref_read(&obj->base.refcount) == 0;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
|
||||
@@ -640,7 +640,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m)
|
||||
|
||||
seq_printf(m, "%08x: %c %2d (%2d) %08llx %p\t",
|
||||
msm_obj->flags, is_active(msm_obj) ? 'A' : 'I',
|
||||
obj->name, obj->refcount.refcount.counter,
|
||||
obj->name, kref_read(&obj->refcount),
|
||||
off, msm_obj->vaddr);
|
||||
|
||||
for (id = 0; id < priv->num_aspaces; id++)
|
||||
|
||||
@@ -527,7 +527,7 @@ static bool nouveau_fence_no_signaling(struct dma_fence *f)
|
||||
* caller should have a reference on the fence,
|
||||
* else fence could get freed here
|
||||
*/
|
||||
WARN_ON(atomic_read(&fence->base.refcount.refcount) <= 1);
|
||||
WARN_ON(kref_read(&fence->base.refcount) <= 1);
|
||||
|
||||
/*
|
||||
* This needs uevents to work correctly, but dma_fence_add_callback relies on
|
||||
|
||||
@@ -1033,7 +1033,7 @@ void omap_gem_describe(struct drm_gem_object *obj, struct seq_file *m)
|
||||
off = drm_vma_node_start(&obj->vma_node);
|
||||
|
||||
seq_printf(m, "%08x: %2d (%2d) %08llx %pad (%2d) %p %4d",
|
||||
omap_obj->flags, obj->name, obj->refcount.refcount.counter,
|
||||
omap_obj->flags, obj->name, kref_read(&obj->refcount),
|
||||
off, &omap_obj->paddr, omap_obj->paddr_cnt,
|
||||
omap_obj->vaddr, omap_obj->roll);
|
||||
|
||||
|
||||
@@ -140,8 +140,8 @@ static void ttm_bo_release_list(struct kref *list_kref)
|
||||
struct ttm_bo_device *bdev = bo->bdev;
|
||||
size_t acc_size = bo->acc_size;
|
||||
|
||||
BUG_ON(atomic_read(&bo->list_kref.refcount));
|
||||
BUG_ON(atomic_read(&bo->kref.refcount));
|
||||
BUG_ON(kref_read(&bo->list_kref));
|
||||
BUG_ON(kref_read(&bo->kref));
|
||||
BUG_ON(atomic_read(&bo->cpu_writers));
|
||||
BUG_ON(bo->mem.mm_node != NULL);
|
||||
BUG_ON(!list_empty(&bo->lru));
|
||||
|
||||
@@ -304,7 +304,7 @@ bool ttm_ref_object_exists(struct ttm_object_file *tfile,
|
||||
* Verify that the ref->obj pointer was actually valid!
|
||||
*/
|
||||
rmb();
|
||||
if (unlikely(atomic_read(&ref->kref.refcount) == 0))
|
||||
if (unlikely(kref_read(&ref->kref) == 0))
|
||||
goto out_false;
|
||||
|
||||
rcu_read_unlock();
|
||||
|
||||
@@ -55,14 +55,14 @@
|
||||
|
||||
#define put_ep(ep) { \
|
||||
PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__, \
|
||||
ep, atomic_read(&((ep)->kref.refcount))); \
|
||||
WARN_ON(atomic_read(&((ep)->kref.refcount)) < 1); \
|
||||
ep, kref_read(&((ep)->kref))); \
|
||||
WARN_ON(kref_read(&((ep)->kref)) < 1); \
|
||||
kref_put(&((ep)->kref), __free_ep); \
|
||||
}
|
||||
|
||||
#define get_ep(ep) { \
|
||||
PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \
|
||||
ep, atomic_read(&((ep)->kref.refcount))); \
|
||||
ep, kref_read(&((ep)->kref))); \
|
||||
kref_get(&((ep)->kref)); \
|
||||
}
|
||||
|
||||
|
||||
@@ -961,7 +961,7 @@ int iwch_modify_qp(struct iwch_dev *rhp, struct iwch_qp *qhp,
|
||||
case IWCH_QP_STATE_RTS:
|
||||
switch (attrs->next_state) {
|
||||
case IWCH_QP_STATE_CLOSING:
|
||||
BUG_ON(atomic_read(&qhp->ep->com.kref.refcount) < 2);
|
||||
BUG_ON(kref_read(&qhp->ep->com.kref) < 2);
|
||||
qhp->attr.state = IWCH_QP_STATE_CLOSING;
|
||||
if (!internal) {
|
||||
abort=0;
|
||||
|
||||
@@ -654,14 +654,14 @@ enum c4iw_mmid_state {
|
||||
|
||||
#define c4iw_put_ep(ep) { \
|
||||
PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__, \
|
||||
ep, atomic_read(&((ep)->kref.refcount))); \
|
||||
WARN_ON(atomic_read(&((ep)->kref.refcount)) < 1); \
|
||||
ep, kref_read(&((ep)->kref))); \
|
||||
WARN_ON(kref_read(&((ep)->kref)) < 1); \
|
||||
kref_put(&((ep)->kref), _c4iw_free_ep); \
|
||||
}
|
||||
|
||||
#define c4iw_get_ep(ep) { \
|
||||
PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \
|
||||
ep, atomic_read(&((ep)->kref.refcount))); \
|
||||
ep, kref_read(&((ep)->kref))); \
|
||||
kref_get(&((ep)->kref)); \
|
||||
}
|
||||
void _c4iw_free_ep(struct kref *kref);
|
||||
|
||||
@@ -1503,7 +1503,7 @@ int c4iw_modify_qp(struct c4iw_dev *rhp, struct c4iw_qp *qhp,
|
||||
case C4IW_QP_STATE_RTS:
|
||||
switch (attrs->next_state) {
|
||||
case C4IW_QP_STATE_CLOSING:
|
||||
BUG_ON(atomic_read(&qhp->ep->com.kref.refcount) < 2);
|
||||
BUG_ON(kref_read(&qhp->ep->com.kref) < 2);
|
||||
t4_set_wq_in_error(&qhp->wq);
|
||||
set_state(qhp, C4IW_QP_STATE_CLOSING);
|
||||
ep = qhp->ep;
|
||||
|
||||
@@ -80,7 +80,7 @@ usnic_ib_show_config(struct device *device, struct device_attribute *attr,
|
||||
left = PAGE_SIZE;
|
||||
|
||||
mutex_lock(&us_ibdev->usdev_lock);
|
||||
if (atomic_read(&us_ibdev->vf_cnt.refcount) > 0) {
|
||||
if (kref_read(&us_ibdev->vf_cnt) > 0) {
|
||||
char *busname;
|
||||
|
||||
/*
|
||||
@@ -99,7 +99,7 @@ usnic_ib_show_config(struct device *device, struct device_attribute *attr,
|
||||
PCI_FUNC(us_ibdev->pdev->devfn),
|
||||
netdev_name(us_ibdev->netdev),
|
||||
us_ibdev->ufdev->mac,
|
||||
atomic_read(&us_ibdev->vf_cnt.refcount));
|
||||
kref_read(&us_ibdev->vf_cnt));
|
||||
UPDATE_PTR_LEFT(n, ptr, left);
|
||||
|
||||
for (res_type = USNIC_VNIC_RES_TYPE_EOL;
|
||||
@@ -147,7 +147,7 @@ usnic_ib_show_max_vf(struct device *device, struct device_attribute *attr,
|
||||
us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev);
|
||||
|
||||
return scnprintf(buf, PAGE_SIZE, "%u\n",
|
||||
atomic_read(&us_ibdev->vf_cnt.refcount));
|
||||
kref_read(&us_ibdev->vf_cnt));
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
|
||||
@@ -291,11 +291,11 @@ int usnic_ib_query_device(struct ib_device *ibdev,
|
||||
qp_per_vf = max(us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_WQ],
|
||||
us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_RQ]);
|
||||
props->max_qp = qp_per_vf *
|
||||
atomic_read(&us_ibdev->vf_cnt.refcount);
|
||||
kref_read(&us_ibdev->vf_cnt);
|
||||
props->device_cap_flags = IB_DEVICE_PORT_ACTIVE_EVENT |
|
||||
IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_BLOCK_MULTICAST_LOOPBACK;
|
||||
props->max_cq = us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_CQ] *
|
||||
atomic_read(&us_ibdev->vf_cnt.refcount);
|
||||
kref_read(&us_ibdev->vf_cnt);
|
||||
props->max_pd = USNIC_UIOM_MAX_PD_CNT;
|
||||
props->max_mr = USNIC_UIOM_MAX_MR_CNT;
|
||||
props->local_ca_ack_delay = 0;
|
||||
|
||||
@@ -1396,7 +1396,7 @@ int genwqe_device_remove(struct genwqe_dev *cd)
|
||||
* application which will decrease this reference from
|
||||
* 1/unused to 0/illegal and not from 2/used 1/empty.
|
||||
*/
|
||||
rc = atomic_read(&cd->cdev_genwqe.kobj.kref.refcount);
|
||||
rc = kref_read(&cd->cdev_genwqe.kobj.kref);
|
||||
if (rc != 1) {
|
||||
dev_err(&pci_dev->dev,
|
||||
"[%s] err: cdev_genwqe...refcount=%d\n", __func__, rc);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user