From: "Peter Chen (Qualcomm)" <peter.chen@kernel.org>
To: Frank Li <Frank.li@oss.nxp.com>
Cc: Xu Yang <xu.yang_2@oss.nxp.com>,
pawell@cadence.com, rogerq@kernel.org,
gregkh@linuxfoundation.org, Frank.Li@nxp.com,
s.hauer@pengutronix.de, kernel@pengutronix.de,
festevam@gmail.com, balbi@kernel.org, linux-usb@vger.kernel.org,
imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, jun.li@nxp.com
Subject: Re: [PATCH] usb: cdns3: imx: fix kernel panic on remove due to kfree of static platform_data
Date: Mon, 19 Oct 2026 19:02:56 -0700 [thread overview]
Message-ID: <atbL0FjdTOQoJHjQ@hu-petche-lv.qualcomm.com> (raw)
In-Reply-To: <atZ_w13x6QgsMhwn@SMW015318>
On 26-10-19 15:38:27, Frank Li wrote:
> On Mon, Oct 19, 2026 at 04:49:44PM +0800, Xu Yang wrote:
> > From: Xu Yang <xu.yang_2@nxp.com>
> >
> > When cdns_imx_remove() calls of_platform_depopulate(), the child
> > platform device is destroyed. platform_device_release() then calls
> > kfree(pdev->dev.platform_data), but cdns3-imx assigns a pointer to
> > a static global variable as platform_data, so kfree() on it triggers
> > a kernel panic.
> >
> > [ 56.809541] Call trace:
> > [ 56.811982] kfree+0x44/0x398 (P)
> > [ 56.815300] platform_device_release+0x24/0x4c
> > [ 56.819747] device_release+0x3c/0xa0
> > [ 56.823413] kobject_put+0xa0/0x120
> > [ 56.826906] klist_children_put+0x18/0x28
> > [ 56.830920] klist_prev+0xb4/0x1c0
> > [ 56.834325] device_for_each_child_reverse+0x7c/0xc8
> > [ 56.839294] of_platform_depopulate+0x34/0x80
> > [ 56.843664] cdns_imx_remove+0x34/0xcc [cdns3_imx]
> >
> > Fix this by iterating over child devices and clearing platform_data
> > to NULL before of_platform_depopulate() is called, preventing the
> > invalid kfree().
> >
> > Fixes: ff6d6e6c6778 ("usb: cdns3: imx: add glue layer runtime pm implementation")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> > ---
>
> Reviewed-by: Frank Li <Frank.Li@nxp.com>
Acked-by: Peter Chen <peter.chen@kernel.org>
Peter
>
> > drivers/usb/cdns3/cdns3-imx.c | 8 ++++++++
> > 1 file changed, 8 insertions(+)
> >
> > diff --git a/drivers/usb/cdns3/cdns3-imx.c b/drivers/usb/cdns3/cdns3-imx.c
> > index a2f041e1707c..2c86fadd2cf2 100644
> > --- a/drivers/usb/cdns3/cdns3-imx.c
> > +++ b/drivers/usb/cdns3/cdns3-imx.c
> > @@ -218,12 +218,20 @@ static int cdns_imx_probe(struct platform_device *pdev)
> > return ret;
> > }
> >
> > +static int cdns_imx_reset_pdata(struct device *dev, void *data)
> > +{
> > + if (device_is_compatible(dev, "cdns,usb3"))
> > + dev->platform_data = NULL;
> > + return 0;
> > +}
> > +
> > static void cdns_imx_remove(struct platform_device *pdev)
> > {
> > struct device *dev = &pdev->dev;
> > struct cdns_imx *data = dev_get_drvdata(dev);
> >
> > pm_runtime_get_sync(dev);
> > + device_for_each_child(dev, NULL, cdns_imx_reset_pdata);
> > of_platform_depopulate(dev);
> > clk_bulk_disable_unprepare(data->num_clks, data->clks);
> > pm_runtime_disable(dev);
> > --
> > 2.34.1
> >
> >
--
Thanks,
Peter Chen
prev parent reply other threads:[~2026-10-20 2:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 8:49 Xu Yang
2026-10-19 20:38 ` Frank Li
2026-10-20 2:02 ` Peter Chen (Qualcomm) [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=atbL0FjdTOQoJHjQ@hu-petche-lv.qualcomm.com \
--to=peter.chen@kernel.org \
--cc=Frank.Li@nxp.com \
--cc=Frank.li@oss.nxp.com \
--cc=balbi@kernel.org \
--cc=festevam@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=imx@lists.linux.dev \
--cc=jun.li@nxp.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=pawell@cadence.com \
--cc=rogerq@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=xu.yang_2@oss.nxp.com \
/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®