linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: 권오훈 <ohoono.kwon@samsung.com>
To: "robh+dt@kernel.org" <robh+dt@kernel.org>,
	"frowand.list@gmail.com" <frowand.list@gmail.com>
Cc: "lee.jones@linaro.org" <lee.jones@linaro.org>,
	권오훈 <ohoono.kwon@samsung.com>,
	"ohkwon1043@gmail.com" <ohkwon1043@gmail.com>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH] of: base: remove unnecessary for loop
Date: Thu, 01 Jul 2021 23:03:28 +0900	[thread overview]
Message-ID: <20210701140328epcms1p85149318b6c18fa18b3c7c8e966c14db0@epcms1p8> (raw)
In-Reply-To: <CGME20210701140328epcms1p85149318b6c18fa18b3c7c8e966c14db0@epcms1p8>

In __of_get_next_child function, loop iteration for getting next node is
unnecessary.

for loop is already checking if next is NULL or not, and
of_node_get(next) always returns next itself.

Therefore checking return value in the if clause always evaluates to
true, and thus it always breaks out from for loop in the first iteration.

Remove the unnecessary for loop for readability.

I tested the code as below, and it showed that BUG was never called.

-       for (; next; next = next->sibling)
+       for (; next; next = next->sibling) {
                if (of_node_get(next))
                        break;
+               BUG();
+       }

Signed-off-by: Ohhoon Kwon <ohoono.kwon@samsung.com>
---
 drivers/of/base.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 48e941f99558..ca60988ef428 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -708,9 +708,7 @@ static struct device_node *__of_get_next_child(const struct device_node *node,
 		return NULL;
 
 	next = prev ? prev->sibling : node->child;
-	for (; next; next = next->sibling)
-		if (of_node_get(next))
-			break;
+	of_node_get(next);
 	of_node_put(prev);
 	return next;
 }
-- 
2.17.1

       reply	other threads:[~2021-07-01 14:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20210701140328epcms1p85149318b6c18fa18b3c7c8e966c14db0@epcms1p8>
2021-07-01 14:03 ` 권오훈 [this message]
2021-07-14 22:30   ` Rob Herring
2021-07-01 14:11 ` [PATCH] of: of_reserved_mem: match memblock_free with memblock_reserve 권오훈

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210701140328epcms1p85149318b6c18fa18b3c7c8e966c14db0@epcms1p8 \
    --to=ohoono.kwon@samsung.com \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ohkwon1043@gmail.com \
    --cc=robh+dt@kernel.org \
    --subject='Re: [PATCH] of: base: remove unnecessary for loop' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).