From patchwork Thu Feb 13 18:24:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13973889 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68B3BC021A0 for ; Thu, 13 Feb 2025 18:25:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D94B810EB6B; Thu, 13 Feb 2025 18:25:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="S5Jg4K2V"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6959310EB6B for ; Thu, 13 Feb 2025 18:25:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739471134; x=1771007134; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uLX7BKkCsOAAmxOi6VDKnJUBlyAfuP7t1DKSjk9fKlE=; b=S5Jg4K2Vs4K3i/d+CF1fT8NFfNmUnquhAdtAEW0vt8EVXS5Lk+M2ZJmM 6hNijT7vi0l8xvESMz7Ok+bSbVdIzBWH2h/UicJ3j5HaVkJ33gvFgiZad AWcVMeXgCYudY/xkwMrmdEsttFZBhcXy+7ZgL80i9IUengilowe+/4Fe6 Fwq0i7Xg5FGQUy+8o1Q0V5zodv8QbjP8IScZkJH5AUqRFvMGvt5SnTjWD NKgmNJDrEWeC0ZfGbCI7irnyPmxfbPbun5cW5Pk2PyKb7VkSRbPwwZyZY 7+jeuy3ab9n2rqINe5qOQVIwr/HtqcJk/Ty44QCouhbJuXagFCJu1PzGg g==; X-CSE-ConnectionGUID: XzjhmB/ASgGpi0XfMNRakQ== X-CSE-MsgGUID: qdX8S4jtQImI/22/SkLngQ== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="50407640" X-IronPort-AV: E=Sophos;i="6.13,282,1732608000"; d="scan'208";a="50407640" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 10:25:34 -0800 X-CSE-ConnectionGUID: L6EReLleSf2aGolaPW7PZA== X-CSE-MsgGUID: Y5FJqQU3Tbm7wX/V0GFH7g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,282,1732608000"; d="scan'208";a="118314411" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa004.fm.intel.com with ESMTP; 13 Feb 2025 10:25:30 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 068891F5; Thu, 13 Feb 2025 20:25:28 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , Alexandru Ardelean , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Linus Walleij , Bartosz Golaszewski Subject: [PATCH v2 1/2] drm: Move for_each_if() to util_macros.h for wider use Date: Thu, 13 Feb 2025 20:24:00 +0200 Message-ID: <20250213182527.3092371-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.45.1.3035.g276e886db78b In-Reply-To: <20250213182527.3092371-1-andriy.shevchenko@linux.intel.com> References: <20250213182527.3092371-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Other subsystem(s) may want to reuse the for_each_if() macro. Move it to util_macros.h to make it globally available. Suggested-by: Bartosz Golaszewski Signed-off-by: Andy Shevchenko Reviewed-by: Bartosz Golaszewski Acked-by: Jani Nikula --- include/drm/drm_util.h | 16 +--------------- include/linux/util_macros.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/include/drm/drm_util.h b/include/drm/drm_util.h index 79952d8c4bba..440199618620 100644 --- a/include/drm/drm_util.h +++ b/include/drm/drm_util.h @@ -36,6 +36,7 @@ #include #include #include +#include /* * Use EXPORT_SYMBOL_FOR_TESTS_ONLY() for functions that shall @@ -47,21 +48,6 @@ #define EXPORT_SYMBOL_FOR_TESTS_ONLY(x) #endif -/** - * for_each_if - helper for handling conditionals in various for_each macros - * @condition: The condition to check - * - * Typical use:: - * - * #define for_each_foo_bar(x, y) \' - * list_for_each_entry(x, y->list, head) \' - * for_each_if(x->something == SOMETHING) - * - * The for_each_if() macro makes the use of for_each_foo_bar() less error - * prone. - */ -#define for_each_if(condition) if (!(condition)) {} else - /** * drm_can_sleep - returns true if currently okay to sleep * diff --git a/include/linux/util_macros.h b/include/linux/util_macros.h index 825487fb66fa..3b570b765b75 100644 --- a/include/linux/util_macros.h +++ b/include/linux/util_macros.h @@ -4,6 +4,21 @@ #include +/** + * for_each_if - helper for handling conditionals in various for_each macros + * @condition: The condition to check + * + * Typical use:: + * + * #define for_each_foo_bar(x, y) \' + * list_for_each_entry(x, y->list, head) \' + * for_each_if(x->something == SOMETHING) + * + * The for_each_if() macro makes the use of for_each_foo_bar() less error + * prone. + */ +#define for_each_if(condition) if (!(condition)) {} else + /** * find_closest - locate the closest element in a sorted array * @x: The reference value. From patchwork Thu Feb 13 18:24:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13973891 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63C1EC021A6 for ; Thu, 13 Feb 2025 18:25:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E85F410EB72; Thu, 13 Feb 2025 18:25:40 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="N530O3Jm"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id AC30410EB6C for ; Thu, 13 Feb 2025 18:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739471140; x=1771007140; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k7ua/KFoZaBYMvO6Q/O+0QUvgRzL0DRgto7N8H41V7g=; b=N530O3JmXoChO0hkLgp1XVLSZkYuQ38m5y4ITJnT35SEXyNdvMDgu+bT 4iRkobkSV+yUI/q24BzpjQTIyYdgrVvdBtjdw0TWVN38WdGles2+Dz1/a z6u/BoZzOnbxzdH1fOZxAHlC7OrTKTWkpE97Ni272WCysOwH/eWwv8Cdf cqknx/el8moXUkiMFFrmbMSZlvxCxK7LnECrBr3VMiWLpdSS0J/JzZkv+ ZK5cYPxNcxndfUZpZipZKSCAgFKMnTOrYjR7MeL/kNuqOd/Y4JRedlaEF K3Xoi8BC+vIoV6rxhbNNLpUcTcvKX5yCSpakYKjbiF2ub7XyLRjBIbjlC Q==; X-CSE-ConnectionGUID: rD7ia4RyQceASbqNERJDMQ== X-CSE-MsgGUID: 6k3qBaD5QrOQr6xM5Pow3w== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="51177660" X-IronPort-AV: E=Sophos;i="6.13,282,1732608000"; d="scan'208";a="51177660" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 10:25:35 -0800 X-CSE-ConnectionGUID: 2w/+92TyT6SEWaUrBCUo0A== X-CSE-MsgGUID: O+bpjhxARyus70Sw3d5X/g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="113721778" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa007.jf.intel.com with ESMTP; 13 Feb 2025 10:25:30 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 1BE642CA; Thu, 13 Feb 2025 20:25:29 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , Alexandru Ardelean , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Linus Walleij , Bartosz Golaszewski Subject: [PATCH v2 2/2] gpiolib: Switch to use for_each_if() helper Date: Thu, 13 Feb 2025 20:24:01 +0200 Message-ID: <20250213182527.3092371-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.45.1.3035.g276e886db78b In-Reply-To: <20250213182527.3092371-1-andriy.shevchenko@linux.intel.com> References: <20250213182527.3092371-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The for_each_*() APIs that are conditional can be written shorter and less error prone with for_each_if() helper in use. Switch them to use this helper. Signed-off-by: Andy Shevchenko --- include/linux/gpio/driver.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index ae93f75170f2..af046f7fd4f5 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -14,6 +14,7 @@ #include #include #include +#include #ifdef CONFIG_GENERIC_MSI_IRQ #include @@ -561,7 +562,7 @@ DEFINE_CLASS(_gpiochip_for_each_data, for (CLASS(_gpiochip_for_each_data, _data)(&_label, &_i); \ _i < _size; \ _i++, kfree(_label), _label = NULL) \ - if (IS_ERR(_label = gpiochip_dup_line_label(_chip, _base + _i))) {} else + for_each_if(!IS_ERR(_label = gpiochip_dup_line_label(_chip, _base + _i))) /** * for_each_hwgpio - Iterates over all GPIOs for given chip. @@ -583,7 +584,7 @@ DEFINE_CLASS(_gpiochip_for_each_data, */ #define for_each_requested_gpio_in_range(_chip, _i, _base, _size, _label) \ for_each_hwgpio_in_range(_chip, _i, _base, _size, _label) \ - if (_label == NULL) {} else + for_each_if(_label) /* Iterates over all requested GPIO of the given @chip */ #define for_each_requested_gpio(chip, i, label) \ @@ -869,7 +870,7 @@ static inline void gpiochip_unlock_as_irq(struct gpio_chip *gc, #define for_each_gpiochip_node(dev, child) \ device_for_each_child_node(dev, child) \ - if (!fwnode_property_present(child, "gpio-controller")) {} else + for_each_if(fwnode_property_present(child, "gpio-controller")) static inline unsigned int gpiochip_node_count(struct device *dev) {