Skip to contentSkip to conversation

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

PATCH In review Rhyland Klein 3 participants 4 messages Jul 24, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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
index d0c8785..e11b762 100644
@@ -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
maintainer
#1 lore raw

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_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.

#2 lore raw
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_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

Quoted 4 lines

* Unknown Key
* 0x7EA229BD

Signature · 1 line
nvpublic
#3 lore raw
In reply to Rhyland Klein
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().