summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2026-07-27 16:20:29 +0200
committerChristian Brauner <brauner@kernel.org>2026-07-31 10:09:12 +0200
commiteace17e646b31f3e38ead8e645240f726e871baf (patch)
tree3ffc0323eaa424e49fa31e51160ecbba4048521d /include/linux
parent42c8ed5835921a7b2523517fd6caad1d79b69146 (diff)
parentb6f946cc42f62b82f014d67bc5eea0662d4f5584 (diff)
Merge patch series "lockref tidy ups + touch ups to it's usage by dcache"
Mateusz Guzik <mjguzik@gmail.com> says: The open-coded check for < 0 indicating a dead object uses information it should not know, so to speak. This is a preliminary clean up for a longer term goal of moving dcache away from lockref into an approach which can atomic_add both ways instead of suffering the cmpxchg loop. * patches from https://patch.msgid.link/20260724171422.429284-1-mjguzik@gmail.com: dcache: use lockref routines for dead count checks lockref: tidy up dead count handling Link: https://patch.msgid.link/20260724171422.429284-1-mjguzik@gmail.com Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/lockref.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/include/linux/lockref.h b/include/linux/lockref.h
index 6ded24cdb4a8..ddfb7d3b8cec 100644
--- a/include/linux/lockref.h
+++ b/include/linux/lockref.h
@@ -34,6 +34,8 @@ struct lockref {
};
};
+#define __LOCKREF_DEAD_VAL -128
+
/**
* lockref_init - Initialize a lockref
* @lockref: pointer to lockref structure
@@ -55,9 +57,15 @@ void lockref_mark_dead(struct lockref *lockref);
bool lockref_get_not_dead(struct lockref *lockref);
/* Must be called under spinlock for reliable results */
-static inline bool __lockref_is_dead(const struct lockref *l)
+static inline bool lockref_is_dead(const struct lockref *l)
+{
+ return (READ_ONCE(l->count) == __LOCKREF_DEAD_VAL);
+}
+
+static inline bool lockref_is_dead_or_zero(const struct lockref *l)
{
- return ((int)l->count < 0);
+ int count = READ_ONCE(l->count);
+ return (count == __LOCKREF_DEAD_VAL || count == 0);
}
#endif /* __LINUX_LOCKREF_H */