Patchwork regulator: palmas: fix pdata ptr not be updated after it has been allocated

login
register
mail settings
Submitter Rhyland Klein
Date July 24, 2013, 4:28 p.m.
Message ID <1374683282-17517-1-git-send-email-rklein@nvidia.com>
Download mbox | patch
Permalink /patch/261458/
State Not Applicable, archived
Headers show

Comments

Rhyland Klein - July 24, 2013, 4:28 p.m.
The pmic platform data wasn't updated to dev.platform_data after it had
been allocated. That can cause the driver crash when using it.
This patch fixes the issue.

We need to update the pdata pointer at the end of probe because if
probe should fail for some reason, for instance if an in-supply
isn't ready yet, then probe will defer. However, the pdata is allocated
with devm, and so is freed when probe is deferred.

Based on work by Joseph Lo.

Cc: Joseph Lo <josephl@nvidia.com>
Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 drivers/regulator/palmas-regulator.c |    2 ++
 1 file changed, 2 insertions(+)
Mark Brown - July 24, 2013, 5:02 p.m.
On Wed, Jul 24, 2013 at 12:28:02PM -0400, Rhyland Klein wrote:

> +	/* Store the pdata pointer after everything else passes */
> +	pdev->dev.platform_data = pdata;

No, this is bad - the driver should not be modifying the platform_data
pointer, it's owned by the thing that created the device.  If the
platform data needs to be modified it should be copied somewhere in the
driver data.
Rhyland Klein - July 24, 2013, 5:09 p.m.
On 7/24/2013 1:02 PM, Mark Brown wrote:
> * PGP Signed by an unknown key
> 
> On Wed, Jul 24, 2013 at 12:28:02PM -0400, Rhyland Klein wrote:
> 
>> +	/* Store the pdata pointer after everything else passes */
>> +	pdev->dev.platform_data = pdata;
> 
> No, this is bad - the driver should not be modifying the platform_data
> pointer, it's owned by the thing that created the device.  If the
> platform data needs to be modified it should be copied somewhere in the
> driver data.

Alright, thanks.

-rhyland

> 
> * Unknown Key
> * 0x7EA229BD
>
Stephen Warren - July 24, 2013, 5:20 p.m.
On 07/24/2013 09:28 AM, Rhyland Klein wrote:
> The pmic platform data wasn't updated to dev.platform_data after it had
> been allocated. That can cause the driver crash when using it.
> This patch fixes the issue.
> 
> We need to update the pdata pointer at the end of probe because if
> probe should fail for some reason, for instance if an in-supply
> isn't ready yet, then probe will defer. However, the pdata is allocated
> with devm, and so is freed when probe is deferred.

This looks wrong. If the module is removed and re-probed, then the pdata
pointer will still be set to a stale (free'd) value and hence not
re-allocated, but it will still be used.

This function shouldn't save the pdata in dev.platform_data, but rather
some data structure that has the same scope as probe()..remove(), for
example as a field in the drvdata struct, as set by dev_set_drvdata().
--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index d0c8785..e11b762 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -1027,6 +1027,8 @@  static int palmas_regulators_probe(struct platform_device *pdev)
 		}
 	}
 
+	/* Store the pdata pointer after everything else passes */
+	pdev->dev.platform_data = pdata;
 
 	return 0;