locking/refcounts: Change WARN() to WARN_ONCE()

Linus noticed that the new refcount.h APIs used WARN(), which would turn
into a dmesg DoS if it triggers frequently on some buggy driver.

So make sure we only warn once. These warnings are never supposed to happen,
so it's typically not a problem to lose subsequent warnings.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Elena Reshetova <elena.reshetova@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/CA+55aFzbYUTZ=oqZ2YgDjY0C2_n6ODhTfqj6V+m5xWmDxsuB0w@mail.gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
Ingo Molnar 2017-03-01 09:25:55 +01:00 committed by xxmustafacooTR
parent aadf156747
commit 51e86ead56
No known key found for this signature in database
GPG key ID: 520B6FE385CBF5C9

View file

@ -78,7 +78,7 @@ bool refcount_add_not_zero(unsigned int i, refcount_t *r)
val = old; val = old;
} }
WARN(new == UINT_MAX, "refcount_t: saturated; leaking memory.\n"); WARN_ONCE(new == UINT_MAX, "refcount_t: saturated; leaking memory.\n");
return true; return true;
} }
@ -102,7 +102,7 @@ EXPORT_SYMBOL_GPL(refcount_add_not_zero);
*/ */
void refcount_add(unsigned int i, refcount_t *r) void refcount_add(unsigned int i, refcount_t *r)
{ {
WARN(!refcount_add_not_zero(i, r), "refcount_t: addition on 0; use-after-free.\n"); WARN_ONCE(!refcount_add_not_zero(i, r), "refcount_t: addition on 0; use-after-free.\n");
} }
EXPORT_SYMBOL_GPL(refcount_add); EXPORT_SYMBOL_GPL(refcount_add);
@ -138,7 +138,7 @@ bool refcount_inc_not_zero(refcount_t *r)
val = old; val = old;
} }
WARN(new == UINT_MAX, "refcount_t: saturated; leaking memory.\n"); WARN_ONCE(new == UINT_MAX, "refcount_t: saturated; leaking memory.\n");
return true; return true;
} }
@ -158,7 +158,7 @@ EXPORT_SYMBOL_GPL(refcount_inc_not_zero);
*/ */
void refcount_inc(refcount_t *r) void refcount_inc(refcount_t *r)
{ {
WARN(!refcount_inc_not_zero(r), "refcount_t: increment on 0; use-after-free.\n"); WARN_ONCE(!refcount_inc_not_zero(r), "refcount_t: increment on 0; use-after-free.\n");
} }
EXPORT_SYMBOL_GPL(refcount_inc); EXPORT_SYMBOL_GPL(refcount_inc);
@ -192,7 +192,7 @@ bool refcount_sub_and_test(unsigned int i, refcount_t *r)
new = val - i; new = val - i;
if (new > val) { if (new > val) {
WARN(new > val, "refcount_t: underflow; use-after-free.\n"); WARN_ONCE(new > val, "refcount_t: underflow; use-after-free.\n");
return false; return false;
} }
@ -238,7 +238,7 @@ EXPORT_SYMBOL_GPL(refcount_dec_and_test);
*/ */
void refcount_dec(refcount_t *r) void refcount_dec(refcount_t *r)
{ {
WARN(refcount_dec_and_test(r), "refcount_t: decrement hit 0; leaking memory.\n"); WARN_ONCE(refcount_dec_and_test(r), "refcount_t: decrement hit 0; leaking memory.\n");
} }
EXPORT_SYMBOL(refcount_dec); EXPORT_SYMBOL(refcount_dec);
#endif /* CONFIG_REFCOUNT_FULL */ #endif /* CONFIG_REFCOUNT_FULL */
@ -289,7 +289,7 @@ bool refcount_dec_not_one(refcount_t *r)
new = val - 1; new = val - 1;
if (new > val) { if (new > val) {
WARN(new > val, "refcount_t: underflow; use-after-free.\n"); WARN_ONCE(new > val, "refcount_t: underflow; use-after-free.\n");
return true; return true;
} }