[PATCH] soc: ti: wkup_m3_ipc: Use the device's own state in remove()

Andrew Davis afd at ti.com
Thu Dec 3 07:39:48 PST 2026


On 11/20/26 8:11 AM, Nhat Tran wrote:
> 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 at vger.kernel.org
> Signed-off-by: Nhat Tran <nhat.tranminhk2 at gmail.com>
> ---

Good find, but this fix is incomplete. You'll end up with the same NULL
dereference in `wkup_m3_ipc_resume()` should we go into suspend before
firmware is loaded, same for debugfs access before firmware.

The core issue is that `m3_ipc_state` being set is used both to signal
the core is available, and access the device structure in functions that
can't get it through other means. It would be betterto split these two
which also solves the issue here. Basically after probe `m3_ipc_state`
should always be set to prevent NULL dereference and a different signal
variable added/used for available check, something like:


> diff --git a/drivers/soc/ti/wkup_m3_ipc.c b/drivers/soc/ti/wkup_m3_ipc.c
> index eb6074a67ba3b..b351623079f16 100644
> --- a/drivers/soc/ti/wkup_m3_ipc.c
> +++ b/drivers/soc/ti/wkup_m3_ipc.c
> @@ -547,7 +547,7 @@ static const char *wkup_m3_request_wake_src(struct wkup_m3_ipc *m3_ipc)
>   */
>  static void wkup_m3_set_rtc_only(struct wkup_m3_ipc *m3_ipc)
>  {
> -       if (m3_ipc_state)
> +       if (m3_ipc_state->available)
>                 m3_ipc_state->is_rtc_only = true;
>  }
>  
> @@ -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->available)
>                 get_device(m3_ipc_state->dev);
>         else
>                 return NULL;
> @@ -584,7 +584,7 @@ EXPORT_SYMBOL_GPL(wkup_m3_ipc_get);
>   */
>  void wkup_m3_ipc_put(struct wkup_m3_ipc *m3_ipc)
>  {
> -       if (m3_ipc_state)
> +       if (m3_ipc_state->available)
>                 put_device(m3_ipc_state->dev);
>  }
>  EXPORT_SYMBOL_GPL(wkup_m3_ipc_put);
> @@ -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_state->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 5e1b26f988e22..f4a8ab45ee306 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