]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lockref: add a lockref_init helper
authorChristoph Hellwig <hch@lst.de>
Wed, 15 Jan 2025 09:46:41 +0000 (10:46 +0100)
committerChristian Brauner <brauner@kernel.org>
Thu, 16 Jan 2025 10:48:11 +0000 (11:48 +0100)
Add a helper to initialize the lockdep, that is initialize the spinlock
and set a value.  Having to open code them isn't a big deal, but having
an initializer feels right for a proper primitive.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20250115094702.504610-6-hch@lst.de
Signed-off-by: Christian Brauner <brauner@kernel.org>
include/linux/lockref.h

index f821f46e9fb40eb1ca0d1399d105c8a9b7643d51..c39f119659ba4684906fea9adb4a6ec89ca537e3 100644 (file)
@@ -34,6 +34,17 @@ struct lockref {
        };
 };
 
+/**
+ * lockref_init - Initialize a lockref
+ * @lockref: pointer to lockref structure
+ * @count: initial count
+ */
+static inline void lockref_init(struct lockref *lockref, unsigned int count)
+{
+       spin_lock_init(&lockref->lock);
+       lockref->count = count;
+}
+
 void lockref_get(struct lockref *lockref);
 int lockref_put_return(struct lockref *lockref);
 bool lockref_get_not_zero(struct lockref *lockref);