[PATCH v1] of: Put coreboot node after compatibility check

Yuho Choi posted 1 patch 2 months ago
There is a newer version of this series
drivers/of/base.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
[PATCH v1] of: Put coreboot node after compatibility check
Posted by Yuho Choi 2 months ago
of_find_compatible_node() returns a referenced device node, but
EXCLUDED_DEFAULT_CELLS_PLATFORMS used the result only as a boolean and
discarded the reference. This leaked a reference each time the
address-cells or size-cells warning condition was evaluated on a
coreboot system.

Use a helper that drops the node reference after checking whether the
coreboot node exists.

Fixes: 8600058ba28a7 ("of: Add coreboot firmware to excluded default cells list")
Signed-off-by: Yuho Choi <dbgh9129@gmail.com>
---
 drivers/of/base.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 6e7a42dedad3..8d04eaed9805 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -95,9 +95,21 @@ static bool __of_node_is_type(const struct device_node *np, const char *type)
 	return !strcmp(match, type);
 }
 
+static bool of_coreboot_present(void)
+{
+	struct device_node *np;
+	bool found;
+
+	np = of_find_compatible_node(NULL, NULL, "coreboot");
+	found = np != NULL;
+	of_node_put(np);
+
+	return found;
+}
+
 #define EXCLUDED_DEFAULT_CELLS_PLATFORMS ( \
 	IS_ENABLED(CONFIG_SPARC) || \
-	of_find_compatible_node(NULL, NULL, "coreboot") \
+	of_coreboot_present() \
 )
 
 int of_bus_n_addr_cells(struct device_node *np)
-- 
2.43.0
Re: [PATCH v1] of: Put coreboot node after compatibility check
Posted by Krzysztof Kozlowski 1 month, 4 weeks ago
On Sat, Aug 01, 2026 at 10:38:21PM -0400, Yuho Choi wrote:
> of_find_compatible_node() returns a referenced device node, but
> EXCLUDED_DEFAULT_CELLS_PLATFORMS used the result only as a boolean and
> discarded the reference. This leaked a reference each time the
> address-cells or size-cells warning condition was evaluated on a
> coreboot system.
> 
> Use a helper that drops the node reference after checking whether the
> coreboot node exists.
> 
> Fixes: 8600058ba28a7 ("of: Add coreboot firmware to excluded default cells list")
> Signed-off-by: Yuho Choi <dbgh9129@gmail.com>
> ---
>  drivers/of/base.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 6e7a42dedad3..8d04eaed9805 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -95,9 +95,21 @@ static bool __of_node_is_type(const struct device_node *np, const char *type)
>  	return !strcmp(match, type);
>  }
>  
> +static bool of_coreboot_present(void)
> +{
> +	struct device_node *np;
> +	bool found;
> +
> +	np = of_find_compatible_node(NULL, NULL, "coreboot");

Code is simple, but could be even simpler with __free. Basically two
instructions instead of four and no need for this assignment comparison.

> +	found = np != NULL;
> +	of_node_put(np);

Best regards,
Krzysztof