From 322492c19eb35aa10308736090de5c898acead64 Mon Sep 17 00:00:00 2001 From: haojl2 Date: Wed, 18 Jul 2018 15:50:55 +0800 Subject: [PATCH] himax_mmi: Free gpio if request failed If gpio init failed in probe routine, already inited gpio should be free. Change-Id: I5522be9b763eb0ae2d7d084a9be805219e3f0458 Signed-off-by: haojl2 Reviewed-on: https://gerrit.mot.com/1211145 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Jianqi Yang Submit-Approved: Jira Key --- .../touchscreen/himax_mmi/himax_common.c | 7 +++- .../touchscreen/himax_mmi/himax_platform.c | 39 ++++++++++++------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/drivers/input/touchscreen/himax_mmi/himax_common.c b/drivers/input/touchscreen/himax_mmi/himax_common.c index 2eac5ec0b9bf..df300d93d00d 100644 --- a/drivers/input/touchscreen/himax_mmi/himax_common.c +++ b/drivers/input/touchscreen/himax_mmi/himax_common.c @@ -1767,7 +1767,11 @@ int himax_chip_common_probe(struct i2c_client *client, const struct i2c_device_i ts->rst_gpio = pdata->gpio_reset; #endif - himax_gpio_power_config(ts->client, pdata); + if (himax_gpio_power_config(ts->client, pdata) < 0) + { + I(" GPIO and power config failed\n"); + goto err_gpio_power_config_failed; + } #ifndef CONFIG_OF if (pdata->power) @@ -2099,6 +2103,7 @@ err_ic_package_failed: err_power_failed: #endif +err_gpio_power_config_failed: err_alloc_dt_pdata_failed: kfree(hx_touch_data); err_alloc_touch_data_failed: diff --git a/drivers/input/touchscreen/himax_mmi/himax_platform.c b/drivers/input/touchscreen/himax_mmi/himax_platform.c index a045ccf356bb..e87cc568de9d 100644 --- a/drivers/input/touchscreen/himax_mmi/himax_platform.c +++ b/drivers/input/touchscreen/himax_mmi/himax_platform.c @@ -493,13 +493,6 @@ int himax_gpio_power_config(struct i2c_client *client,struct himax_i2c_platform_ E("%s: request reset pin failed\n", __func__); return error; } - error = gpio_direction_output(pdata->gpio_reset, 0); - if (error) - { - E("unable to set direction for gpio [%d]\n", - pdata->gpio_reset); - return error; - } } #endif if (pdata->gpio_3v3_en >= 0) @@ -508,7 +501,7 @@ int himax_gpio_power_config(struct i2c_client *client,struct himax_i2c_platform_ if (error < 0) { E("%s: request 3v3_en pin failed\n", __func__); - return error; + goto err_3v3_en_request; } gpio_direction_output(pdata->gpio_3v3_en, 1); I("3v3_en pin =%d\n", gpio_get_value(pdata->gpio_3v3_en)); @@ -520,36 +513,56 @@ int himax_gpio_power_config(struct i2c_client *client,struct himax_i2c_platform_ if (error) { E("unable to request gpio [%d]\n",pdata->gpio_irq); - return error; + goto err_irq_request; } error = gpio_direction_input(pdata->gpio_irq); if (error) { E("unable to set direction for gpio [%d]\n",pdata->gpio_irq); - return error; + goto err_irq_set_direction; } client->irq = gpio_to_irq(pdata->gpio_irq); } else { E("irq gpio not provided\n"); - return error; + goto err_irq_request; } - msleep(20); #ifdef HX_RST_PIN_FUNC if (pdata->gpio_reset >= 0) { + error = gpio_direction_output(pdata->gpio_reset, 0); + if (error) + { + E("unable to set direction for gpio [%d]\n", + pdata->gpio_reset); + goto err_rst_set_value; + } + msleep(20); error = gpio_direction_output(pdata->gpio_reset, 1); if (error) { E("unable to set direction for gpio [%d]\n", pdata->gpio_reset); - return error; + goto err_rst_set_value; } } #endif + return 0; +#ifdef HX_RST_PIN_FUNC +err_rst_set_value: +#endif +err_irq_set_direction: + if (gpio_is_valid(pdata->gpio_irq)) + gpio_free(pdata->gpio_irq); +err_irq_request: + if (gpio_is_valid(pdata->gpio_3v3_en)) + gpio_free(pdata->gpio_3v3_en); +err_3v3_en_request: + if (gpio_is_valid(pdata->gpio_reset)) + gpio_free(pdata->gpio_reset); return error; }