]> git.hungrycats.org Git - linux/commit
hwrng: st - keep clock enabled while hwrng is registered
authorMartin Kaiser <martin@kaiser.cx>
Fri, 16 Jun 2023 08:58:13 +0000 (09:58 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 Jul 2023 17:39:50 +0000 (19:39 +0200)
commit950f1e7b956ce04268862fa69f2fc78c861608e8
tree77bbe12df00c7882985b44a412e68f79fa96f0e9
parent8267c76c52017a71f5bcb8aeeb2320e17beb23c8
hwrng: st - keep clock enabled while hwrng is registered

[ Upstream commit 501e197a02d4aef157f53ba3a0b9049c3e52fedc ]

The st-rng driver uses devres to register itself with the hwrng core,
the driver will be unregistered from hwrng when its device goes out of
scope. This happens after the driver's remove function is called.

However, st-rng's clock is disabled in the remove function. There's a
short timeframe where st-rng is still registered with the hwrng core
although its clock is disabled. I suppose the clock must be active to
access the hardware and serve requests from the hwrng core.

Switch to devm_clk_get_enabled and let devres disable the clock and
unregister the hwrng. This avoids the race condition.

Fixes: 3e75241be808 ("hwrng: drivers - Use device-managed registration API")
Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/char/hw_random/st-rng.c