From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Linkai Gong <gonglinkai@kylinos.cn>
Cc: Andi Shyti <andi.shyti@kernel.org>,
Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
Luca Ceresoli <luca.ceresoli@bootlin.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Wolfram Sang <wsa@kernel.org>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] i2c: atr: fix dangling adapter pointer on add failure
Date: Tue, 11 Aug 2026 17:36:13 +0300 [thread overview]
Message-ID: <anszXdhlAJk7p7ts@ashevche-desk.local> (raw)
In-Reply-To: <20260806073545.2071006-1-gonglinkai@kylinos.cn>
On Thu, Aug 06, 2026 at 03:35:45PM +0800, Linkai Gong wrote:
> i2c_atr_add_adapter() stores atr->adapter[chan_id] before
> i2c_add_adapter() so that the I2C bus notifier can match child clients
> during registration. On failure the channel is freed but the slot was
> left pointing at freed memory, which can lead to use-after-free in
> i2c_atr_del_adapter() / cleanup and also block reuse with -EEXIST.
>
> Clear the slot on the i2c_add_adapter() error path before freeing chan.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
...
> if (ret) {
> dev_err(dev, "failed to add atr-adapter %u (error=%d)\n",
> chan_id, ret);
> + atr->adapter[chan_id] = NULL;
It's better to NULLify first and print after. This will reduce the window of
possible calls with the stale pointer.
> goto err_free_alias_pool;
> }
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-08-11 14:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 7:35 Linkai Gong
2026-08-11 14:36 ` Andy Shevchenko [this message]
2026-09-07 7:07 ` Linkai Gong
2026-09-07 7:11 ` [PATCH v2] " Linkai Gong
2026-09-16 6:09 ` Andi Shyti
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=anszXdhlAJk7p7ts@ashevche-desk.local \
--to=andriy.shevchenko@linux.intel.com \
--cc=andi.shyti@kernel.org \
--cc=gonglinkai@kylinos.cn \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=mchehab@kernel.org \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=wsa@kernel.org \
/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
all inboxes | Powered by JetHome®