[PATCH] soc: brcmstb: pm: Add of_node_put() when the iteration breaks

Arnd Bergmann arnd at arndb.de
Tue Jul 5 04:54:05 PDT 2022


On Tue, Jul 5, 2022 at 1:28 PM Liang He <windhl at 126.com> wrote:
> --- a/drivers/soc/bcm/brcmstb/pm/pm-arm.c
> +++ b/drivers/soc/bcm/brcmstb/pm/pm-arm.c
> @@ -732,11 +732,13 @@ static int brcmstb_pm_probe(struct platform_device *pdev)
>                 i = ctrl.num_memc;
>                 if (i >= MAX_NUM_MEMC) {
>                         pr_warn("too many MEMCs (max %d)\n", MAX_NUM_MEMC);
> +                       of_node_put(dn);
>                         break;
>                 }
>
>                 base = of_io_request_and_map(dn, 0, dn->full_name);
>                 if (IS_ERR(base)) {
> +                       of_node_put(dn);
>                         if (!ctrl.support_warm_boot)
>                                 break;
>
> @@ -752,12 +754,14 @@ static int brcmstb_pm_probe(struct platform_device *pdev)
>         for_each_matching_node(dn, brcmstb_memc_of_match) {
>                 base = of_iomap(dn, 0);
>                 if (!base) {
> +                       of_node_put(dn);
>                         pr_err("error mapping DDR Sequencer %d\n", i);
>                         return -ENOMEM;
>                 }
>
>                 of_id = of_match_node(brcmstb_memc_of_match, dn);
>                 if (!of_id) {
> +                       of_node_put(dn);
>                         iounmap(base);
>                         return -EINVAL;
>                 }

While all of these changes look correct to me, there seems to be a
larger issue in the error handling for these loops, as they also leak
the __iomem token returned by of_iomap()/of_io_request_and_map()
and by the earlier calls from this function.

Can you try to rework the unwinding to address those as well?

       Arnd



More information about the linux-arm-kernel mailing list