From patchwork Mon Jul 9 16:25:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10515201 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3E8426032C for ; Mon, 9 Jul 2018 16:25:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CEC528BD7 for ; Mon, 9 Jul 2018 16:25:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20E3328CA4; Mon, 9 Jul 2018 16:25:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B9E7728BD7 for ; Mon, 9 Jul 2018 16:25:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C68146E53C; Mon, 9 Jul 2018 16:25:18 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by gabe.freedesktop.org (Postfix) with ESMTPS id 205E96E534 for ; Mon, 9 Jul 2018 16:25:17 +0000 (UTC) Received: by mail-ed1-x544.google.com with SMTP id g12-v6so14379789edi.9 for ; Mon, 09 Jul 2018 09:25:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+fbqYqPvkeNQn/GeP/TLNQC6r5DJ3br/mflYTWDsAbw=; b=ZTSmbxuhEKydj//q2oDf9N9Lz3hWTuRBTnZDJX3PKy/uRaUETwf8j8ZqbvixbBgYeH KSgmKRo/q3N3EnIzbO0WxSYdgRXxyZZp1OAGhQ9F3lbk810cXQ0gKu1tjh47ycA9p3vl j90dtfqwEakjvjDA4UhbUa8DBn2b1fIOAfRxLE7h6UXmWKkoykR0J1P94jfuzoMbnzz0 jrqCHnvQMUGdrLTcbgjTxQKUsxzsmK/ZxAVnOOvq2CgbRud9uGavyZt0k27Offlfo7Pl xrU3GVkAzzROq1vYNAVRbDxHh+IEJUmuSnR/SW0g0SBpNsmimvA4xfe8zOjpONtu9FPR 1xSQ== X-Gm-Message-State: APt69E04itXuKrxWiC0RKss6xYzeYdQDBMAdwFLET7N7ew1xUQNHo+/I qpnMznaFzEaLjPC9u6XA/f0ZKg== X-Google-Smtp-Source: AAOMgpdu3uIJO5A3ZMH//9TI76An6wwZXlcam+EGPtvg8eA+oLA3POOMoOCgKYoK9Rq9uixHrxOFTw== X-Received: by 2002:a50:a4f1:: with SMTP id x46-v6mr22349768edb.247.1531153515752; Mon, 09 Jul 2018 09:25:15 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:5628:0:496f:7dc5:66d7:a057]) by smtp.gmail.com with ESMTPSA id z3-v6sm7578905edh.56.2018.07.09.09.25.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jul 2018 09:25:14 -0700 (PDT) From: Daniel Vetter To: LKML Date: Mon, 9 Jul 2018 18:25:09 +0200 Message-Id: <20180709162509.29343-1-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180709083650.23549-1-daniel.vetter@ffwll.ch> References: <20180709083650.23549-1-daniel.vetter@ffwll.ch> Subject: [Intel-gfx] [PATCH] kernel.h: Add for_each_if() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kees Cook , Greg Kroah-Hartman , David Airlie , Daniel Vetter , Intel Graphics Development , Randy Dunlap , NeilBrown , DRI Development , Yisheng Xie , Peter Zijlstra , Stefan Agner , Wei Wang , Daniel Vetter , Andrew Morton , Andy Shevchenko , Ingo Molnar , Andrei Vagin MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP To avoid compilers complainig about ambigious else blocks when putting an if condition into a for_each macro one needs to invert the condition and add a dummy else. We have a nice little convenience macro for that in drm headers, let's move it out. Subsequent patches will roll it out to other places. The issue the compilers complain about are nested if with an else block and no {} to disambiguate which if the else belongs to. The C standard is clear, but in practice people forget: if (foo) if (bar) /* something */ else /* something else The same can happen in a for_each macro when it also contains an if condition at the end, except the compiler message is now really confusing since there's only 1 if: for_each_something() if (bar) /* something */ else /* something else The for_each_if() macro, by inverting the condition and adding an else, avoids the compiler warning. Motivated by a discussion with Andy and Yisheng, who want to add another for_each_macro which would benefit from for_each_if() instead of hand-rolling it. Cc: Gustavo Padovan Cc: Maarten Lankhorst Cc: Sean Paul Cc: David Airlie Cc: Andrew Morton Cc: Kees Cook Cc: Ingo Molnar Cc: Greg Kroah-Hartman Cc: NeilBrown Cc: Wei Wang Cc: Stefan Agner Cc: Andrei Vagin Cc: Randy Dunlap Cc: Andy Shevchenko Cc: Yisheng Xie Cc: Peter Zijlstra Reviewed-by: Andy Shevchenko Signed-off-by: Daniel Vetter --- v2: Explain a bit better what this is good for, after the discussion with Peter Z. --- include/drm/drmP.h | 3 --- include/linux/kernel.h | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/drm/drmP.h b/include/drm/drmP.h index f7a19c2a7a80..05350424a4d3 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -110,7 +110,4 @@ static inline bool drm_can_sleep(void) return true; } -/* helper for handling conditionals in various for_each macros */ -#define for_each_if(condition) if (!(condition)) {} else - #endif diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 941dc0a5a877..4cb95ab9a5bc 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -71,6 +71,9 @@ */ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) +/* helper for handling conditionals in various for_each macros */ +#define for_each_if(condition) if (!(condition)) {} else + #define u64_to_user_ptr(x) ( \ { \ typecheck(u64, x); \