mirror of https://github.com/torvalds/linux.git
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 <hch@lst.de> Link: https://lore.kernel.org/r/20250115094702.504610-4-hch@lst.de Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
d60f2280a1
commit
6d2868d5b6
|
|
@ -36,11 +36,11 @@ struct lockref {
|
||||||
|
|
||||||
extern void lockref_get(struct lockref *);
|
extern void lockref_get(struct lockref *);
|
||||||
extern int lockref_put_return(struct lockref *);
|
extern int lockref_put_return(struct lockref *);
|
||||||
extern int lockref_get_not_zero(struct lockref *);
|
bool lockref_get_not_zero(struct lockref *lockref);
|
||||||
extern int lockref_put_or_lock(struct lockref *);
|
bool lockref_put_or_lock(struct lockref *lockref);
|
||||||
|
|
||||||
extern void lockref_mark_dead(struct 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 */
|
/* 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)
|
||||||
|
|
|
||||||
|
|
@ -58,23 +58,22 @@ EXPORT_SYMBOL(lockref_get);
|
||||||
* @lockref: pointer to lockref structure
|
* @lockref: pointer to lockref structure
|
||||||
* Return: 1 if count updated successfully or 0 if count was zero
|
* 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(
|
CMPXCHG_LOOP(
|
||||||
new.count++;
|
new.count++;
|
||||||
if (old.count <= 0)
|
if (old.count <= 0)
|
||||||
return 0;
|
return false;
|
||||||
,
|
,
|
||||||
return 1;
|
return true;
|
||||||
);
|
);
|
||||||
|
|
||||||
spin_lock(&lockref->lock);
|
spin_lock(&lockref->lock);
|
||||||
retval = 0;
|
|
||||||
if (lockref->count > 0) {
|
if (lockref->count > 0) {
|
||||||
lockref->count++;
|
lockref->count++;
|
||||||
retval = 1;
|
retval = true;
|
||||||
}
|
}
|
||||||
spin_unlock(&lockref->lock);
|
spin_unlock(&lockref->lock);
|
||||||
return retval;
|
return retval;
|
||||||
|
|
@ -106,22 +105,22 @@ EXPORT_SYMBOL(lockref_put_return);
|
||||||
* @lockref: pointer to lockref structure
|
* @lockref: pointer to lockref structure
|
||||||
* Return: 1 if count updated successfully or 0 if count <= 1 and lock taken
|
* 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(
|
CMPXCHG_LOOP(
|
||||||
new.count--;
|
new.count--;
|
||||||
if (old.count <= 1)
|
if (old.count <= 1)
|
||||||
break;
|
break;
|
||||||
,
|
,
|
||||||
return 1;
|
return true;
|
||||||
);
|
);
|
||||||
|
|
||||||
spin_lock(&lockref->lock);
|
spin_lock(&lockref->lock);
|
||||||
if (lockref->count <= 1)
|
if (lockref->count <= 1)
|
||||||
return 0;
|
return false;
|
||||||
lockref->count--;
|
lockref->count--;
|
||||||
spin_unlock(&lockref->lock);
|
spin_unlock(&lockref->lock);
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(lockref_put_or_lock);
|
EXPORT_SYMBOL(lockref_put_or_lock);
|
||||||
|
|
||||||
|
|
@ -141,23 +140,22 @@ EXPORT_SYMBOL(lockref_mark_dead);
|
||||||
* @lockref: pointer to lockref structure
|
* @lockref: pointer to lockref structure
|
||||||
* Return: 1 if count updated successfully or 0 if lockref was dead
|
* 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(
|
CMPXCHG_LOOP(
|
||||||
new.count++;
|
new.count++;
|
||||||
if (old.count < 0)
|
if (old.count < 0)
|
||||||
return 0;
|
return false;
|
||||||
,
|
,
|
||||||
return 1;
|
return true;
|
||||||
);
|
);
|
||||||
|
|
||||||
spin_lock(&lockref->lock);
|
spin_lock(&lockref->lock);
|
||||||
retval = 0;
|
|
||||||
if (lockref->count >= 0) {
|
if (lockref->count >= 0) {
|
||||||
lockref->count++;
|
lockref->count++;
|
||||||
retval = 1;
|
retval = true;
|
||||||
}
|
}
|
||||||
spin_unlock(&lockref->lock);
|
spin_unlock(&lockref->lock);
|
||||||
return retval;
|
return retval;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue