Skip to contentSkip to conversation

driver: pmc_atom: free pmc->regmap when pmc_setup_clks fails

PATCH NAK Dongliang Mu 2 participants 5 messages Dec 5, 2021 – Dec 6, 2021 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 driver: pmc_atom: free pmc->regmap when pmc_setup_clks fails

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")
---
 drivers/platform/x86/pmc_atom.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/platform/x86/pmc_atom.c +3 -1
index a9d2a4b98e57..e338c1572237 100644
@@ -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;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 10 lines · Dongliang Mu

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")

---

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

...

drivers/platform/x86/pmc_atom.c static int pmc_setup_dev(struct pci_dev *pdev, const struct pci_device_id *ent) · line 494

Quoted 6 lines
drivers/platform/x86/pmc_atom.c +2 -1
 	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);
Quoted 1 line
drivers/platform/x86/pmc_atom.c +1 -0
+	}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 25 lines · Andy Shevchenko
Quoted 10 lines · Dongliang Mu

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")

---

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

...

drivers/platform/x86/pmc_atom.c static int pmc_setup_dev(struct pci_dev *pdev, const struct pci_device_id *ent) · line 494

Quoted 6 lines
drivers/platform/x86/pmc_atom.c +2 -1
 	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

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

drivers/platform/x86/pmc_atom.c static int pmc_setup_dev(struct pci_dev *pdev, const struct pci_device_id *ent) · line 495

Quoted 1 line
drivers/platform/x86/pmc_atom.c +1 -0
+	}

Also, what about cleaning up debugfs?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
In reply to Andy Shevchenko
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Dongliang Mu

Smatch reports:

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

Quoted 7 lines
Quoted 5 lines

Fix this by deallocating pm->regmap when pmc_setup_clks fails.

Fixes 282a4e4ce5f9("platform/x86: Enable Atom PMC platform clocks")

---

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.

Quoted 21 lines

...

drivers/platform/x86/pmc_atom.c static int pmc_setup_dev(struct pci_dev *pdev, const struct pci_device_id *ent) · line 494

Quoted 6 lines
      ret = pmc_setup_clks(pdev, pmc->regmap, data);
drivers/platform/x86/pmc_atom.c +2 -1
-     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);
Quoted 1 line

+ }

--
With Best Regards,
Andy Shevchenko

#4 lore raw
In reply to Dongliang Mu
Quoted 9 lines · Dongliang Mu

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")

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.

Signature · 2 lines
With Best Regards,
Andy Shevchenko