mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nhat Tran <nhat.tranminhk2@gmail.com>
To: Nishanth Menon <nm@ti.com>, Santosh Shilimkar <ssantosh@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Nhat Tran <nhat.tranminhk2@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] soc: ti: wkup_m3_ipc: Use the device's own state in remove()
Date: Fri, 20 Nov 2026 21:11:39 +0700	[thread overview]
Message-ID: <20261120141139.55783-1-nhat.tranminhk2@gmail.com> (raw)

wkup_m3_ipc_remove() tears down the driver through the global
m3_ipc_state pointer. That pointer is only set by the rproc boot thread
once rproc_boot() succeeds, while probe returns success regardless of
the boot result. If the wkup_m3 firmware cannot be loaded, for example
because the driver is built in and probes before the root filesystem
holding am335x-pm-firmware.elf is mounted, m3_ipc_state stays NULL and
unbinding the driver dereferences it.

On a BeagleBone Black (AM335x):

  wkup_m3_ipc 44e11324.wkup_m3_ipc: rproc_boot failed
  # cd /sys/bus/platform/drivers/wkup_m3_ipc
  # echo 44e11324.wkup_m3_ipc > unbind
  Unable to handle kernel NULL pointer dereference at virtual address 00000064 when read
  Internal error: Oops: 5 [#1] SMP ARM
  PC is at wkup_m3_ipc_remove+0xc/0x48
  LR is at device_release_driver_internal+0xbc/0x144
  Call trace:
   wkup_m3_ipc_remove from device_release_driver_internal+0xbc/0x144
   device_release_driver_internal from unbind_store+0x50/0x74
   unbind_store from kernfs_fop_write_iter+0x11c/0x1d4
   kernfs_fop_write_iter from vfs_write+0x2a8/0x3f8
   vfs_write from ksys_write+0x60/0xe0
   ksys_write from ret_fast_syscall+0x0/0x54

The same happens when the mailbox the driver depends on is unbound.

Store the per-device state as driver data in probe and use it in
remove(), so the debugfs entries, the mailbox channel and the rproc
reference taken in probe are released whether or not the M3 was
booted. rproc_shutdown() already returns -EINVAL for a remote processor
that is not running.

Tested on a BeagleBone Black with the firmware not loaded at probe
time: unbinding the driver directly or through the mailbox no longer
oopses, and repeated unbind/bind cycles rebind and boot the M3 again.

Fixes: cdd5de500b2c ("soc: ti: Add wkup_m3_ipc driver")
Cc: stable@vger.kernel.org
Signed-off-by: Nhat Tran <nhat.tranminhk2@gmail.com>
---
 drivers/soc/ti/wkup_m3_ipc.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/soc/ti/wkup_m3_ipc.c b/drivers/soc/ti/wkup_m3_ipc.c
index eb6074a67ba3..224651955cda 100644
--- a/drivers/soc/ti/wkup_m3_ipc.c
+++ b/drivers/soc/ti/wkup_m3_ipc.c
@@ -695,6 +695,7 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev)
 		goto err_put_rproc;
 	}
 
+	platform_set_drvdata(pdev, m3_ipc);
 	wkup_m3_ipc_dbg_init(m3_ipc);
 
 	return 0;
@@ -708,12 +709,14 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev)
 
 static void wkup_m3_ipc_remove(struct platform_device *pdev)
 {
-	wkup_m3_ipc_dbg_destroy(m3_ipc_state);
+	struct wkup_m3_ipc *m3_ipc = platform_get_drvdata(pdev);
 
-	mbox_free_channel(m3_ipc_state->mbox);
+	wkup_m3_ipc_dbg_destroy(m3_ipc);
 
-	rproc_shutdown(m3_ipc_state->rproc);
-	rproc_put(m3_ipc_state->rproc);
+	mbox_free_channel(m3_ipc->mbox);
+
+	rproc_shutdown(m3_ipc->rproc);
+	rproc_put(m3_ipc->rproc);
 
 	m3_ipc_state = NULL;
 }
-- 
2.25.1


                 reply	other threads:[~2026-11-20 14:15 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=20261120141139.55783-1-nhat.tranminhk2@gmail.com \
    --to=nhat.tranminhk2@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=ssantosh@kernel.org \
    --cc=stable@vger.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®