[PATCH 2/2] bus: stm32_firewall: Simplify with scoped for each OF child loop

Jonathan Cameron jonathan.cameron at huawei.com
Mon Jan 5 02:49:10 PST 2026


On Fri,  2 Jan 2026 13:50:32 +0100
Krzysztof Kozlowski <krzysztof.kozlowski at oss.qualcomm.com> wrote:

> Use scoped for-each loop when iterating over device nodes to make code a
> bit simpler.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski at oss.qualcomm.com>
You could throw a __free() in there for firewalls and avoid having
any cleanup at all to do on error (or good path for that matter).

Otherwise LGTM.

Jonathan

> ---
>  drivers/bus/stm32_firewall.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/bus/stm32_firewall.c b/drivers/bus/stm32_firewall.c
> index 2fc9761dadec..fae881cea9a0 100644
> --- a/drivers/bus/stm32_firewall.c
> +++ b/drivers/bus/stm32_firewall.c
> @@ -241,7 +241,6 @@ EXPORT_SYMBOL_GPL(stm32_firewall_controller_unregister);
>  int stm32_firewall_populate_bus(struct stm32_firewall_controller *firewall_controller)
>  {
>  	struct stm32_firewall *firewalls;
> -	struct device_node *child;
>  	struct device *parent;
>  	unsigned int i;
>  	int len;
> @@ -251,25 +250,20 @@ int stm32_firewall_populate_bus(struct stm32_firewall_controller *firewall_contr
>  
>  	dev_dbg(parent, "Populating %s system bus\n", dev_name(firewall_controller->dev));
>  
> -	for_each_available_child_of_node(dev_of_node(parent), child) {
> +	for_each_available_child_of_node_scoped(dev_of_node(parent), child) {
>  		/* The access-controllers property is mandatory for firewall bus devices */
>  		len = of_count_phandle_with_args(child, "access-controllers",
>  						 "#access-controller-cells");
> -		if (len <= 0) {
> -			of_node_put(child);
> +		if (len <= 0)
>  			return -EINVAL;
> -		}
>  
>  		firewalls = kcalloc(len, sizeof(*firewalls), GFP_KERNEL);
> -		if (!firewalls) {
> -			of_node_put(child);
> +		if (!firewalls)
>  			return -ENOMEM;
> -		}
>  
>  		err = stm32_firewall_get_firewall(child, firewalls, (unsigned int)len);
>  		if (err) {
>  			kfree(firewalls);
> -			of_node_put(child);
>  			return err;
>  		}
>  




More information about the linux-arm-kernel mailing list