diff mbox series

[3/3] ASoC: atmel-ssc: replace usage of found with dedicated list iterator variable

Message ID 20220331215003.882143-3-jakobkoschel@gmail.com
State New
Headers show
Series [1/3] ASoC: Intel: catpt: remove check of list iterator against head past the loop body | expand

Commit Message

Jakob Koschel March 31, 2022, 9:50 p.m. UTC
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/ [1]
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
---
 drivers/misc/atmel-ssc.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

Comments

Codrin Ciubotariu April 5, 2022, 6:44 a.m. UTC | #1
On 01.04.2022 00:50, Jakob Koschel wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> 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/ [1]
> Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>

Reviewed-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>

Thanks!
diff mbox series

Patch

diff --git a/drivers/misc/atmel-ssc.c b/drivers/misc/atmel-ssc.c
index d6cd5537126c..343e25555fbb 100644
--- a/drivers/misc/atmel-ssc.c
+++ b/drivers/misc/atmel-ssc.c
@@ -25,25 +25,24 @@  static LIST_HEAD(ssc_list);
 
 struct ssc_device *ssc_request(unsigned int ssc_num)
 {
-	int ssc_valid = 0;
-	struct ssc_device *ssc;
+	struct ssc_device *ssc = NULL, *iter;
 
 	mutex_lock(&user_lock);
-	list_for_each_entry(ssc, &ssc_list, list) {
-		if (ssc->pdev->dev.of_node) {
-			if (of_alias_get_id(ssc->pdev->dev.of_node, "ssc")
+	list_for_each_entry(iter, &ssc_list, list) {
+		if (iter->pdev->dev.of_node) {
+			if (of_alias_get_id(iter->pdev->dev.of_node, "ssc")
 				== ssc_num) {
-				ssc->pdev->id = ssc_num;
-				ssc_valid = 1;
+				iter->pdev->id = ssc_num;
+				ssc = iter;
 				break;
 			}
-		} else if (ssc->pdev->id == ssc_num) {
-			ssc_valid = 1;
+		} else if (iter->pdev->id == ssc_num) {
+			ssc = iter;
 			break;
 		}
 	}
 
-	if (!ssc_valid) {
+	if (!ssc) {
 		mutex_unlock(&user_lock);
 		pr_err("ssc: ssc%d platform device is missing\n", ssc_num);
 		return ERR_PTR(-ENODEV);