diff mbox series

[PATCHv6,net-next,7/7] net: ibm: emac: use of_find_matching_node

Message ID 20241011195622.6349-8-rosenp@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series ibm: emac: more cleanups | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 3 this patch: 3
netdev/checkpatch fail ERROR: space required before the open parenthesis '('
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-10-12--12-00 (tests: 777)

Commit Message

Rosen Penev Oct. 11, 2024, 7:56 p.m. UTC
Cleaner than using of_find_all_nodes and then of_match_node.

Also modified EMAC_BOOT_LIST_SIZE check to run before of_node_get to
avoid having to call of_node_put on failure.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/net/ethernet/ibm/emac/core.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Comments

Simon Horman Oct. 12, 2024, 1:21 p.m. UTC | #1
On Fri, Oct 11, 2024 at 12:56:22PM -0700, Rosen Penev wrote:
> Cleaner than using of_find_all_nodes and then of_match_node.
> 
> Also modified EMAC_BOOT_LIST_SIZE check to run before of_node_get to
> avoid having to call of_node_put on failure.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/net/ethernet/ibm/emac/core.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
> index faa483790b29..5265616400c2 100644
> --- a/drivers/net/ethernet/ibm/emac/core.c
> +++ b/drivers/net/ethernet/ibm/emac/core.c
> @@ -3253,21 +3253,17 @@ static void __init emac_make_bootlist(void)
>  	int cell_indices[EMAC_BOOT_LIST_SIZE];
>  
>  	/* Collect EMACs */
> -	while((np = of_find_all_nodes(np)) != NULL) {
> +	while((np = of_find_matching_node(np, emac_match))) {
>  		u32 idx;
>  
> -		if (of_match_node(emac_match, np) == NULL)
> -			continue;
>  		if (of_property_read_bool(np, "unused"))
>  			continue;
>  		if (of_property_read_u32(np, "cell-index", &idx))
>  			continue;
>  		cell_indices[i] = idx;
> -		emac_boot_list[i++] = of_node_get(np);
> -		if (i >= EMAC_BOOT_LIST_SIZE) {
> -			of_node_put(np);
> +		if (i >= EMAC_BOOT_LIST_SIZE)
>  			break;
> -		}
> +		emac_boot_list[i++] = of_node_get(np);

Reading the Kernel doc for of_find_matching_node() it seems
that of_node_put() needs to called each time it (and thus
of_find_matching_node() returns a np. But that doesn't seem
to be the case here. Am I mistaken?


>  	}
>  	max = i;
>  
> -- 
> 2.47.0
>
Rosen Penev Oct. 15, 2024, 7:45 p.m. UTC | #2
On Sat, Oct 12, 2024 at 6:21 AM Simon Horman <horms@kernel.org> wrote:
>
> On Fri, Oct 11, 2024 at 12:56:22PM -0700, Rosen Penev wrote:
> > Cleaner than using of_find_all_nodes and then of_match_node.
> >
> > Also modified EMAC_BOOT_LIST_SIZE check to run before of_node_get to
> > avoid having to call of_node_put on failure.
> >
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > ---
> >  drivers/net/ethernet/ibm/emac/core.c | 10 +++-------
> >  1 file changed, 3 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
> > index faa483790b29..5265616400c2 100644
> > --- a/drivers/net/ethernet/ibm/emac/core.c
> > +++ b/drivers/net/ethernet/ibm/emac/core.c
> > @@ -3253,21 +3253,17 @@ static void __init emac_make_bootlist(void)
> >       int cell_indices[EMAC_BOOT_LIST_SIZE];
> >
> >       /* Collect EMACs */
> > -     while((np = of_find_all_nodes(np)) != NULL) {
> > +     while((np = of_find_matching_node(np, emac_match))) {
> >               u32 idx;
> >
> > -             if (of_match_node(emac_match, np) == NULL)
> > -                     continue;
> >               if (of_property_read_bool(np, "unused"))
> >                       continue;
> >               if (of_property_read_u32(np, "cell-index", &idx))
> >                       continue;
> >               cell_indices[i] = idx;
> > -             emac_boot_list[i++] = of_node_get(np);
> > -             if (i >= EMAC_BOOT_LIST_SIZE) {
> > -                     of_node_put(np);
> > +             if (i >= EMAC_BOOT_LIST_SIZE)
> >                       break;
> > -             }
> > +             emac_boot_list[i++] = of_node_get(np);
>
> Reading the Kernel doc for of_find_matching_node() it seems
> that of_node_put() needs to called each time it (and thus
> of_find_matching_node() returns a np. But that doesn't seem
> to be the case here. Am I mistaken?
Bad change. Will remove.
>
>
> >       }
> >       max = i;
> >
> > --
> > 2.47.0
> >
diff mbox series

Patch

diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index faa483790b29..5265616400c2 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -3253,21 +3253,17 @@  static void __init emac_make_bootlist(void)
 	int cell_indices[EMAC_BOOT_LIST_SIZE];
 
 	/* Collect EMACs */
-	while((np = of_find_all_nodes(np)) != NULL) {
+	while((np = of_find_matching_node(np, emac_match))) {
 		u32 idx;
 
-		if (of_match_node(emac_match, np) == NULL)
-			continue;
 		if (of_property_read_bool(np, "unused"))
 			continue;
 		if (of_property_read_u32(np, "cell-index", &idx))
 			continue;
 		cell_indices[i] = idx;
-		emac_boot_list[i++] = of_node_get(np);
-		if (i >= EMAC_BOOT_LIST_SIZE) {
-			of_node_put(np);
+		if (i >= EMAC_BOOT_LIST_SIZE)
 			break;
-		}
+		emac_boot_list[i++] = of_node_get(np);
 	}
 	max = i;