Re: [PATCH] Input: edt-ft5x06 - fix memleak when rmmod edt_ft5x06

From: Oliver Graute
Date: Fri Oct 11 2024 - 09:08:27 EST


On 10/10/24, Li Zetao wrote:
> When insmod and rmmod the edt_ft5x06 driver, kmemleak reported a
> memory leak issue:
> $ modprobe edt-ft5x06
> edt_ft5x06 0-0004: touchscreen probe failed
> $ modprobe -r edt-ft5x06
>
> unreferenced object 0xffff88810b38c8a0 (size 8):
> comm "modprobe", pid 23672, jiffies 4295355205
> hex dump (first 8 bytes):
> 93 00 00 00 00 00 00 00 ........
> backtrace (crc a10fb312):
> [<ffffffff81e12f70>] __kmalloc_noprof+0x2f0/0x3d0
> [<ffffffff8368c3b6>] __regmap_init+0x2d26/0x4810
> [<ffffffffc06b4875>] __regmap_init_i2c+0x65/0x80 [regmap_i2c]
> [<ffffffffc07108a6>] edt_ft5x06_ts_probe+0xd6/0x3410 [edt_ft5x06]
> [<ffffffff83bd85d1>] i2c_device_probe+0x3c1/0x8b0
> ...
>
> This is caused by not releasing the tsdata->regmap resource in time on
> the probe failure path. By adding the err_regmap_exit label, execute
> regmap_exit on the error path to release map resources. However, it
> should be noted that during the ts identify stage, regmap_exit may be
> performed first and then regmap may be reinitialized, so when
> edt_ft5x06_ts_identify() returns an error, it need to check whether the
> regmap initialization failed.
>
> Fixes: 9dfd9708ffba ("Input: edt-ft5x06 - convert to use regmap API")
> Signed-off-by: Li Zetao <lizetao1@xxxxxxxxxx>

Reviewed-by: Oliver Graute <oliver.graute@xxxxxxxxxxxxxxxxx>