linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Oliver Graute <oliver.graute@gmail.com>
Cc: Li Zetao <lizetao1@huawei.com>,
	u.kleine-koenig@pengutronix.de, felix@kaechele.ca,
	ye.xingchen@zte.com.cn, joelselvaraj.oss@gmail.com,
	andreas@kemnade.info, viro@zeniv.linux.org.uk,
	dario.binacchi@amarulasolutions.com, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Input: edt-ft5x06 - fix memleak when rmmod edt_ft5x06
Date: Fri, 18 Oct 2024 17:20:09 -0700	[thread overview]
Message-ID: <ZxL7OS_mIoZRPhYw@google.com> (raw)
In-Reply-To: <ZwkjNoa63gH5U6Mu@graute-think>

On Fri, Oct 11, 2024 at 03:08:06PM +0200, Oliver Graute wrote:
> 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@huawei.com>
> 
> Reviewed-by: Oliver Graute <oliver.graute@kococonnector.com>

No, this is not the right way to fix the issue. The rest of the driver
uses managed resources, which means that regmap in error path will be
freed too early, which may cause issues.

We have same issue in driver's remove() path as well.

I CCed you on a patch that uses devm to release regmap which will make
sure all resources are released in the right order.

Thanks.

-- 
Dmitry

      reply	other threads:[~2024-10-19  0:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-10 15:40 [PATCH] Input: edt-ft5x06 - fix memleak when rmmod edt_ft5x06 Li Zetao
2024-10-11 13:08 ` Oliver Graute
2024-10-19  0:20   ` Dmitry Torokhov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZxL7OS_mIoZRPhYw@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=andreas@kemnade.info \
    --cc=dario.binacchi@amarulasolutions.com \
    --cc=felix@kaechele.ca \
    --cc=joelselvaraj.oss@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizetao1@huawei.com \
    --cc=oliver.graute@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=viro@zeniv.linux.org.uk \
    --cc=ye.xingchen@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).