Skip to content

Commit bffdf9d

Browse files
committed
Input: edt-ft5x06 - fix regmap leak when probe fails
The driver neglects to free the instance of I2C regmap constructed at the beginning of the edt_ft5x06_ts_probe() method when probe fails. Additionally edt_ft5x06_ts_remove() is freeing the regmap too early, before the rest of the device resources that are managed by devm are released. Fix this by installing a custom devm action that will ensure that the regmap is released at the right time during normal teardown as well as in case of probe failure. Note that devm_regmap_init_i2c() could not be used because the driver may replace the original regmap with a regmap specific for M06 devices in the middle of the probe, and using devm_regmap_init_i2c() would result in releasing the M06 regmap too early. Reported-by: Li Zetao <lizetao1@huawei.com> Fixes: 9dfd970 ("Input: edt-ft5x06 - convert to use regmap API") Cc: stable@vger.kernel.org Reviewed-by: Oliver Graute <oliver.graute@kococonnector.com> Link: https://lore.kernel.org/r/ZxL6rIlVlgsAu-Jv@google.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 2de01e0 commit bffdf9d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

drivers/input/touchscreen/edt-ft5x06.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,14 @@ static void edt_ft5x06_ts_set_regs(struct edt_ft5x06_ts_data *tsdata)
11211121
}
11221122
}
11231123

1124+
static void edt_ft5x06_exit_regmap(void *arg)
1125+
{
1126+
struct edt_ft5x06_ts_data *data = arg;
1127+
1128+
if (!IS_ERR_OR_NULL(data->regmap))
1129+
regmap_exit(data->regmap);
1130+
}
1131+
11241132
static void edt_ft5x06_disable_regulators(void *arg)
11251133
{
11261134
struct edt_ft5x06_ts_data *data = arg;
@@ -1154,6 +1162,16 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client)
11541162
return PTR_ERR(tsdata->regmap);
11551163
}
11561164

1165+
/*
1166+
* We are not using devm_regmap_init_i2c() and instead install a
1167+
* custom action because we may replace regmap with M06-specific one
1168+
* and we need to make sure that it will not be released too early.
1169+
*/
1170+
error = devm_add_action_or_reset(&client->dev, edt_ft5x06_exit_regmap,
1171+
tsdata);
1172+
if (error)
1173+
return error;
1174+
11571175
chip_data = device_get_match_data(&client->dev);
11581176
if (!chip_data)
11591177
chip_data = (const struct edt_i2c_chip_data *)id->driver_data;
@@ -1347,7 +1365,6 @@ static void edt_ft5x06_ts_remove(struct i2c_client *client)
13471365
struct edt_ft5x06_ts_data *tsdata = i2c_get_clientdata(client);
13481366

13491367
edt_ft5x06_ts_teardown_debugfs(tsdata);
1350-
regmap_exit(tsdata->regmap);
13511368
}
13521369

13531370
static int edt_ft5x06_ts_suspend(struct device *dev)

0 commit comments

Comments
 (0)