Skip to content

Commit 6d2868d

Browse files
Christoph Hellwigbrauner
authored andcommitted
lockref: use bool for false/true returns
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent d60f228 commit 6d2868d

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

include/linux/lockref.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ struct lockref {
3636

3737
extern void lockref_get(struct lockref *);
3838
extern int lockref_put_return(struct lockref *);
39-
extern int lockref_get_not_zero(struct lockref *);
40-
extern int lockref_put_or_lock(struct lockref *);
39+
bool lockref_get_not_zero(struct lockref *lockref);
40+
bool lockref_put_or_lock(struct lockref *lockref);
4141

4242
extern void lockref_mark_dead(struct lockref *);
43-
extern int lockref_get_not_dead(struct lockref *);
43+
bool lockref_get_not_dead(struct lockref *lockref);
4444

4545
/* Must be called under spinlock for reliable results */
4646
static inline bool __lockref_is_dead(const struct lockref *l)

lib/lockref.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,22 @@ EXPORT_SYMBOL(lockref_get);
5858
* @lockref: pointer to lockref structure
5959
* Return: 1 if count updated successfully or 0 if count was zero
6060
*/
61-
int lockref_get_not_zero(struct lockref *lockref)
61+
bool lockref_get_not_zero(struct lockref *lockref)
6262
{
63-
int retval;
63+
bool retval = false;
6464

6565
CMPXCHG_LOOP(
6666
new.count++;
6767
if (old.count <= 0)
68-
return 0;
68+
return false;
6969
,
70-
return 1;
70+
return true;
7171
);
7272

7373
spin_lock(&lockref->lock);
74-
retval = 0;
7574
if (lockref->count > 0) {
7675
lockref->count++;
77-
retval = 1;
76+
retval = true;
7877
}
7978
spin_unlock(&lockref->lock);
8079
return retval;
@@ -106,22 +105,22 @@ EXPORT_SYMBOL(lockref_put_return);
106105
* @lockref: pointer to lockref structure
107106
* Return: 1 if count updated successfully or 0 if count <= 1 and lock taken
108107
*/
109-
int lockref_put_or_lock(struct lockref *lockref)
108+
bool lockref_put_or_lock(struct lockref *lockref)
110109
{
111110
CMPXCHG_LOOP(
112111
new.count--;
113112
if (old.count <= 1)
114113
break;
115114
,
116-
return 1;
115+
return true;
117116
);
118117

119118
spin_lock(&lockref->lock);
120119
if (lockref->count <= 1)
121-
return 0;
120+
return false;
122121
lockref->count--;
123122
spin_unlock(&lockref->lock);
124-
return 1;
123+
return true;
125124
}
126125
EXPORT_SYMBOL(lockref_put_or_lock);
127126

@@ -141,23 +140,22 @@ EXPORT_SYMBOL(lockref_mark_dead);
141140
* @lockref: pointer to lockref structure
142141
* Return: 1 if count updated successfully or 0 if lockref was dead
143142
*/
144-
int lockref_get_not_dead(struct lockref *lockref)
143+
bool lockref_get_not_dead(struct lockref *lockref)
145144
{
146-
int retval;
145+
bool retval = false;
147146

148147
CMPXCHG_LOOP(
149148
new.count++;
150149
if (old.count < 0)
151-
return 0;
150+
return false;
152151
,
153-
return 1;
152+
return true;
154153
);
155154

156155
spin_lock(&lockref->lock);
157-
retval = 0;
158156
if (lockref->count >= 0) {
159157
lockref->count++;
160-
retval = 1;
158+
retval = true;
161159
}
162160
spin_unlock(&lockref->lock);
163161
return retval;

0 commit comments

Comments
 (0)