Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752567AbbH0U5U (ORCPT ); Thu, 27 Aug 2015 16:57:20 -0400 Received: from mail-io0-f180.google.com ([209.85.223.180]:36327 "EHLO mail-io0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752456AbbH0U5R (ORCPT ); Thu, 27 Aug 2015 16:57:17 -0400 Date: Thu, 27 Aug 2015 16:57:13 -0400 From: Chuck Ebbert To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org Subject: [PATCH -next] static-keys: Better error checking for static_key_enable/disable Message-ID: <20150827165713.7fc9ff4c@as> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1247 Lines: 35 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 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); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/