All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Hi655x: mfd/pmic: regulator: Correct dependencies
@ 2017-03-21  4:53 Jeremy Linton
  2017-03-21  4:53 ` [PATCH 1/2] mfd: hi655x: Reference required regulator driver Jeremy Linton
  2017-03-21  4:53 ` [PATCH 2/2] regulator: hi655x: Bump parent pmic module use count Jeremy Linton
  0 siblings, 2 replies; 7+ messages in thread
From: Jeremy Linton @ 2017-03-21  4:53 UTC (permalink / raw)
  To: linux-kernel; +Cc: broonie, lgirdwood, puck.chen, lee.jones, Jeremy Linton

In an environment where the hi655x pmic is being built as a 
standalone module, it fails to automatically load resulting
in boot failures, machine hangs, etc. First we correct this
by setting an appropriate module dependency. Then we bump the
module use count on the mfd/pmic driver so that it cannot be
unloaded when in use. Again this avoids machine crashes.

Jeremy Linton (2):
  mfd: hi655x: Reference required regulator driver
  regulator: hi655x: Bump parent pmic module use count

 drivers/mfd/hi655x-pmic.c            |  1 +
 drivers/regulator/hi655x-regulator.c | 26 ++++++++++++++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

-- 
2.10.2

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

* [PATCH 1/2] mfd: hi655x: Reference required regulator driver
  2017-03-21  4:53 [PATCH 0/2] Hi655x: mfd/pmic: regulator: Correct dependencies Jeremy Linton
@ 2017-03-21  4:53 ` Jeremy Linton
  2017-03-23 16:31   ` Lee Jones
  2017-03-21  4:53 ` [PATCH 2/2] regulator: hi655x: Bump parent pmic module use count Jeremy Linton
  1 sibling, 1 reply; 7+ messages in thread
From: Jeremy Linton @ 2017-03-21  4:53 UTC (permalink / raw)
  To: linux-kernel; +Cc: broonie, lgirdwood, puck.chen, lee.jones, Jeremy Linton

The hisi pmic requires an independent regulator driver to be
loaded so that devices dependent on the pmic/regulator are
started properly. Currently there is only a single compatible
regulator driver in the tree, so reference it with a module soft
dependency so that modprobe loads it whenever the hisi pmic
driver is loaded.

Signed-off-by: Jeremy Linton <lintonrjeremy@gmail.com>
---
 drivers/mfd/hi655x-pmic.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mfd/hi655x-pmic.c b/drivers/mfd/hi655x-pmic.c
index ba706ad..56e027d 100644
--- a/drivers/mfd/hi655x-pmic.c
+++ b/drivers/mfd/hi655x-pmic.c
@@ -184,3 +184,4 @@ module_platform_driver(hi655x_pmic_driver);
 MODULE_AUTHOR("Chen Feng <puck.chen@hisilicon.com>");
 MODULE_DESCRIPTION("Hisilicon hi655x PMIC driver");
 MODULE_LICENSE("GPL v2");
+MODULE_SOFTDEP("post: hi655x-regulator");
-- 
2.10.2

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

* [PATCH 2/2] regulator: hi655x: Bump parent pmic module use count
  2017-03-21  4:53 [PATCH 0/2] Hi655x: mfd/pmic: regulator: Correct dependencies Jeremy Linton
  2017-03-21  4:53 ` [PATCH 1/2] mfd: hi655x: Reference required regulator driver Jeremy Linton
@ 2017-03-21  4:53 ` Jeremy Linton
  2017-03-21 11:08   ` Mark Brown
  1 sibling, 1 reply; 7+ messages in thread
From: Jeremy Linton @ 2017-03-21  4:53 UTC (permalink / raw)
  To: linux-kernel; +Cc: broonie, lgirdwood, puck.chen, lee.jones, Jeremy Linton

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@gmail.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

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

* Re: [PATCH 2/2] regulator: hi655x: Bump parent pmic module use count
  2017-03-21  4:53 ` [PATCH 2/2] regulator: hi655x: Bump parent pmic module use count Jeremy Linton
@ 2017-03-21 11:08   ` Mark Brown
  2017-03-21 20:23     ` Jeremy Linton
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2017-03-21 11:08 UTC (permalink / raw)
  To: Jeremy Linton; +Cc: linux-kernel, lgirdwood, puck.chen, lee.jones

[-- Attachment #1: Type: text/plain, Size: 307 bytes --]

On Mon, Mar 20, 2017 at 11:53:41PM -0500, Jeremy Linton wrote:

> +	if (!try_module_get(parent->driver->owner)) {
> +		dev_err(&pdev->dev, "unable to get parent module\n");
> +		return -ENODEV;
> +	}
> +

If this makes sense it should be being done in the driver core, not open
coded in individual drivers.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 2/2] regulator: hi655x: Bump parent pmic module use count
  2017-03-21 11:08   ` Mark Brown
@ 2017-03-21 20:23     ` Jeremy Linton
  2017-03-22 11:43       ` Mark Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Jeremy Linton @ 2017-03-21 20:23 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel, Liam Girdwood, puck.chen, lee.jones

Hi,

On Tue, Mar 21, 2017 at 6:08 AM, Mark Brown <broonie@kernel.org> wrote:
> On Mon, Mar 20, 2017 at 11:53:41PM -0500, Jeremy Linton wrote:
>
>> +     if (!try_module_get(parent->driver->owner)) {
>> +             dev_err(&pdev->dev, "unable to get parent module\n");
>> +             return -ENODEV;
>> +     }
>> +
>
> If this makes sense it should be being done in the driver core, not open
> coded in individual drivers.

Well, this is only really required for the drivers that are oddly
split like these two. It doesn't appear to be necessary for say the
max77* regulators which consume the pmic node, and register
regulators.

I don't understand why it was done this way, and I'm not sure that
this driver shouldn't be triggered based on 'hi655x-regulator' device
(which is being registered by the hi655x-pmic/mfd driver). The only
thing I know for sure, is that its broken in its current
configuration.

Initially I tried a variation on the previous patch, which instead of
trying to double consume the hi655x-pmic platform device, it tried to
consume the hi655x-regulator, but for whatever reason that didn't
work. At least part of the problem with that solution is that depmod
(and therefore tools which are building the initrd) don't understand
the driver relationships here, so simply saying that dw_mmc_k3 is
required for boot doesn't result in the correct set of drivers being
put in the initrd, as one would expect if there were simple symbol
dependencies.

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

* Re: [PATCH 2/2] regulator: hi655x: Bump parent pmic module use count
  2017-03-21 20:23     ` Jeremy Linton
@ 2017-03-22 11:43       ` Mark Brown
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2017-03-22 11:43 UTC (permalink / raw)
  To: Jeremy Linton; +Cc: linux-kernel, Liam Girdwood, puck.chen, lee.jones

[-- Attachment #1: Type: text/plain, Size: 392 bytes --]

On Tue, Mar 21, 2017 at 03:23:50PM -0500, Jeremy Linton wrote:

> I don't understand why it was done this way, and I'm not sure that
> this driver shouldn't be triggered based on 'hi655x-regulator' device
> (which is being registered by the hi655x-pmic/mfd driver). The only
> thing I know for sure, is that its broken in its current
> configuration.

That's exactly what it should be doing.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 1/2] mfd: hi655x: Reference required regulator driver
  2017-03-21  4:53 ` [PATCH 1/2] mfd: hi655x: Reference required regulator driver Jeremy Linton
@ 2017-03-23 16:31   ` Lee Jones
  0 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2017-03-23 16:31 UTC (permalink / raw)
  To: Jeremy Linton; +Cc: linux-kernel, broonie, lgirdwood, puck.chen

On Mon, 20 Mar 2017, Jeremy Linton wrote:

> The hisi pmic requires an independent regulator driver to be
> loaded so that devices dependent on the pmic/regulator are
> started properly. Currently there is only a single compatible
> regulator driver in the tree, so reference it with a module soft
> dependency so that modprobe loads it whenever the hisi pmic
> driver is loaded.

This is a new one on my, but it sounds okay.

OOI, what happens when there are lots of compatible drivers?

> Signed-off-by: Jeremy Linton <lintonrjeremy@gmail.com>
> ---
>  drivers/mfd/hi655x-pmic.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/mfd/hi655x-pmic.c b/drivers/mfd/hi655x-pmic.c
> index ba706ad..56e027d 100644
> --- a/drivers/mfd/hi655x-pmic.c
> +++ b/drivers/mfd/hi655x-pmic.c
> @@ -184,3 +184,4 @@ module_platform_driver(hi655x_pmic_driver);
>  MODULE_AUTHOR("Chen Feng <puck.chen@hisilicon.com>");
>  MODULE_DESCRIPTION("Hisilicon hi655x PMIC driver");
>  MODULE_LICENSE("GPL v2");
> +MODULE_SOFTDEP("post: hi655x-regulator");

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

end of thread, other threads:[~2017-03-23 16:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-21  4:53 [PATCH 0/2] Hi655x: mfd/pmic: regulator: Correct dependencies Jeremy Linton
2017-03-21  4:53 ` [PATCH 1/2] mfd: hi655x: Reference required regulator driver Jeremy Linton
2017-03-23 16:31   ` Lee Jones
2017-03-21  4:53 ` [PATCH 2/2] regulator: hi655x: Bump parent pmic module use count Jeremy Linton
2017-03-21 11:08   ` Mark Brown
2017-03-21 20:23     ` Jeremy Linton
2017-03-22 11:43       ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.