public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] driver: pmc_atom: free pmc->regmap when pmc_setup_clks fails
@ 2021-12-05  8:44 Dongliang Mu
  2021-12-06 14:00 ` Andy Shevchenko
  2021-12-06 14:05 ` Andy Shevchenko
  0 siblings, 2 replies; 5+ messages in thread
From: Dongliang Mu @ 2021-12-05  8:44 UTC (permalink / raw)
  To: Hans de Goede, Mark Gross, Stephen Boyd, Irina Tirdea,
	Pierre-Louis Bossart, Andy Shevchenko
  Cc: Dongliang Mu, platform-driver-x86, linux-kernel

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 when pmc_setup_clks fails.

Fixes: 282a4e4ce5f9("platform/x86: Enable Atom PMC platform clocks")
Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
---
 drivers/platform/x86/pmc_atom.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/pmc_atom.c b/drivers/platform/x86/pmc_atom.c
index a9d2a4b98e57..e338c1572237 100644
--- a/drivers/platform/x86/pmc_atom.c
+++ b/drivers/platform/x86/pmc_atom.c
@@ -488,9 +488,11 @@ static int pmc_setup_dev(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	/* Register platform clocks - PMC_PLT_CLK [0..5] */
 	ret = pmc_setup_clks(pdev, pmc->regmap, data);
-	if (ret)
+	if (ret) {
+		iounmap(pmc->regmap);
 		dev_warn(&pdev->dev, "platform clocks register failed: %d\n",
 			 ret);
+	}
 
 	pmc->init = true;
 	return ret;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] driver: pmc_atom: free pmc->regmap when pmc_setup_clks fails
  2021-12-05  8:44 [PATCH v2] driver: pmc_atom: free pmc->regmap when pmc_setup_clks fails Dongliang Mu
@ 2021-12-06 14:00 ` Andy Shevchenko
  2021-12-06 14:01   ` Andy Shevchenko
  2021-12-06 14:09   ` Dongliang Mu
  2021-12-06 14:05 ` Andy Shevchenko
  1 sibling, 2 replies; 5+ messages in thread
From: Andy Shevchenko @ 2021-12-06 14:00 UTC (permalink / raw)
  To: Dongliang Mu
  Cc: Hans de Goede, Mark Gross, Stephen Boyd, Irina Tirdea,
	Pierre-Louis Bossart, platform-driver-x86, linux-kernel

On Sun, Dec 05, 2021 at 04:44:19PM +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 when pmc_setup_clks fails.
> 
> Fixes: 282a4e4ce5f9("platform/x86: Enable Atom PMC platform clocks")
> Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
> ---

It says v2 in the subject, what is in v2 exactly in comparison to v1?

...

>  	ret = pmc_setup_clks(pdev, pmc->regmap, data);
> -	if (ret)
> +	if (ret) {
> +		iounmap(pmc->regmap);
>  		dev_warn(&pdev->dev, "platform clocks register failed: %d\n",
>  			 ret);

In this case it makes sense to move to

		dev_err(&pdev->dev, "platform clocks register failed: %d\n", ret);

> +	}

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] driver: pmc_atom: free pmc->regmap when pmc_setup_clks fails
  2021-12-06 14:00 ` Andy Shevchenko
@ 2021-12-06 14:01   ` Andy Shevchenko
  2021-12-06 14:09   ` Dongliang Mu
  1 sibling, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2021-12-06 14:01 UTC (permalink / raw)
  To: Dongliang Mu
  Cc: Hans de Goede, Mark Gross, Stephen Boyd, Irina Tirdea,
	Pierre-Louis Bossart, platform-driver-x86, linux-kernel

On Mon, Dec 06, 2021 at 04:00:13PM +0200, Andy Shevchenko wrote:
> On Sun, Dec 05, 2021 at 04:44:19PM +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 when pmc_setup_clks fails.
> > 
> > Fixes: 282a4e4ce5f9("platform/x86: Enable Atom PMC platform clocks")
> > Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
> > ---
> 
> It says v2 in the subject, what is in v2 exactly in comparison to v1?
> 
> ...
> 
> >  	ret = pmc_setup_clks(pdev, pmc->regmap, data);
> > -	if (ret)
> > +	if (ret) {
> > +		iounmap(pmc->regmap);
> >  		dev_warn(&pdev->dev, "platform clocks register failed: %d\n",
> >  			 ret);
> 
> In this case it makes sense to move to
> 
> 		dev_err(&pdev->dev, "platform clocks register failed: %d\n", ret);
> 
> > +	}

Also, what about cleaning up debugfs?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] driver: pmc_atom: free pmc->regmap when pmc_setup_clks fails
  2021-12-05  8:44 [PATCH v2] driver: pmc_atom: free pmc->regmap when pmc_setup_clks fails Dongliang Mu
  2021-12-06 14:00 ` Andy Shevchenko
@ 2021-12-06 14:05 ` Andy Shevchenko
  1 sibling, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2021-12-06 14:05 UTC (permalink / raw)
  To: Dongliang Mu
  Cc: Hans de Goede, Mark Gross, Stephen Boyd, Irina Tirdea,
	Pierre-Louis Bossart, platform-driver-x86, linux-kernel

On Sun, Dec 05, 2021 at 04:44:19PM +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 when pmc_setup_clks fails.
> 
> Fixes: 282a4e4ce5f9("platform/x86: Enable Atom PMC platform clocks")
> Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>

Okay, this driver is two in one, i.e. library for PMC access and some other
stuff. When you do iounmap() you ruin library routines with that.

So, my other comments are fine in general, but not applicable here.

NAK.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] driver: pmc_atom: free pmc->regmap when pmc_setup_clks fails
  2021-12-06 14:00 ` Andy Shevchenko
  2021-12-06 14:01   ` Andy Shevchenko
@ 2021-12-06 14:09   ` Dongliang Mu
  1 sibling, 0 replies; 5+ messages in thread
From: Dongliang Mu @ 2021-12-06 14:09 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Hans de Goede, Mark Gross, Stephen Boyd, Irina Tirdea,
	Pierre-Louis Bossart, platform-driver-x86, linux-kernel

On Mon, Dec 6, 2021 at 10:01 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Sun, Dec 05, 2021 at 04:44:19PM +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 when pmc_setup_clks fails.
> >
> > Fixes: 282a4e4ce5f9("platform/x86: Enable Atom PMC platform clocks")
> > Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
> > ---
>
> It says v2 in the subject, what is in v2 exactly in comparison to v1?

Sorry to forget to add this information

v1->v2: move iounmap(pmc->regmap); from success path to the error handling code.

>
> ...
>
> >       ret = pmc_setup_clks(pdev, pmc->regmap, data);
> > -     if (ret)
> > +     if (ret) {
> > +             iounmap(pmc->regmap);
> >               dev_warn(&pdev->dev, "platform clocks register failed: %d\n",
> >                        ret);
>
> In this case it makes sense to move to
>
>                 dev_err(&pdev->dev, "platform clocks register failed: %d\n", ret);
>
> > +     }
>
> --
> With Best Regards,
> Andy Shevchenko
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-06 14:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-05  8:44 [PATCH v2] driver: pmc_atom: free pmc->regmap when pmc_setup_clks fails Dongliang Mu
2021-12-06 14:00 ` Andy Shevchenko
2021-12-06 14:01   ` Andy Shevchenko
2021-12-06 14:09   ` Dongliang Mu
2021-12-06 14:05 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox