[PATCH v2] soc: ti: wkup_m3_ipc: Fix NULL dereference when the M3 fails to boot
Andrew Davis
afd at ti.com
Thu Dec 3 11:17:34 PST 2026
On 12/3/26 11:41 AM, Nhat Tran wrote:
> m3_ipc_state is set by the rproc boot thread only once rproc_boot()
> succeeds, while probe returns success regardless of the boot result.
> The pointer is used both to tell wkup_m3_ipc_get() that the M3 is
> available and as the only way remove() and the resume callback reach
> the driver state. 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
> both resuming from system sleep and unbinding the driver dereference it.
>
> On a BeagleBone Black (AM335x) with the firmware missing:
>
> wkup_m3_ipc 44e11324.wkup_m3_ipc: rproc_boot failed
> # echo devices > /sys/power/pm_test
> # echo freeze > /sys/power/state
> Unable to handle kernel NULL pointer dereference at virtual address 00000060 when read
> Internal error: Oops: 5 [#1] SMP ARM
> PC is at wkup_m3_ipc_resume+0xc/0x44 [wkup_m3_ipc]
> LR is at dpm_run_callback+0x4c/0x208
> Call trace:
> wkup_m3_ipc_resume [wkup_m3_ipc] from dpm_run_callback+0x4c/0x208
> dpm_run_callback from device_resume+0xf0/0x298
> device_resume from dpm_resume+0x178/0x2dc
> dpm_resume from dpm_resume_end+0xc/0x1c
> dpm_resume_end from suspend_devices_and_enter+0x25c/0x9d4
> suspend_devices_and_enter from pm_suspend+0x2f8/0x340
> pm_suspend from state_store+0x68/0xc8
>
> Unbinding the driver, directly or through the mailbox it depends on,
> oopses the same way in wkup_m3_ipc_remove().
>
> Split the two uses. Set m3_ipc_state at the end of probe so it is valid
> for as long as the driver is bound, and add an 'available' flag that the
> boot thread sets once the M3 is running and remove() clears.
> wkup_m3_ipc_get() checks the flag, so pm33xx still defers its probe
> until the M3 has booted. The boot thread sets the flag through its own
> pointer because it is started before probe assigns m3_ipc_state.
> wkup_m3_ipc_put() keeps checking only the pointer, as it has to drop
> the reference taken by wkup_m3_ipc_get() whether or not the M3 is still
> running.
>
> Tested on a BeagleBone Black:
> - firmware missing: s2idle with pm_test=devices resumes without an
> oops, and repeated unbind/bind cycles no longer oops
> - firmware present: the M3 boots, pm33xx probes, and s2idle still
> suspends and resumes
>
> Fixes: cdd5de500b2c ("soc: ti: Add wkup_m3_ipc driver")
> Cc: stable at vger.kernel.org
> Suggested-by: Andrew Davis <afd at ti.com>
> Signed-off-by: Nhat Tran <nhat.tranminhk2 at gmail.com>
> ---
Acked-by: Andrew Davis <afd at ti.com>
> v1 -> v2:
> - Instead of passing the state to remove() as driver data, keep
> m3_ipc_state set from probe and track whether the M3 is running in a
> separate flag, as suggested by Andrew Davis. This also fixes
> the same NULL dereference in the resume callback, which v1 missed.
> - Retitled from "Use the device's own state in remove()".
> v1: https://lore.kernel.org/r/20261120141139.55783-1-nhat.tranminhk2@gmail.com
> ---
> drivers/soc/ti/wkup_m3_ipc.c | 8 ++++++--
> include/linux/wkup_m3_ipc.h | 1 +
> 2 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/soc/ti/wkup_m3_ipc.c b/drivers/soc/ti/wkup_m3_ipc.c
> index eb6074a67ba3..7f9d67115ebf 100644
> --- a/drivers/soc/ti/wkup_m3_ipc.c
> +++ b/drivers/soc/ti/wkup_m3_ipc.c
> @@ -569,7 +569,7 @@ static struct wkup_m3_ipc_ops ipc_ops = {
> */
> struct wkup_m3_ipc *wkup_m3_ipc_get(void)
> {
> - if (m3_ipc_state)
> + if (m3_ipc_state && m3_ipc_state->available)
> get_device(m3_ipc_state->dev);
> else
> return NULL;
> @@ -601,7 +601,7 @@ static int wkup_m3_rproc_boot_thread(void *arg)
> if (ret)
> dev_err(dev, "rproc_boot failed\n");
> else
> - m3_ipc_state = m3_ipc;
> + m3_ipc->available = true;
>
> return 0;
> }
> @@ -695,6 +695,8 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev)
> goto err_put_rproc;
> }
>
> + m3_ipc_state = m3_ipc;
> +
> wkup_m3_ipc_dbg_init(m3_ipc);
>
> return 0;
> @@ -708,6 +710,8 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev)
>
> static void wkup_m3_ipc_remove(struct platform_device *pdev)
> {
> + m3_ipc_state->available = false;
> +
> wkup_m3_ipc_dbg_destroy(m3_ipc_state);
>
> mbox_free_channel(m3_ipc_state->mbox);
> diff --git a/include/linux/wkup_m3_ipc.h b/include/linux/wkup_m3_ipc.h
> index 5e1b26f988e2..f4a8ab45ee30 100644
> --- a/include/linux/wkup_m3_ipc.h
> +++ b/include/linux/wkup_m3_ipc.h
> @@ -29,6 +29,7 @@ struct wkup_m3_ipc {
> int isolation_conf;
> int state;
> u32 halt;
> + bool available;
>
> unsigned long volt_scale_offsets;
> const char *sd_fw_name;
More information about the linux-arm-kernel
mailing list