Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Prasanth R <ragaprasanth@gmail.com>
To: Peter Chen <peter.chen@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Frank Li <Frank.Li@nxp.com>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	linux-usb@vger.kernel.org, imx@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Prasanth R <ragaprasanth@gmail.com>
Subject: [PATCH] usb: chipidea: ci_hdrc_imx: link to usbmisc to fix NULL deref on unbind
Date: Wed,  2 Dec 2026 17:28:20 +0900	[thread overview]
Message-ID: <20261202082820.3764321-1-ragaprasanth@gmail.com> (raw)

ci_hdrc_imx uses the usbmisc driver data in suspend and resume, but
nothing keeps usbmisc bound. After usbmisc is unbound, its driver data
is NULL and the next resume crashes. On the i.MX6Q SABRE-SD, with the
USB host port runtime suspended:

  echo 2184800.usbmisc > /sys/bus/platform/drivers/usbmisc_imx/unbind
  echo 2184200.usb > /sys/bus/platform/drivers/imx_usb/unbind

  BUG: KASAN: null-ptr-deref in imx_usbmisc_resume+0x34/0x2b4
  Read of size 4 at addr 0000000c

Add a device link from the controller to usbmisc, so unbinding usbmisc
unbinds the controller first.

Fixes: e14db48dfcf3 ("usb: chipidea: imx: add runtime power management support")

Signed-off-by: Prasanth R <prasanth.r@lineo.co.jp>
---
Tested on the i.MX6Q SABRE-SD with KASAN: no crash after the fix,
and both USB ports bind again after usbmisc is bound again.
Suspend to RAM and resume still work.

I used an AI assistant (Claude) to find this and write the change.

 drivers/usb/chipidea/ci_hdrc_imx.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
index 282314eea..af5485e1d 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -170,6 +170,12 @@ static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev)
 	}
 	data->dev = &misc_pdev->dev;
 
+	/* Keep usbmisc bound while this controller uses it */
+	if (!device_link_add(dev, &misc_pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER)) {
+		put_device(&misc_pdev->dev);
+		return ERR_PTR(-EINVAL);
+	}
+
 	/*
 	 * Check the various over current related properties. If over current
 	 * detection is disabled we're not interested in the polarity.
-- 
2.34.1



                 reply	other threads:[~2026-12-02  8:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261202082820.3764321-1-ragaprasanth@gmail.com \
    --to=ragaprasanth@gmail.com \
    --cc=Frank.Li@nxp.com \
    --cc=festevam@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=peter.chen@kernel.org \
    --cc=s.hauer@pengutronix.de \
    /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