diff mbox series

hwrng: cctrng: Add cancel_work_sync before module remove

Message ID d71e0bcee781ebe12697df94083f16d651fb30c0.1732786634.git.xiaopei01@kylinos.cn
State New
Headers show
Series hwrng: cctrng: Add cancel_work_sync before module remove | expand

Commit Message

Pei Xiao Nov. 28, 2024, 9:39 a.m. UTC
Be ensured that the work is canceled before proceeding with
the cleanup in cc_trng_pm_fini.

Fixes: a583ed310bb6 ("hwrng: cctrng - introduce Arm CryptoCell driver")
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
 drivers/char/hw_random/cctrng.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Herbert Xu Dec. 10, 2024, 5:28 a.m. UTC | #1
Pei Xiao <xiaopei01@kylinos.cn> wrote:
> Be ensured that the work is canceled before proceeding with
> the cleanup in cc_trng_pm_fini.
> 
> Fixes: a583ed310bb6 ("hwrng: cctrng - introduce Arm CryptoCell driver")
> Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
> ---
> drivers/char/hw_random/cctrng.c | 2 ++
> 1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/char/hw_random/cctrng.c b/drivers/char/hw_random/cctrng.c
> index 4db198849695..fd1ee3687782 100644
> --- a/drivers/char/hw_random/cctrng.c
> +++ b/drivers/char/hw_random/cctrng.c
> @@ -127,6 +127,8 @@ static void cc_trng_pm_fini(struct cctrng_drvdata *drvdata)
> {
>        struct device *dev = &(drvdata->pdev->dev);
> 
> +       cancel_work_sync(&drvdata->compwork);
> +       cancel_work_sync(&drvdata->startwork);
>        pm_runtime_disable(dev);
> }

I don't think this is right.  This is a problem with using devres:
you need to be very careful with unwinding things.  The remove
occurs before all devm resources are released.  So the device is
still registered with the hwrng core and potentially live.

These work tasks are created by the ISR.  So they should only be
cancelled after the IRQ handler has been unregistered.

Perhaps we should just rip out all the devm code and go back to
manual freeing.

Cheers,
diff mbox series

Patch

diff --git a/drivers/char/hw_random/cctrng.c b/drivers/char/hw_random/cctrng.c
index 4db198849695..fd1ee3687782 100644
--- a/drivers/char/hw_random/cctrng.c
+++ b/drivers/char/hw_random/cctrng.c
@@ -127,6 +127,8 @@  static void cc_trng_pm_fini(struct cctrng_drvdata *drvdata)
 {
 	struct device *dev = &(drvdata->pdev->dev);
 
+	cancel_work_sync(&drvdata->compwork);
+	cancel_work_sync(&drvdata->startwork);
 	pm_runtime_disable(dev);
 }