[PATCH] soc: ti: wkup_m3_ipc: Use the device's own state in remove()
Andrew Davis
afd at ti.com
Thu Dec 3 11:21:04 PST 2026
On 12/3/26 11:52 AM, Nhat Tran wrote:
> Dear Andrew,
>
>> 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.
>
> Thanks, you're right. I tested it on v1 and resume crashes too when
> the firmware is missing.
>
>> 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.
>
> I sent v2 with this approach:
> https://lore.kernel.org/r/20261203174139.55646-1-nhat.tranminhk2@gmail.com
>
> I changed a few small things from your diff:
>
>>> struct wkup_m3_ipc *wkup_m3_ipc_get(void)
>>> {
>>> - if (m3_ipc_state)
>>> + if (m3_ipc_state->available)
>>> get_device(m3_ipc_state->dev);
>
> m3_ipc_state can still be NULL here, e.g. if pm33xx probes before
> wkup_m3_ipc. So I kept the NULL check:
>
> if (m3_ipc_state && m3_ipc_state->available)
>
>>> 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);
>>> }
>
> I left put() as it was. It should drop the reference even if the M3 is
> no longer available. Also m3_ipc_state is NULL again after remove(), so
> this would crash if pm33xx is removed after wkup_m3_ipc.
>
>>> @@ -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;
>
> The thread starts before probe sets m3_ipc_state, so I used
> m3_ipc->available here instead.
>
Another option would have been to set m3_ipc_state = m3_ipc;
earlier in probe() so that it would be available before
this thread could be scheduled. But your v2 using m3_ipc
looks fine also.
Andrew
> Best Regards,
> Nhat Tran
More information about the linux-arm-kernel
mailing list