Skip to content

Commit

Permalink
fs: dlm: move kref_put assert for lkb structs
Browse files Browse the repository at this point in the history
The unhold_lkb() function decrements the lock's kref, and
asserts that the ref count was not the final one.  Use the
kref_put release function (which should not be called) to
call the assert, rather than doing the assert based on the
kref_put return value.  Using kill_lkb() as the release
function doesn't make sense if we only want to assert.

Signed-off-by: Alexander Aring <[email protected]>
Signed-off-by: David Teigland <[email protected]>
  • Loading branch information
Alexander Aring authored and teigland committed Aug 1, 2022
1 parent 6b0afc0 commit 9585898
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions fs/dlm/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1310,16 +1310,21 @@ static inline void hold_lkb(struct dlm_lkb *lkb)
kref_get(&lkb->lkb_ref);
}

static void unhold_lkb_assert(struct kref *kref)
{
struct dlm_lkb *lkb = container_of(kref, struct dlm_lkb, lkb_ref);

DLM_ASSERT(false, dlm_print_lkb(lkb););
}

/* This is called when we need to remove a reference and are certain
it's not the last ref. e.g. del_lkb is always called between a
find_lkb/put_lkb and is always the inverse of a previous add_lkb.
put_lkb would work fine, but would involve unnecessary locking */

static inline void unhold_lkb(struct dlm_lkb *lkb)
{
int rv;
rv = kref_put(&lkb->lkb_ref, kill_lkb);
DLM_ASSERT(!rv, dlm_print_lkb(lkb););
kref_put(&lkb->lkb_ref, unhold_lkb_assert);
}

static void lkb_add_ordered(struct list_head *new, struct list_head *head,
Expand Down

0 comments on commit 9585898

Please sign in to comment.