Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp722562imm; Mon, 9 Jul 2018 09:26:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfAhHnsjgjxtwzagvLqxqlwuNjgLmKATkoT8Pk3Hy80rmW90g+7228AWkQvp/2dA3VifjOo X-Received: by 2002:a62:3687:: with SMTP id d129-v6mr21926239pfa.137.1531153602603; Mon, 09 Jul 2018 09:26:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531153602; cv=none; d=google.com; s=arc-20160816; b=mjkIo0xdJnv38IPg2CS6MZebB6OIPJEi4cNctlbC6Ip89hy/HkQYvOAzzq42L3/4TN S76NE2OJvxTz2kDLqf4MxlIVqPDaqhfJIkLImkaJTxHBZQAl4foJbkpf2v5ls2MOa3tc pwsnWQooYF+e2xzW18nn96BFVm+IVKkeaI350TqNKClI9ahVLssDcfijlb5S6TMXHhLN Afp5zwnidauKzVyjJ9zqraVZuxfmhI8xufwy2D+7pYiViEfoLW1ItmltE7jmz6arMHEQ 3IMsO3GVS7cjcLuCK5ZFc0u9psojPBa3zN4+/MOVo3gtVHnFr5l7VyyQHaphijryKVE6 0gtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=+fbqYqPvkeNQn/GeP/TLNQC6r5DJ3br/mflYTWDsAbw=; b=0/me7jl/fl4V052DAWBcJ/II6B4UKsPLppSCtI2uUrYgz9VhZz/KAq+XznHfQMF7qJ b9TXJrqiI+t659Z0VdSQJ3AZGqPqZgBcwS45u/F/FnPH1xpub3KcVQjZ80h49rFucU1V U9DUNUIW3uMFv06XVC2b3DHcsa4ETjA/w+vdD7s8E9qoW1PQq0cIoM7UXG52rZDfFkpS z1sjIYTFCLG+hgGnjCFeATzjeoeWzv31+NeNG5nhh1ECK0yOFLsI8kCIJwBGynmoc+BI 53K1Zmq8W11hmu8fJ+fegp7/C2De+glIFyBkoy2Hmqhg2iDgsIPPbT1woc5x7gz98OHp /APA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=Nng9FFdG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8-v6si15231272plb.125.2018.07.09.09.26.28; Mon, 09 Jul 2018 09:26:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=Nng9FFdG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933323AbeGIQZT (ORCPT + 99 others); Mon, 9 Jul 2018 12:25:19 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:33993 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932770AbeGIQZR (ORCPT ); Mon, 9 Jul 2018 12:25:17 -0400 Received: by mail-ed1-f68.google.com with SMTP id d3-v6so14417750edi.1 for ; Mon, 09 Jul 2018 09:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+fbqYqPvkeNQn/GeP/TLNQC6r5DJ3br/mflYTWDsAbw=; b=Nng9FFdGyGViJ8cgd79/orpbzKuVGmwUXJf4atqY2h114pBGvoAREAu9vAT0J4zZO5 w4lEFY/wE5doRrPvHltThc/8zmdKKtJAqE2jJJbL8UROycNE5j1r7x954GHh5ZAhxwjS fiBqWQ8oJhj7L6GSi2M4j6DDRzQABcHHOXylM= 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=XnVGkzfrqIHTL0T3B33oxYJL+rgt9PHUhUIS4B+SYCi4E5CVYuvBGtFfUYkpdvkhkw iazEcUzotwzmR6sNQMSz1y91msOBpUNnRQ9TnmF79TayUhIELk/7UEIyAxE+MjhGxuVU RIXYnw92VYsqP/SqkRn3nfFb4LZ3z/5Snt2xOGqkUL9j69pUzeCNXND8EaHs17iWW7mA E3KB1B4J0mXWJ/VlcU+kQBhhLzL69zl66zvy3X+E8S9hNVHHM2RmHtqGtuDMURSgvQWX ZT2uWuHlW7BFZVvrsxOGWhOAK0r18mwQE7zRJfuSuyJvBTCLxtvPHuHxf0QEiY5FMW4g u3TQ== X-Gm-Message-State: APt69E3cTViE7/sA61Jcw3Gn4mKH91lol6w6LnfnNRFPdbfw5yQxhyzy TAYM5UP+2+op+MXPIBoSmYAmFvlf 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 Cc: DRI Development , Intel Graphics Development , Daniel Vetter , Gustavo Padovan , Maarten Lankhorst , Sean Paul , David Airlie , Andrew Morton , Kees Cook , Ingo Molnar , Greg Kroah-Hartman , NeilBrown , Wei Wang , Stefan Agner , Andrei Vagin , Randy Dunlap , Andy Shevchenko , Yisheng Xie , Peter Zijlstra , Daniel Vetter Subject: [PATCH] kernel.h: Add for_each_if() 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); \ -- 2.18.0