hwrng: Explicitly drop current_rng when unregistering rng device
PATCH 1/1 hwrng: Explicitly drop current_rng when unregistering rng device
When the currently in-use hw rng is being removed from the system, explicitly drop it before using enable_best_rng as enable_best_rng will not do anything if the list of avaialble RNGs is empty.
Without this, the last RNG removed from the system will never get cleaned up and hwrng_unregister will hang.
--- drivers/char/hw_random/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/hw_random/core.c +3 -1
@@ -515,8 +515,10 @@ void hwrng_unregister(struct hwrng *rng)mutex_lock (&rng_mutex);list_del (&rng->list); -if (current_rng == rng) +if (current_rng == rng) { +drop_current_rng ();enable_best_rng (); + }if (list_empty (&rng_list)) {mutex_unlock (&rng_mutex);
Signature · 1 line
2.15.1
Quoted 17 lines · Keith Packard
When the currently in-use hw rng is being removed from the system, explicitly drop it before using
enable_best_rngasenable_best_rngwill not do anything if the list of avaialble RNGs is empty.Without this, the last RNG removed from the system will never get cleaned up and
hwrng_unregisterwill hang.Signed-off-by Keith Packard <[email protected]>--- drivers/char/hw_random/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/char/hw_random/core.c +0
-0
drivers/char/hw_random/core.c void hwrng_unregister(struct hwrng *rng) · line 521
Quoted 8 lines
drivers/char/hw_random/core.c +3
-1@@ -515,8 +515,10 @@ void hwrng_unregister(struct hwrng *rng)mutex_lock (&rng_mutex);list_del (&rng->list); -if (current_rng == rng) +if (current_rng == rng) { +drop_current_rng ();enable_best_rng (); + }
A similar fix was already in the cryptodev tree and I thought was part of a recent pull request.
Thanks,
Tom
Quoted 4 lines
drivers/char/hw_random/core.c +0
-0if (list_empty (&rng_list)) {mutex_unlock (&rng_mutex);
Quoted 2 lines · Tom Lendacky
A similar fix was already in the cryptodev tree and I thought was part of a recent pull request.
Yup, just saw it on master. I've checked and it will do pretty much the same thing as my patch, with the addition of clearing cur_rng_set_by_user, which is necessary. Thanks for looking at my patch!
Signature · 1 line
-keith