Pārlūkot izejas kodu

touch: exit in probe

Adjust exit labels to avoid the use-after-free issue.

Change-Id: I46368c80014aa3cbb680cf6e9967e20e188c1340
Signed-off-by: Srikanth Katteboina <[email protected]>
Srikanth Katteboina 2 gadi atpakaļ
vecāks
revīzija
dedef8c90d
1 mainītis faili ar 21 papildinājumiem un 16 dzēšanām
  1. 21 16
      raydium/raydium_driver.c

+ 21 - 16
raydium/raydium_driver.c

@@ -1867,13 +1867,15 @@ static int raydium_get_regulator(struct raydium_ts_data *cd, bool get)
 
 regulator_put:
 #ifdef VDD_ANALOG_ENABLE
-	if (cd->vdd) {
+	if (!IS_ERR(cd->vdd)) {
+		dev_err(&cd->client->dev, "Regulator put vdd\n");
 		regulator_put(cd->vdd);
 		cd->vdd = NULL;
 	}
 #endif
 
-	if (cd->vcc_i2c) {
+	if (!IS_ERR(cd->vcc_i2c)) {
+		dev_err(&cd->client->dev, "Regulator put vcc_i2c\n");
 		regulator_put(cd->vcc_i2c);
 		cd->vcc_i2c = NULL;
 	}
@@ -2063,9 +2065,9 @@ static int raydium_ts_probe(struct i2c_client *client,
 
 	/*print touch i2c ready*/
 	ret = raydium_check_i2c_ready(&u16_i2c_data);
-	if (ret < 0) {
+	if (ret < 0 || (u16_i2c_data == 0)) {
 		LOGD(LOG_ERR, "[touch]Check I2C failed\n");
-		ret = -ENODEV;
+		ret = -EPROBE_DEFER;
 		goto exit_check_i2c;
 	}
 
@@ -2143,6 +2145,8 @@ static int raydium_ts_probe(struct i2c_client *client,
 		ret = -ENODEV;
 		goto exit_irq_request_failed;
 	}
+
+	LOGD(LOG_INFO, "[touch] probe: done\n");
 	return 0;
 
 exit_irq_request_failed:
@@ -2158,31 +2162,32 @@ exit_input_register_device_failed:
 
 exit_input_dev_alloc_failed:
 exit_check_i2c:
-	if (gpio_is_valid(pdata->reset_gpio))
-		gpio_free(pdata->reset_gpio);
-
-	if (gpio_is_valid(pdata->irq_gpio))
-		gpio_free(pdata->irq_gpio);
-
-err_gpio_req:
 #ifdef MSM_NEW_VER
 	if (g_raydium_ts->ts_pinctrl) {
 		if (IS_ERR_OR_NULL(g_raydium_ts->pinctrl_state_release)) {
 			devm_pinctrl_put(g_raydium_ts->ts_pinctrl);
 			g_raydium_ts->ts_pinctrl = NULL;
 		} else {
-			ret = pinctrl_select_state(g_raydium_ts->ts_pinctrl,
-						   g_raydium_ts->pinctrl_state_release);
-			if (ret)
-				LOGD(LOG_ERR, "[touch]pinctrl_select_state failed\n");
+			if (pinctrl_select_state(g_raydium_ts->ts_pinctrl,
+					g_raydium_ts->pinctrl_state_release))
+				LOGD(LOG_ERR,
+				    "[touch]pinctrl_select_state failed\n");
 		}
 	}
 #endif/*end of MSM_NEW_VER*/
 
+	if (gpio_is_valid(pdata->reset_gpio))
+		gpio_free(pdata->reset_gpio);
+
+	if (gpio_is_valid(pdata->irq_gpio))
+		gpio_free(pdata->irq_gpio);
+
+err_gpio_req:
+	raydium_get_regulator(g_raydium_ts, false);
 error_get_regulator:
 	raydium_get_regulator(g_raydium_ts, false);
 error_alloc_data:
-	kfree(g_raydium_ts);
+
 parse_dt_failed:
 exit_check_functionality_failed:
 	return ret;