Skip to content

Commit 2c935bc

Browse files
Peter Zijlstraingomolnar
authored andcommitted
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>
1 parent 1e24edc commit 2c935bc

56 files changed

Lines changed: 121 additions & 117 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎drivers/block/drbd/drbd_req.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m,
520520
/* Completion does it's own kref_put. If we are going to
521521
* kref_sub below, we need req to be still around then. */
522522
int at_least = k_put + !!c_put;
523-
int refcount = atomic_read(&req->kref.refcount);
523+
int refcount = kref_read(&req->kref);
524524
if (refcount < at_least)
525525
drbd_err(device,
526526
"mod_rq_state: Logic BUG: %x -> %x: refcount = %d, should be >= %d\n",

‎drivers/block/rbd.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ static bool obj_request_overlaps_parent(struct rbd_obj_request *obj_request)
15351535
static void rbd_obj_request_get(struct rbd_obj_request *obj_request)
15361536
{
15371537
dout("%s: obj %p (was %d)\n", __func__, obj_request,
1538-
atomic_read(&obj_request->kref.refcount));
1538+
kref_read(&obj_request->kref));
15391539
kref_get(&obj_request->kref);
15401540
}
15411541

@@ -1544,14 +1544,14 @@ static void rbd_obj_request_put(struct rbd_obj_request *obj_request)
15441544
{
15451545
rbd_assert(obj_request != NULL);
15461546
dout("%s: obj %p (was %d)\n", __func__, obj_request,
1547-
atomic_read(&obj_request->kref.refcount));
1547+
kref_read(&obj_request->kref));
15481548
kref_put(&obj_request->kref, rbd_obj_request_destroy);
15491549
}
15501550

15511551
static void rbd_img_request_get(struct rbd_img_request *img_request)
15521552
{
15531553
dout("%s: img %p (was %d)\n", __func__, img_request,
1554-
atomic_read(&img_request->kref.refcount));
1554+
kref_read(&img_request->kref));
15551555
kref_get(&img_request->kref);
15561556
}
15571557

@@ -1562,7 +1562,7 @@ static void rbd_img_request_put(struct rbd_img_request *img_request)
15621562
{
15631563
rbd_assert(img_request != NULL);
15641564
dout("%s: img %p (was %d)\n", __func__, img_request,
1565-
atomic_read(&img_request->kref.refcount));
1565+
kref_read(&img_request->kref));
15661566
if (img_request_child_test(img_request))
15671567
kref_put(&img_request->kref, rbd_parent_request_destroy);
15681568
else

‎drivers/block/virtio_blk.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ static void virtblk_remove(struct virtio_device *vdev)
767767
/* Stop all the virtqueues. */
768768
vdev->config->reset(vdev);
769769

770-
refc = atomic_read(&disk_to_dev(vblk->disk)->kobj.kref.refcount);
770+
refc = kref_read(&disk_to_dev(vblk->disk)->kobj.kref);
771771
put_disk(vblk->disk);
772772
vdev->config->del_vqs(vdev);
773773
kfree(vblk->vqs);

‎drivers/gpu/drm/drm_gem_cma_helper.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void drm_gem_cma_describe(struct drm_gem_cma_object *cma_obj,
376376
off = drm_vma_node_start(&obj->vma_node);
377377

378378
seq_printf(m, "%2d (%2d) %08llx %pad %p %zu",
379-
obj->name, obj->refcount.refcount.counter,
379+
obj->name, kref_read(&obj->refcount),
380380
off, &cma_obj->paddr, cma_obj->vaddr, obj->size);
381381

382382
seq_printf(m, "\n");

‎drivers/gpu/drm/drm_info.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static int drm_gem_one_name_info(int id, void *ptr, void *data)
118118
seq_printf(m, "%6d %8zd %7d %8d\n",
119119
obj->name, obj->size,
120120
obj->handle_count,
121-
atomic_read(&obj->refcount.refcount));
121+
kref_read(&obj->refcount));
122122
return 0;
123123
}
124124

‎drivers/gpu/drm/drm_mode_object.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ EXPORT_SYMBOL(drm_mode_object_find);
159159
void drm_mode_object_unreference(struct drm_mode_object *obj)
160160
{
161161
if (obj->free_cb) {
162-
DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount));
162+
DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, kref_read(&obj->refcount));
163163
kref_put(&obj->refcount, obj->free_cb);
164164
}
165165
}
@@ -176,7 +176,7 @@ EXPORT_SYMBOL(drm_mode_object_unreference);
176176
void drm_mode_object_reference(struct drm_mode_object *obj)
177177
{
178178
if (obj->free_cb) {
179-
DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount));
179+
DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, kref_read(&obj->refcount));
180180
kref_get(&obj->refcount);
181181
}
182182
}

‎drivers/gpu/drm/etnaviv/etnaviv_gem.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m)
486486

487487
seq_printf(m, "%08x: %c %2d (%2d) %08lx %p %zd\n",
488488
etnaviv_obj->flags, is_active(etnaviv_obj) ? 'A' : 'I',
489-
obj->name, obj->refcount.refcount.counter,
489+
obj->name, kref_read(&obj->refcount),
490490
off, etnaviv_obj->vaddr, obj->size);
491491

492492
rcu_read_lock();

‎drivers/gpu/drm/i915/i915_gem_object.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ extern void drm_gem_object_unreference_unlocked(struct drm_gem_object *);
256256
static inline bool
257257
i915_gem_object_is_dead(const struct drm_i915_gem_object *obj)
258258
{
259-
return atomic_read(&obj->base.refcount.refcount) == 0;
259+
return kref_read(&obj->base.refcount) == 0;
260260
}
261261

262262
static inline bool

‎drivers/gpu/drm/msm/msm_gem.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m)
640640

641641
seq_printf(m, "%08x: %c %2d (%2d) %08llx %p\t",
642642
msm_obj->flags, is_active(msm_obj) ? 'A' : 'I',
643-
obj->name, obj->refcount.refcount.counter,
643+
obj->name, kref_read(&obj->refcount),
644644
off, msm_obj->vaddr);
645645

646646
for (id = 0; id < priv->num_aspaces; id++)

‎drivers/gpu/drm/nouveau/nouveau_fence.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static bool nouveau_fence_no_signaling(struct dma_fence *f)
527527
* caller should have a reference on the fence,
528528
* else fence could get freed here
529529
*/
530-
WARN_ON(atomic_read(&fence->base.refcount.refcount) <= 1);
530+
WARN_ON(kref_read(&fence->base.refcount) <= 1);
531531

532532
/*
533533
* This needs uevents to work correctly, but dma_fence_add_callback relies on

0 commit comments

Comments
 (0)