diff mbox series

hwrng: mtk - Add remove function

Message ID 20240826014419.5151-1-guoqing.jiang@canonical.com (mailing list archive)
State New
Headers show
Series hwrng: mtk - Add remove function | expand

Commit Message

Guoqing Jiang Aug. 26, 2024, 1:44 a.m. UTC
Add mtk_rng_remove function which calles pm_runtime relevant funcs
and unregister hwrng to paired with mtk_rng_probe.

And without remove function, pm_runtime complains below when reload
the driver.

mtk_rng 1020f000.rng: Unbalanced pm_runtime_enable!

Signed-off-by: Guoqing Jiang <guoqing.jiang@canonical.com>
---
 drivers/char/hw_random/mtk-rng.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Chen-Yu Tsai Aug. 26, 2024, 5:17 a.m. UTC | #1
On Mon, Aug 26, 2024 at 9:45 AM Guoqing Jiang
<guoqing.jiang@canonical.com> wrote:
>
> Add mtk_rng_remove function which calles pm_runtime relevant funcs
> and unregister hwrng to paired with mtk_rng_probe.
>
> And without remove function, pm_runtime complains below when reload
> the driver.
>
> mtk_rng 1020f000.rng: Unbalanced pm_runtime_enable!
>
> Signed-off-by: Guoqing Jiang <guoqing.jiang@canonical.com>
> ---
>  drivers/char/hw_random/mtk-rng.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/drivers/char/hw_random/mtk-rng.c b/drivers/char/hw_random/mtk-rng.c
> index 302e201b51c2..1b6aa9406b11 100644
> --- a/drivers/char/hw_random/mtk-rng.c
> +++ b/drivers/char/hw_random/mtk-rng.c
> @@ -149,6 +149,15 @@ static int mtk_rng_probe(struct platform_device *pdev)
>         return 0;
>  }
>
> +static void mtk_rng_remove(struct platform_device *pdev)
> +{
> +        struct mtk_rng *priv = platform_get_drvdata(pdev);
> +
> +       pm_runtime_disable(&pdev->dev);

Instead maybe just replace pm_runtime_enable() with devm_pm_runtime_enable()
in the probe function?

> +       pm_runtime_set_suspended(&pdev->dev);

Not sure if this is needed? I'm not super familiar with runtime PM.

> +       devm_hwrng_unregister(&pdev->dev, &priv->rng);

The fact that it is already devm_* means that you shouldn't need to
call it.


ChenYu


> +}
> +
>  #ifdef CONFIG_PM
>  static int mtk_rng_runtime_suspend(struct device *dev)
>  {
> @@ -186,6 +195,7 @@ MODULE_DEVICE_TABLE(of, mtk_rng_match);
>
>  static struct platform_driver mtk_rng_driver = {
>         .probe          = mtk_rng_probe,
> +       .remove_new     = mtk_rng_remove,
>         .driver = {
>                 .name = MTK_RNG_DEV,
>                 .pm = MTK_RNG_PM_OPS,
> --
> 2.34.1
>
>
Guoqing Jiang Aug. 26, 2024, 6:41 a.m. UTC | #2
On 8/26/24 13:17, Chen-Yu Tsai wrote:
> On Mon, Aug 26, 2024 at 9:45 AM Guoqing Jiang
> <guoqing.jiang@canonical.com> wrote:
>> Add mtk_rng_remove function which calles pm_runtime relevant funcs
>> and unregister hwrng to paired with mtk_rng_probe.
>>
>> And without remove function, pm_runtime complains below when reload
>> the driver.
>>
>> mtk_rng 1020f000.rng: Unbalanced pm_runtime_enable!
>>
>> Signed-off-by: Guoqing Jiang <guoqing.jiang@canonical.com>
>> ---
>>   drivers/char/hw_random/mtk-rng.c | 10 ++++++++++
>>   1 file changed, 10 insertions(+)
>>
>> diff --git a/drivers/char/hw_random/mtk-rng.c b/drivers/char/hw_random/mtk-rng.c
>> index 302e201b51c2..1b6aa9406b11 100644
>> --- a/drivers/char/hw_random/mtk-rng.c
>> +++ b/drivers/char/hw_random/mtk-rng.c
>> @@ -149,6 +149,15 @@ static int mtk_rng_probe(struct platform_device *pdev)
>>          return 0;
>>   }
>>
>> +static void mtk_rng_remove(struct platform_device *pdev)
>> +{
>> +        struct mtk_rng *priv = platform_get_drvdata(pdev);
>> +
>> +       pm_runtime_disable(&pdev->dev);
> Instead maybe just replace pm_runtime_enable() with devm_pm_runtime_enable()
> in the probe function?

Good point, will try it though it seems the function was not called by 
any hwrng driver so far.

>> +       pm_runtime_set_suspended(&pdev->dev);
> Not sure if this is needed? I'm not super familiar with runtime PM.
>
>> +       devm_hwrng_unregister(&pdev->dev, &priv->rng);
> The fact that it is already devm_* means that you shouldn't need to
> call it.

Okay, will remove the unnecessary calls.

Thanks,
Guoqing
diff mbox series

Patch

diff --git a/drivers/char/hw_random/mtk-rng.c b/drivers/char/hw_random/mtk-rng.c
index 302e201b51c2..1b6aa9406b11 100644
--- a/drivers/char/hw_random/mtk-rng.c
+++ b/drivers/char/hw_random/mtk-rng.c
@@ -149,6 +149,15 @@  static int mtk_rng_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static void mtk_rng_remove(struct platform_device *pdev)
+{
+        struct mtk_rng *priv = platform_get_drvdata(pdev);
+
+	pm_runtime_disable(&pdev->dev);
+	pm_runtime_set_suspended(&pdev->dev);
+	devm_hwrng_unregister(&pdev->dev, &priv->rng);
+}
+
 #ifdef CONFIG_PM
 static int mtk_rng_runtime_suspend(struct device *dev)
 {
@@ -186,6 +195,7 @@  MODULE_DEVICE_TABLE(of, mtk_rng_match);
 
 static struct platform_driver mtk_rng_driver = {
 	.probe          = mtk_rng_probe,
+	.remove_new	= mtk_rng_remove,
 	.driver = {
 		.name = MTK_RNG_DEV,
 		.pm = MTK_RNG_PM_OPS,