From: Christoph Hellwig <hch@lst.de>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>,
Gao Xiang <xiang@kernel.org>, Chao Yu <chao@kernel.org>,
Andreas Gruenbacher <agruenba@redhat.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-erofs@lists.ozlabs.org, gfs2@lists.linux.dev
Subject: [PATCH 3/8] lockref: use bool for false/true returns
Date: Wed, 15 Jan 2025 10:46:39 +0100 [thread overview]
Message-ID: <20250115094702.504610-4-hch@lst.de> (raw)
In-Reply-To: <20250115094702.504610-1-hch@lst.de>
Replace int used as bool with the actual bool type for return values that
can only be true or false.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/linux/lockref.h | 6 +++---
lib/lockref.c | 30 ++++++++++++++----------------
2 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/include/linux/lockref.h b/include/linux/lockref.h
index e5aa0347f274..3d770e1bdbad 100644
--- a/include/linux/lockref.h
+++ b/include/linux/lockref.h
@@ -36,11 +36,11 @@ struct lockref {
extern void lockref_get(struct lockref *);
extern int lockref_put_return(struct lockref *);
-extern int lockref_get_not_zero(struct lockref *);
-extern int lockref_put_or_lock(struct lockref *);
+bool lockref_get_not_zero(struct lockref *lockref);
+bool lockref_put_or_lock(struct lockref *lockref);
extern void lockref_mark_dead(struct lockref *);
-extern int lockref_get_not_dead(struct 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)
diff --git a/lib/lockref.c b/lib/lockref.c
index b1b042a9a6c8..5d8e3ef3860e 100644
--- a/lib/lockref.c
+++ b/lib/lockref.c
@@ -58,23 +58,22 @@ EXPORT_SYMBOL(lockref_get);
* @lockref: pointer to lockref structure
* Return: 1 if count updated successfully or 0 if count was zero
*/
-int lockref_get_not_zero(struct lockref *lockref)
+bool lockref_get_not_zero(struct lockref *lockref)
{
- int retval;
+ bool retval = false;
CMPXCHG_LOOP(
new.count++;
if (old.count <= 0)
- return 0;
+ return false;
,
- return 1;
+ return true;
);
spin_lock(&lockref->lock);
- retval = 0;
if (lockref->count > 0) {
lockref->count++;
- retval = 1;
+ retval = true;
}
spin_unlock(&lockref->lock);
return retval;
@@ -106,22 +105,22 @@ EXPORT_SYMBOL(lockref_put_return);
* @lockref: pointer to lockref structure
* Return: 1 if count updated successfully or 0 if count <= 1 and lock taken
*/
-int lockref_put_or_lock(struct lockref *lockref)
+bool lockref_put_or_lock(struct lockref *lockref)
{
CMPXCHG_LOOP(
new.count--;
if (old.count <= 1)
break;
,
- return 1;
+ return true;
);
spin_lock(&lockref->lock);
if (lockref->count <= 1)
- return 0;
+ return false;
lockref->count--;
spin_unlock(&lockref->lock);
- return 1;
+ return true;
}
EXPORT_SYMBOL(lockref_put_or_lock);
@@ -141,23 +140,22 @@ EXPORT_SYMBOL(lockref_mark_dead);
* @lockref: pointer to lockref structure
* Return: 1 if count updated successfully or 0 if lockref was dead
*/
-int lockref_get_not_dead(struct lockref *lockref)
+bool lockref_get_not_dead(struct lockref *lockref)
{
- int retval;
+ bool retval = false;
CMPXCHG_LOOP(
new.count++;
if (old.count < 0)
- return 0;
+ return false;
,
- return 1;
+ return true;
);
spin_lock(&lockref->lock);
- retval = 0;
if (lockref->count >= 0) {
lockref->count++;
- retval = 1;
+ retval = true;
}
spin_unlock(&lockref->lock);
return retval;
--
2.45.2
next prev parent reply other threads:[~2025-01-15 9:47 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-15 9:46 lockref cleanups Christoph Hellwig
2025-01-15 9:46 ` [PATCH 1/8] lockref: remove lockref_put_not_zero Christoph Hellwig
2025-01-15 9:46 ` [PATCH 2/8] lockref: improve the lockref_get_not_zero description Christoph Hellwig
2025-01-15 13:28 ` Andreas Gruenbacher
2025-01-15 9:46 ` Christoph Hellwig [this message]
2025-03-18 15:25 ` [PATCH 3/8] lockref: use bool for false/true returns Mateusz Guzik
2025-03-18 15:51 ` Mateusz Guzik
2025-03-19 6:29 ` Christoph Hellwig
2025-03-19 12:04 ` Mateusz Guzik
2025-03-20 5:34 ` Christoph Hellwig
2025-01-15 9:46 ` [PATCH 4/8] lockref: drop superfluous externs Christoph Hellwig
2025-01-15 9:46 ` [PATCH 5/8] lockref: add a lockref_init helper Christoph Hellwig
2025-01-15 9:46 ` [PATCH 6/8] dcache: use lockref_init for d_lockref Christoph Hellwig
2025-01-15 20:13 ` Dave Chinner
2025-01-15 20:30 ` Al Viro
2025-01-16 5:03 ` Dave Chinner
2025-01-15 9:46 ` [PATCH 7/8] erofs: use lockref_init for pcl->lockref Christoph Hellwig
2025-01-15 9:49 ` Gao Xiang
2025-01-15 9:46 ` [PATCH 8/8] gfs2: use lockref_init for qd_lockref Christoph Hellwig
2025-01-15 13:35 ` Andreas Gruenbacher
2025-01-16 4:32 ` Christoph Hellwig
2025-01-17 16:03 ` Andreas Gruenbacher
2025-01-20 15:25 ` Christian Brauner
2025-01-20 15:44 ` Andreas Gruenbacher
2025-01-22 12:59 ` Christian Brauner
2025-01-15 10:50 ` lockref cleanups Christian Brauner
2025-01-22 20:40 ` Jeff Layton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250115094702.504610-4-hch@lst.de \
--to=hch@lst.de \
--cc=agruenba@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=chao@kernel.org \
--cc=gfs2@lists.linux.dev \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=xiang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox