lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20170321045341.4833-3-lintonrjeremy@gmail.com>
Date:   Mon, 20 Mar 2017 23:53:41 -0500
From:   Jeremy Linton <lintonrjeremy@...il.com>
To:     linux-kernel@...r.kernel.org
Cc:     broonie@...nel.org, lgirdwood@...il.com, puck.chen@...ilicon.com,
        lee.jones@...aro.org, Jeremy Linton <lintonrjeremy@...il.com>
Subject: [PATCH 2/2] regulator: hi655x: Bump parent pmic module use count

The hi655x-regulator driver depends on the parent pmic/mfc
device driver but doesn't increase its use count. This results
in system crashes if the parent module is unloaded while the
regulators are still in use. Add explicit module get/put
calls to keep the parent from being unloaded.

Signed-off-by: Jeremy Linton <lintonrjeremy@...il.com>
---
 drivers/regulator/hi655x-regulator.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/hi655x-regulator.c b/drivers/regulator/hi655x-regulator.c
index aca1846..5a461d4 100644
--- a/drivers/regulator/hi655x-regulator.c
+++ b/drivers/regulator/hi655x-regulator.c
@@ -185,16 +185,29 @@ static int hi655x_regulator_probe(struct platform_device *pdev)
 	struct hi655x_pmic *pmic;
 	struct regulator_config config = { };
 	struct regulator_dev *rdev;
+	struct device *parent = pdev->dev.parent;
 
-	pmic = dev_get_drvdata(pdev->dev.parent);
+	if (!parent) {
+		dev_err(&pdev->dev, "no regulator parent node\n");
+		return -ENODEV;
+	}
+
+	pmic = dev_get_drvdata(parent);
 	if (!pmic) {
 		dev_err(&pdev->dev, "no pmic in the regulator parent node\n");
 		return -ENODEV;
 	}
 
+	if (!try_module_get(parent->driver->owner)) {
+		dev_err(&pdev->dev, "unable to get parent module\n");
+		return -ENODEV;
+	}
+
 	regulator = devm_kzalloc(&pdev->dev, sizeof(*regulator), GFP_KERNEL);
-	if (!regulator)
+	if (!regulator)	{
+		module_put(parent->driver->owner);
 		return -ENOMEM;
+	}
 
 	platform_set_drvdata(pdev, regulator);
 
@@ -214,11 +227,20 @@ static int hi655x_regulator_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static int hi655x_regulator_remove(struct platform_device *pdev)
+{
+	struct device *parent = pdev->dev.parent;
+
+	module_put(parent->driver->owner);
+	return 0;
+}
+
 static struct platform_driver hi655x_regulator_driver = {
 	.driver = {
 		.name	= "hi655x-regulator",
 	},
 	.probe	= hi655x_regulator_probe,
+	.remove = hi655x_regulator_remove
 };
 module_platform_driver(hi655x_regulator_driver);
 
-- 
2.10.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ