input: touchscreen: cyttsp5: release resources when no touch
When no touch is plugged in, release resources correctly.
Change-Id: Ie527a86bbb7707b6744c872da2f39623ba7d600b
Signed-off-by: Fei Mao <feim1@codeaurora.org>
diff --git a/drivers/input/touchscreen/cyttsp5/cyttsp5_core.c b/drivers/input/touchscreen/cyttsp5/cyttsp5_core.c
index 64cc510..119ac45 100644
--- a/drivers/input/touchscreen/cyttsp5/cyttsp5_core.c
+++ b/drivers/input/touchscreen/cyttsp5/cyttsp5_core.c
@@ -306,8 +306,12 @@
for (i = 0; i < cd->num_hid_reports; i++) {
report = cd->hid_reports[i];
- for (j = 0; j < report->num_fields; j++)
+ if (!report)
+ continue;
+ for (j = 0; j < report->num_fields; j++) {
kfree(report->fields[j]);
+ report->fields[j] = NULL;
+ }
kfree(report);
cd->hid_reports[i] = NULL;
}
@@ -4633,7 +4637,7 @@
rc = cyttsp5_check_and_deassert_int(cd);
- if (reset || retry != CY_CORE_STARTUP_RETRY_COUNT) {
+ if (rc || retry != CY_CORE_STARTUP_RETRY_COUNT) {
/* reset hardware */
rc = cyttsp5_reset_and_wait(cd);
if (rc < 0) {
@@ -4773,12 +4777,11 @@
/* attention startup */
call_atten_cb(cd, CY_ATTEN_STARTUP, 0);
+ cyttsp5_start_wd_timer(cd);
exit:
if (!rc)
cd->startup_retry_count = 0;
- cyttsp5_start_wd_timer(cd);
-
if (!detected)
rc = -ENODEV;
@@ -4806,6 +4809,10 @@
rc = cyttsp5_startup_(cd, reset);
+ /* Wake the waiters for end of startup */
+ if (!rc)
+ wake_up(&cd->wait_q);
+
if (release_exclusive(cd, cd->dev) < 0)
/* Don't return fail code, mode is already changed. */
dev_err(cd->dev, "%s: fail to release exclusive\n", __func__);
@@ -4818,9 +4825,6 @@
cd->startup_state = STARTUP_NONE;
mutex_unlock(&cd->system_lock);
- /* Wake the waiters for end of startup */
- wake_up(&cd->wait_q);
-
return rc;
}
@@ -5759,6 +5763,8 @@
struct cyttsp5_core_commands *cyttsp5_get_commands(void)
{
+ if (!is_cyttsp5_probe_success)
+ return NULL;
return &_cyttsp5_core_commands;
}
EXPORT_SYMBOL_GPL(cyttsp5_get_commands);
@@ -6436,12 +6442,12 @@
cyttsp5_btn_release(dev);
error_startup_mt:
cyttsp5_mt_release(dev);
+ cyttsp5_free_si_ptrs(cd);
error_startup:
pm_runtime_disable(dev);
device_init_wakeup(dev, 0);
cancel_work_sync(&cd->startup_work);
cyttsp5_stop_wd_timer(cd);
- cyttsp5_free_si_ptrs(cd);
remove_sysfs_interfaces(dev);
error_attr_create:
free_irq(cd->irq, cd);
@@ -6453,7 +6459,7 @@
cyttsp5_del_core(dev);
dev_set_drvdata(dev, NULL);
error_power:
- kfree(cd);
+ cyttsp5_power_init(cd, false);
error_alloc_data:
error_no_pdata:
dev_err(dev, "%s failed.\n", __func__);