linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] backlight: replace usage of found with dedicated list iterator variable
@ 2022-03-24  7:06 Jakob Koschel
  2022-03-24 14:55 ` Daniel Thompson
  0 siblings, 1 reply; 2+ messages in thread
From: Jakob Koschel @ 2022-03-24  7:06 UTC (permalink / raw)
  To: Lee Jones
  Cc: Daniel Thompson, Jingoo Han, Helge Deller, dri-devel,
	linux-fbdev, linux-kernel, Mike Rapoport, Brian Johannesmeyer,
	Cristiano Giuffrida, Bos, H.J.,
	Jakob Koschel

To move the list iterator variable into the list_for_each_entry_*()
macro in the future it should be avoided to use the list iterator
variable after the loop body.

To *never* use the list iterator variable after the loop it was
concluded to use a separate iterator variable instead of a
found boolean [1].

This removes the need to use a found variable and simply checking if
the variable was set, can determine if the break/goto was hit.

Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
---
 drivers/video/backlight/backlight.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 4ae6fae94ac2..c05380d7a09e 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -479,19 +479,18 @@ EXPORT_SYMBOL(backlight_device_register);
  */
 struct backlight_device *backlight_device_get_by_type(enum backlight_type type)
 {
-	bool found = false;
-	struct backlight_device *bd;
+	struct backlight_device *bd = NULL, *iter;
 
 	mutex_lock(&backlight_dev_list_mutex);
-	list_for_each_entry(bd, &backlight_dev_list, entry) {
-		if (bd->props.type == type) {
-			found = true;
+	list_for_each_entry(iter, &backlight_dev_list, entry) {
+		if (iter->props.type == type) {
+			bd = iter;
 			break;
 		}
 	}
 	mutex_unlock(&backlight_dev_list_mutex);
 
-	return found ? bd : NULL;
+	return bd;
 }
 EXPORT_SYMBOL(backlight_device_get_by_type);
 

base-commit: f443e374ae131c168a065ea1748feac6b2e76613
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] backlight: replace usage of found with dedicated list iterator variable
  2022-03-24  7:06 [PATCH] backlight: replace usage of found with dedicated list iterator variable Jakob Koschel
@ 2022-03-24 14:55 ` Daniel Thompson
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Thompson @ 2022-03-24 14:55 UTC (permalink / raw)
  To: Jakob Koschel
  Cc: Lee Jones, Jingoo Han, Helge Deller, dri-devel, linux-fbdev,
	linux-kernel, Mike Rapoport, Brian Johannesmeyer,
	Cristiano Giuffrida, Bos, H.J.

On Thu, Mar 24, 2022 at 08:06:08AM +0100, Jakob Koschel wrote:
> To move the list iterator variable into the list_for_each_entry_*()
> macro in the future it should be avoided to use the list iterator
> variable after the loop body.
> 
> To *never* use the list iterator variable after the loop it was
> concluded to use a separate iterator variable instead of a
> found boolean [1].
> 
> This removes the need to use a found variable and simply checking if
> the variable was set, can determine if the break/goto was hit.
> 
> Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/
> Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>

Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>


Daniel.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-24 14:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24  7:06 [PATCH] backlight: replace usage of found with dedicated list iterator variable Jakob Koschel
2022-03-24 14:55 ` Daniel Thompson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).