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: 864903 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26A622063E1; Thu, 13 Feb 2025 18:25:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739471135; cv=none; b=rPbYLQK3KPbdU9RXItI6bmfRO4OQTwxU2cRyOKOVjhFOrr7OHYBJZ2hV7F0rusuv3efPUnf7kEpMAD2INi1/am5SOXRyoBTIkoybmhgUvm5Bx6LvL4M8c97B3KOhbotewjP7Y9u4Ij8UNjBLUV098OfcnmP73EaZzP4bJTggp9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739471135; c=relaxed/simple; bh=uLX7BKkCsOAAmxOi6VDKnJUBlyAfuP7t1DKSjk9fKlE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XEfRETXc30YSZsVGQaTO6Tf7+Kwcr8O/TRo45dlGCDl2Scf/Add+R/28Oscr2d1YM/AYTHi+pCkJpB0FSXFPwHqCfd4Z/XZt15QryDIHEUxPiFHJLl5p2ct366NnlmMaHfgmjBnedt3oJuWrp/kYJTfecCAcaKzWgz/68zyLlBw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=S5Jg4K2V; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="S5Jg4K2V" 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: cqLohFrFRFi3wS3QVHbzPw== X-CSE-MsgGUID: qvHm1/g+RHGTfL8FaqvllA== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="50407634" X-IronPort-AV: E=Sophos;i="6.13,282,1732608000"; d="scan'208";a="50407634" 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:33 -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> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 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: 864902 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08853245027; Thu, 13 Feb 2025 18:25:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739471143; cv=none; b=pqz4clgsgSS10rPyeAkas+gEpCf4Wjeyw+WOGEPCgX7CQeb+4wYqV7ghOFuQmRyMII6svYjld3zc1lz1Fyt4nhSUq9gFNN3rf+Vt25Zza5YHuNCXKhtt6On1nQ1a4BhN0HLFYFYzOBLWYc2kf8ncguG2XK/A+kdODoNxvUDZvCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739471143; c=relaxed/simple; bh=k7ua/KFoZaBYMvO6Q/O+0QUvgRzL0DRgto7N8H41V7g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FJwQroB7BMcU5VddR8WYGFMxbxRjPDnUhJiZaWLBtNK/huBijMHHe729MDhpCo0fF3RoSb3hchZUCR1zaIz2GtkusEYI/Xf1TXWO8XZPGAdqgKah2oY2qIoW5cBl1+3wkdTbC0IHoN8kZQ/kR2iH7gxXiWr16RHOSuKWzrF2bkc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=H2oIPWI7; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="H2oIPWI7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739471142; x=1771007142; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k7ua/KFoZaBYMvO6Q/O+0QUvgRzL0DRgto7N8H41V7g=; b=H2oIPWI7BdB1XK9LnqzUZ4WP9U//+Lx/QzIrIQk5q3IOuxLWDWb/qQTS HIzEZzE9QnXmZho3UfHn4DNGdxk5r+mhkFpZa97qE2iain+9017WQe2Yi M14s4US5rhTr42K9jrz4SNb/oO6ceo/dvygNvwmry9DTi5JY7G2dOgiSv 3d4RK+gzg8wD8qQO0/aYFZLUWS6b4tBTAYXf8nu6n/1HjBkLOTL77R09s sdPQTEJT6wgtXSUYQbfkyUN+HoSVd2dQIT6+f2wGtb3TpQJvphE7cGlc5 xTmLTxCcgKU0KqzkuucIdgzlcvD0SRRrb7gvyCConIspf0gpG1U3NzMfr Q==; X-CSE-ConnectionGUID: N+ZUfQGuR1ujI9DhJ+eNxQ== X-CSE-MsgGUID: +qkUdcD0SiuEPDmnurJG2w== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="51177657" X-IronPort-AV: E=Sophos;i="6.13,282,1732608000"; d="scan'208";a="51177657" 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> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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) {