Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932518AbdCFTKX (ORCPT ); Mon, 6 Mar 2017 14:10:23 -0500 Received: from mail-pf0-f174.google.com ([209.85.192.174]:34227 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932477AbdCFTKC (ORCPT ); Mon, 6 Mar 2017 14:10:02 -0500 From: Kees Cook To: kernel-hardening@lists.openwall.com Cc: Kees Cook , Andrew Morton , Rik van Riel , "Paul E. McKenney" , Jakub Kicinski , Viresh Kumar , Ingo Molnar , Thomas Gleixner , Dmitry Vyukov , Olof Johansson , Peter Zijlstra , Josh Poimboeuf , linux-kernel@vger.kernel.org Subject: [PATCH 2/6] bug: Improve unlikely() in data corruption check Date: Mon, 6 Mar 2017 11:09:42 -0800 Message-Id: <1488827386-87193-3-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488827386-87193-1-git-send-email-keescook@chromium.org> References: <1488827386-87193-1-git-send-email-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1103 Lines: 33 This improves the compiler branch-hinting used in CHECK_DATA_CORRUPTION(), similar to how it is done in WARN_ON() and friends. Signed-off-by: Kees Cook --- include/linux/bug.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/bug.h b/include/linux/bug.h index 5828489309bb..5ef65dc2ed8b 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -129,15 +129,15 @@ static inline enum bug_trap_type report_bug(unsigned long bug_addr, static inline __must_check bool check_data_corruption(bool v) { return v; } #define CHECK_DATA_CORRUPTION(condition, fmt, ...) \ check_data_corruption(({ \ - bool corruption = unlikely(condition); \ - if (corruption) { \ + bool corruption = !!(condition); \ + if (unlikely(corruption)) { \ if (IS_ENABLED(CONFIG_BUG_ON_DATA_CORRUPTION)) { \ pr_err(fmt, ##__VA_ARGS__); \ BUG(); \ } else \ WARN(1, fmt, ##__VA_ARGS__); \ } \ - corruption; \ + unlikely(corruption); \ })) #endif /* _LINUX_BUG_H */ -- 2.7.4