2021-11-30 14:36:00

by Dongliang Mu

[permalink] [raw]
Subject: [PATCH] driver: pmc_atom: free pmc->regmap in pmc_setup_dev

Smatch reports:

drivers/platform/x86/pmc_atom.c:496
pmc_setup_dev() warn: 'pmc->regmap' not released on lines: 496.

Fix this by deallocating pm->regmap.

CC: Dan Carpenter <[email protected]>
Signed-off-by: Dongliang Mu <[email protected]>
---
drivers/platform/x86/pmc_atom.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/platform/x86/pmc_atom.c b/drivers/platform/x86/pmc_atom.c
index a9d2a4b98e57..95ba108ed716 100644
--- a/drivers/platform/x86/pmc_atom.c
+++ b/drivers/platform/x86/pmc_atom.c
@@ -492,6 +492,7 @@ static int pmc_setup_dev(struct pci_dev *pdev, const struct pci_device_id *ent)
dev_warn(&pdev->dev, "platform clocks register failed: %d\n",
ret);

+ iounmap(pmc->regmap);
pmc->init = true;
return ret;
}
--
2.25.1



2021-11-30 14:54:17

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] driver: pmc_atom: free pmc->regmap in pmc_setup_dev

On Tue, Nov 30, 2021 at 10:35:25PM +0800, Dongliang Mu wrote:
> Smatch reports:
>
> drivers/platform/x86/pmc_atom.c:496
> pmc_setup_dev() warn: 'pmc->regmap' not released on lines: 496.
>
> Fix this by deallocating pm->regmap.
>
> CC: Dan Carpenter <[email protected]>
> Signed-off-by: Dongliang Mu <[email protected]>
> ---
> drivers/platform/x86/pmc_atom.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/platform/x86/pmc_atom.c b/drivers/platform/x86/pmc_atom.c
> index a9d2a4b98e57..95ba108ed716 100644
> --- a/drivers/platform/x86/pmc_atom.c
> +++ b/drivers/platform/x86/pmc_atom.c
> @@ -492,6 +492,7 @@ static int pmc_setup_dev(struct pci_dev *pdev, const struct pci_device_id *ent)
> dev_warn(&pdev->dev, "platform clocks register failed: %d\n",
> ret);
>
> + iounmap(pmc->regmap);

This releases it on the success path so it will break the driver.

regards,
dan carpenter

> pmc->init = true;
> return ret;
> }
> --
> 2.25.1

2021-12-01 02:03:13

by Dongliang Mu

[permalink] [raw]
Subject: Re: [PATCH] driver: pmc_atom: free pmc->regmap in pmc_setup_dev

On Tue, Nov 30, 2021 at 10:51 PM Dan Carpenter <[email protected]> wrote:
>
> On Tue, Nov 30, 2021 at 10:35:25PM +0800, Dongliang Mu wrote:
> > Smatch reports:
> >
> > drivers/platform/x86/pmc_atom.c:496
> > pmc_setup_dev() warn: 'pmc->regmap' not released on lines: 496.
> >
> > Fix this by deallocating pm->regmap.
> >
> > CC: Dan Carpenter <[email protected]>
> > Signed-off-by: Dongliang Mu <[email protected]>
> > ---
> > drivers/platform/x86/pmc_atom.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/platform/x86/pmc_atom.c b/drivers/platform/x86/pmc_atom.c
> > index a9d2a4b98e57..95ba108ed716 100644
> > --- a/drivers/platform/x86/pmc_atom.c
> > +++ b/drivers/platform/x86/pmc_atom.c
> > @@ -492,6 +492,7 @@ static int pmc_setup_dev(struct pci_dev *pdev, const struct pci_device_id *ent)
> > dev_warn(&pdev->dev, "platform clocks register failed: %d\n",
> > ret);
> >
> > + iounmap(pmc->regmap);
>
> This releases it on the success path so it will break the driver.

Yes. I should only deallocate it in the failure handling of
pm_setup_clks. Will modify it in the v2 version.


>
> regards,
> dan carpenter
>
> > pmc->init = true;
> > return ret;
> > }
> > --
> > 2.25.1