regulator: palmas: fix pdata ptr not be updated after it has been allocated
PATCH 1/1 regulator: palmas: fix pdata ptr not be updated after it has been allocated
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.
--- drivers/regulator/palmas-regulator.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/regulator/palmas-regulator.c +2 -0
@@ -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 ;
Signature · 1 line
1.7.9.5
Mark Brown
maintainerdrivers/regulator/palmas-regulator.c static int palmas_regulators_probe(struct platform_device *pdev) · line 1031
Quoted 2 lines · Rhyland Klein
drivers/regulator/palmas-regulator.c +2
-0+/* 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.
Quoted 11 lines · Mark Brown
* PGP Signed by an unknown key
drivers/regulator/palmas-regulator.c static int palmas_regulators_probe(struct platform_device *pdev) · line 1031
Quoted 2 lines · Rhyland Klein
drivers/regulator/palmas-regulator.c +2
-0+/* 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_datapointer, 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
Quoted 4 lines
* Unknown Key
*0x7EA229BD
Signature · 1 line
nvpublic
Quoted 8 lines · Rhyland Klein
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().