浏览代码

regulator: anatop: make sure regulator name is properly defined

For anatop regulator we must have a name accordingly. Make sure the name
is properly checked before using it to avoid a possible kernel NULL
point crash.

Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Dong Aisheng 8 年之前
父节点
当前提交
4af5924c02
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 5 2
      drivers/regulator/anatop-regulator.c

+ 5 - 2
drivers/regulator/anatop-regulator.c

@@ -198,6 +198,10 @@ static int anatop_regulator_probe(struct platform_device *pdev)
 	rdesc->owner = THIS_MODULE;
 	rdesc->owner = THIS_MODULE;
 
 
 	of_property_read_string(np, "regulator-name", &rdesc->name);
 	of_property_read_string(np, "regulator-name", &rdesc->name);
+	if (!rdesc->name) {
+		dev_err(dev, "failed to get a regulator-name\n");
+		return -EINVAL;
+	}
 
 
 	initdata = of_get_regulator_init_data(dev, np, rdesc);
 	initdata = of_get_regulator_init_data(dev, np, rdesc);
 	if (!initdata)
 	if (!initdata)
@@ -300,8 +304,7 @@ static int anatop_regulator_probe(struct platform_device *pdev)
 			sreg->sel = 22;
 			sreg->sel = 22;
 
 
 		/* set the default voltage of the pcie phy to be 1.100v */
 		/* set the default voltage of the pcie phy to be 1.100v */
-		if (!sreg->sel && rdesc->name &&
-		    !strcmp(rdesc->name, "vddpcie"))
+		if (!sreg->sel && !strcmp(rdesc->name, "vddpcie"))
 			sreg->sel = 0x10;
 			sreg->sel = 0x10;
 
 
 		if (!sreg->bypass && !sreg->sel) {
 		if (!sreg->bypass && !sreg->sel) {