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;
}