input: sensor: add check if regulator is valid before releasing it
Sensor regulator could be still invalid at the time of a system
suspend, this change is to avoid freeing NULL regulators under such
occasion.
Change-Id: Ia520b2516b43feaa3fbbbe30628cc47ee7fad96a
Signed-off-by: Wentao Xu <wentaox@codeaurora.org>
diff --git a/drivers/input/misc/lis3dh_acc.c b/drivers/input/misc/lis3dh_acc.c
index cc4ee9f..ea1b079 100644
--- a/drivers/input/misc/lis3dh_acc.c
+++ b/drivers/input/misc/lis3dh_acc.c
@@ -274,6 +274,7 @@
rc = PTR_ERR(lis3dh_acc_vreg[i].vreg);
pr_err("%s:regulator get failed rc=%d\n",
__func__, rc);
+ lis3dh_acc_vreg[i].vreg = NULL;
goto error_vdd;
}
@@ -287,6 +288,7 @@
pr_err("%s: set voltage failed rc=%d\n",
__func__, rc);
regulator_put(lis3dh_acc_vreg[i].vreg);
+ lis3dh_acc_vreg[i].vreg = NULL;
goto error_vdd;
}
}
@@ -302,6 +304,7 @@
lis3dh_acc_vreg[i].max_uV);
}
regulator_put(lis3dh_acc_vreg[i].vreg);
+ lis3dh_acc_vreg[i].vreg = NULL;
goto error_vdd;
}
}
@@ -312,12 +315,16 @@
error_vdd:
while (--i >= 0) {
- if (regulator_count_voltages(lis3dh_acc_vreg[i].vreg) > 0) {
- regulator_set_voltage(lis3dh_acc_vreg[i].vreg, 0,
- lis3dh_acc_vreg[i].max_uV);
+ if (!IS_ERR_OR_NULL(lis3dh_acc_vreg[i].vreg)) {
+ if (regulator_count_voltages(
+ lis3dh_acc_vreg[i].vreg) > 0) {
+ regulator_set_voltage(lis3dh_acc_vreg[i].vreg,
+ 0, lis3dh_acc_vreg[i].max_uV);
+ }
+ regulator_disable(lis3dh_acc_vreg[i].vreg);
+ regulator_put(lis3dh_acc_vreg[i].vreg);
+ lis3dh_acc_vreg[i].vreg = NULL;
}
- regulator_disable(lis3dh_acc_vreg[i].vreg);
- regulator_put(lis3dh_acc_vreg[i].vreg);
}
return rc;
}
diff --git a/drivers/input/misc/mpu3050.c b/drivers/input/misc/mpu3050.c
index db6f93c..6c64a57 100644
--- a/drivers/input/misc/mpu3050.c
+++ b/drivers/input/misc/mpu3050.c
@@ -184,6 +184,7 @@
rc = PTR_ERR(mpu_vreg[i].vreg);
pr_err("%s:regulator get failed rc=%d\n",
__func__, rc);
+ mpu_vreg[i].vreg = NULL;
goto error_vdd;
}
@@ -194,6 +195,7 @@
pr_err("%s:set_voltage failed rc=%d\n",
__func__, rc);
regulator_put(mpu_vreg[i].vreg);
+ mpu_vreg[i].vreg = NULL;
goto error_vdd;
}
}
@@ -210,6 +212,7 @@
0, mpu_vreg[i].max_uV);
}
regulator_put(mpu_vreg[i].vreg);
+ mpu_vreg[i].vreg = NULL;
goto error_vdd;
}
}
@@ -219,12 +222,16 @@
}
error_vdd:
while (--i >= 0) {
- if (regulator_count_voltages(mpu_vreg[i].vreg) > 0) {
- regulator_set_voltage(mpu_vreg[i].vreg, 0,
+ if (!IS_ERR_OR_NULL(mpu_vreg[i].vreg)) {
+ if (regulator_count_voltages(
+ mpu_vreg[i].vreg) > 0) {
+ regulator_set_voltage(mpu_vreg[i].vreg, 0,
mpu_vreg[i].max_uV);
+ }
+ regulator_disable(mpu_vreg[i].vreg);
+ regulator_put(mpu_vreg[i].vreg);
+ mpu_vreg[i].vreg = NULL;
}
- regulator_disable(mpu_vreg[i].vreg);
- regulator_put(mpu_vreg[i].vreg);
}
return rc;
}