Re: [PATCH] hwrng: omap - Unregister hwrng before disabling the device on remove
From: Herbert Xu
Date: Fri Nov 20 2026 - 04:59:39 EST
On Sun, Nov 15, 2026 at 09:50:50PM +0700, Nhat Tran wrote:
> Commit 3e75241be808 ("hwrng: drivers - Use device-managed registration
> API") switched omap-rng to devm_hwrng_register() and dropped the
> hwrng_unregister() call from the start of omap_rng_remove(). Since then
> the hwrng is unregistered by devres only after omap_rng_remove() has
> returned, i.e. after the device has been runtime suspended and its
> runtime PM disabled.
>
> When the omap-rng is the current hwrng, hwrng_unregister() drops the
> last reference and schedules cleanup_rng_work(), which calls
> omap_rng_cleanup() and in turn omap4_rng_cleanup(). That reads and
> writes RNG_CONTROL_REG while the module clock is gated. On a
> BeagleBone Black (AM335x) unbinding the driver triggers:
>
> # echo 48310000.rng > /sys/bus/platform/drivers/omap_rng/unbind
> Unhandled fault: external abort on non-linefetch (0x1028) at 0xfa310014
> Internal error: : 1028 [#1] SMP ARM
> Workqueue: events cleanup_rng_work
> PC is at omap4_rng_cleanup+0x14/0x24
> LR is at cleanup_rng_work+0x30/0x48
> Call trace:
> omap4_rng_cleanup from cleanup_rng_work+0x30/0x48
> cleanup_rng_work from process_scheduled_works+0xf0/0x518
> process_scheduled_works from worker_thread+0x140/0x2f0
> worker_thread from kthread+0xfc/0x134
> kthread from ret_from_fork+0x14/0x28
>
> The worker dies before it completes rng->cleanup_done, so the unbind
> also never returns because hwrng_unregister() waits for that
> completion. The same window lets the hwrng fill thread call
> omap_rng_do_read() on the suspended device.
>
> Restore the original teardown order: register with hwrng_register()
> and call hwrng_unregister() first in omap_rng_remove(), while the
> device is still powered.
>
> Fixes: 3e75241be808 ("hwrng: drivers - Use device-managed registration API")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Nhat Tran <nhat.tranminhk2@xxxxxxxxx>
> ---
> drivers/char/hw_random/omap-rng.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt