2024-04-16 01:30:54

by Marilene A Garcia

[permalink] [raw]
Subject: [PATCH] nvmem: meson-efuse: Replacing the use of of_node_put to __free

Use __free for device_node values, and thus drop calls to
of_node_put.

The goal is to reduce memory management issues by using this
scope-based of_node_put() cleanup to simplify function exit
handling. When using __free a resource is allocated within a
block, it is automatically freed at the end of the block.

Suggested-by: Julia Lawall <[email protected]>
Signed-off-by: MarileneGarcia <[email protected]>
---
drivers/nvmem/meson-efuse.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c
index 33678d0af2c2..400a9a075e53 100644
--- a/drivers/nvmem/meson-efuse.c
+++ b/drivers/nvmem/meson-efuse.c
@@ -42,20 +42,19 @@ static int meson_efuse_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct meson_sm_firmware *fw;
- struct device_node *sm_np;
struct nvmem_device *nvmem;
struct nvmem_config *econfig;
struct clk *clk;
unsigned int size;
+ struct device_node *sm_np __free(device_node) =
+ of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);

- sm_np = of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
if (!sm_np) {
dev_err(&pdev->dev, "no secure-monitor node\n");
return -ENODEV;
}

fw = meson_sm_get(sm_np);
- of_node_put(sm_np);
if (!fw)
return -EPROBE_DEFER;

--
2.34.1



2024-05-15 02:29:37

by Marilene A Garcia

[permalink] [raw]
Subject: Re: [PATCH] nvmem: meson-efuse: Replacing the use of of_node_put to __free

On 15/04/2024 22:17, MarileneGarcia wrote:
> Use __free for device_node values, and thus drop calls to
> of_node_put.
>
> The goal is to reduce memory management issues by using this
> scope-based of_node_put() cleanup to simplify function exit
> handling. When using __free a resource is allocated within a
> block, it is automatically freed at the end of the block.
>
> Suggested-by: Julia Lawall <[email protected]>
> Signed-off-by: MarileneGarcia <[email protected]>
> ---
> drivers/nvmem/meson-efuse.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c
> index 33678d0af2c2..400a9a075e53 100644
> --- a/drivers/nvmem/meson-efuse.c
> +++ b/drivers/nvmem/meson-efuse.c
> @@ -42,20 +42,19 @@ static int meson_efuse_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> struct meson_sm_firmware *fw;
> - struct device_node *sm_np;
> struct nvmem_device *nvmem;
> struct nvmem_config *econfig;
> struct clk *clk;
> unsigned int size;
> + struct device_node *sm_np __free(device_node) =
> + of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
>
> - sm_np = of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
> if (!sm_np) {
> dev_err(&pdev->dev, "no secure-monitor node\n");
> return -ENODEV;
> }
>
> fw = meson_sm_get(sm_np);
> - of_node_put(sm_np);
> if (!fw)
> return -EPROBE_DEFER;
>

Hello everyone,
Did you have a chance to look at the patch? Any questions or suggestions
about it?

Thank you,
Marilene

2024-05-15 07:38:46

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH] nvmem: meson-efuse: Replacing the use of of_node_put to __free



On Tue, 14 May 2024, Marilene Andrade Garcia wrote:

> On 15/04/2024 22:17, MarileneGarcia wrote:
> > Use __free for device_node values, and thus drop calls to
> > of_node_put.
> >
> > The goal is to reduce memory management issues by using this
> > scope-based of_node_put() cleanup to simplify function exit
> > handling. When using __free a resource is allocated within a
> > block, it is automatically freed at the end of the block.
> >
> > Suggested-by: Julia Lawall <[email protected]>
> > Signed-off-by: MarileneGarcia <[email protected]>
> > ---
> > drivers/nvmem/meson-efuse.c | 5 ++---
> > 1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c
> > index 33678d0af2c2..400a9a075e53 100644
> > --- a/drivers/nvmem/meson-efuse.c
> > +++ b/drivers/nvmem/meson-efuse.c
> > @@ -42,20 +42,19 @@ static int meson_efuse_probe(struct platform_device
> > *pdev)
> > {
> > struct device *dev = &pdev->dev;
> > struct meson_sm_firmware *fw;
> > - struct device_node *sm_np;
> > struct nvmem_device *nvmem;
> > struct nvmem_config *econfig;
> > struct clk *clk;
> > unsigned int size;
> > + struct device_node *sm_np __free(device_node) =
> > + of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
> > - sm_np = of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);

There should be a blank line after the last variable declaration, so here.

julia

> > if (!sm_np) {
> > dev_err(&pdev->dev, "no secure-monitor node\n");
> > return -ENODEV;
> > }
> > fw = meson_sm_get(sm_np);
> > - of_node_put(sm_np);
> > if (!fw)
> > return -EPROBE_DEFER;
> >
>
> Hello everyone,
> Did you have a chance to look at the patch? Any questions or suggestions about
> it?
>
> Thank you,
> Marilene
>