Skip to contentSkip to conversation

regulator: Avoid potential NULL dereference in reg_fixed_voltage_probe()

PATCH Applied Axel Lin 2 participants 2 messages Nov 27, 2011 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH v2 1/1 regulator: Avoid potential NULL dereference in reg_fixed_voltage_probe()

of_get_fixed_voltage_config() may return NULL, return -ENOMEM in this case so we don't dereference NULL pointer.

---
 drivers/regulator/fixed.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
drivers/regulator/fixed.c +6 -1
index 6828dce..72abbf5 100644
@@ -163,12 +163,17 @@ static struct regulator_ops fixed_voltage_ops = {
 
 static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
 {
-	struct fixed_voltage_config *config = pdev->dev.platform_data;
+	struct fixed_voltage_config *config;
 	struct fixed_voltage_data *drvdata;
 	int ret;
 
 	if (pdev->dev.of_node)
 		config = of_get_fixed_voltage_config(&pdev->dev);
+	else
+		config = pdev->dev.platform_data;
+
+	if (!config)
+		return -ENOMEM;
 
 	drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL);
 	if (drvdata == NULL) {
Signature · 1 line
1.7.5.4
Applied
#1 lore raw
Quoted 4 lines · Axel Lin

of_get_fixed_voltage_config() may return NULL, return -ENOMEM in this case so we don't dereference NULL pointer.

Applied, thanks.