diff mbox series

[v2,1/2] drm: Move for_each_if() to util_macros.h for wider use

Message ID 20250213182527.3092371-2-andriy.shevchenko@linux.intel.com (mailing list archive)
State New
Headers show
Series gpiolib: Make code more robust by using for_each_if() | expand

Commit Message

Andy Shevchenko Feb. 13, 2025, 6:24 p.m. UTC
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 <brgl@bgdev.pl>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/drm/drm_util.h      | 16 +---------------
 include/linux/util_macros.h | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 15 deletions(-)

Comments

Bartosz Golaszewski Feb. 13, 2025, 6:36 p.m. UTC | #1
On Thu, Feb 13, 2025 at 7:25 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> 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 <brgl@bgdev.pl>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Who would pick it up? Should I take it via the GPIO tree and provide
an immutable branch for the DRM tree?

Bart
Jani Nikula Feb. 13, 2025, 6:48 p.m. UTC | #2
On Thu, 13 Feb 2025, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 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 <brgl@bgdev.pl>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Yay!

Acked-by: Jani Nikula <jani.nikula@intel.com>

If you want to go down the memory lane, see [1]. ;)


[1] https://lore.kernel.org/r/20180709083650.23549-1-daniel.vetter@ffwll.ch

> ---
>  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 <linux/kgdb.h>
>  #include <linux/preempt.h>
>  #include <linux/smp.h>
> +#include <linux/util_macros.h>
>  
>  /*
>   * 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 <linux/math.h>
>  
> +/**
> + * 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.
Andy Shevchenko Feb. 13, 2025, 6:50 p.m. UTC | #3
On Thu, Feb 13, 2025 at 07:36:38PM +0100, Bartosz Golaszewski wrote:
> On Thu, Feb 13, 2025 at 7:25 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > Other subsystem(s) may want to reuse the for_each_if() macro.
> > Move it to util_macros.h to make it globally available.

> Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> Who would pick it up? Should I take it via the GPIO tree and provide
> an immutable branch for the DRM tree?

I believe it makes sense as the first user outside drm is GPIO.
Andy Shevchenko Feb. 13, 2025, 6:51 p.m. UTC | #4
On Thu, Feb 13, 2025 at 08:48:02PM +0200, Jani Nikula wrote:
> On Thu, 13 Feb 2025, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > Other subsystem(s) may want to reuse the for_each_if() macro.
> > Move it to util_macros.h to make it globally available.

> Acked-by: Jani Nikula <jani.nikula@intel.com>

Thanks!

> If you want to go down the memory lane, see [1]. ;)
> 
> [1] https://lore.kernel.org/r/20180709083650.23549-1-daniel.vetter@ffwll.ch

Yeah, I have read it a few hours ago to refresh my memories.
diff mbox series

Patch

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 <linux/kgdb.h>
 #include <linux/preempt.h>
 #include <linux/smp.h>
+#include <linux/util_macros.h>
 
 /*
  * 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 <linux/math.h>
 
+/**
+ * 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.