2015-08-27 20:57:20

by Chuck Ebbert

[permalink] [raw]
Subject: [PATCH -next] static-keys: Better error checking for static_key_enable/disable

The warnings for static_key_enable/disable don't catch common
errors. For example, starting with a default enabled key and
calling enable doesn't cause a warning until the next enable
or disable. Check explicitly for zero or one instead of allowing
both values in every case. Generated code should be smaller too.

Signed-off-by: Chuck Ebbert <[email protected]>

diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index 7f653e8..ba9ca0c 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -225,7 +225,7 @@ static inline void static_key_enable(struct static_key *key)
{
int count = static_key_count(key);

- WARN_ON_ONCE(count < 0 || count > 1);
+ WARN_ON_ONCE(count);

if (!count)
static_key_slow_inc(key);
@@ -235,7 +235,7 @@ static inline void static_key_disable(struct static_key *key)
{
int count = static_key_count(key);

- WARN_ON_ONCE(count < 0 || count > 1);
+ WARN_ON_ONCE(count != 1);

if (count)
static_key_slow_dec(key);


2015-08-27 22:23:28

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH -next] static-keys: Better error checking for static_key_enable/disable

On Thu, Aug 27, 2015 at 04:57:13PM -0400, Chuck Ebbert wrote:
> The warnings for static_key_enable/disable don't catch common
> errors. For example, starting with a default enabled key and
> calling enable doesn't cause a warning until the next enable
> or disable. Check explicitly for zero or one instead of allowing
> both values in every case. Generated code should be smaller too.

I explicitly intended to allow multiple consecutive static_key_enable()
calls (same for disable).

If its already enabled, calling enable should be a no-op.