public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] static-keys: Better error checking for static_key_enable/disable
@ 2015-08-27 20:57 Chuck Ebbert
  2015-08-27 22:23 ` Peter Zijlstra
  0 siblings, 1 reply; 2+ messages in thread
From: Chuck Ebbert @ 2015-08-27 20:57 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: linux-kernel

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 <cebbert.lkml@gmail.com>

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);

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH -next] static-keys: Better error checking for static_key_enable/disable
  2015-08-27 20:57 [PATCH -next] static-keys: Better error checking for static_key_enable/disable Chuck Ebbert
@ 2015-08-27 22:23 ` Peter Zijlstra
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2015-08-27 22:23 UTC (permalink / raw)
  To: Chuck Ebbert; +Cc: linux-kernel

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-08-27 22:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-27 20:57 [PATCH -next] static-keys: Better error checking for static_key_enable/disable Chuck Ebbert
2015-08-27 22:23 ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox