* [PATCH 6/6] platform/x86/amd/pmf: Ensure mutexes are initialized before use
@ 2023-01-30 13:25 Hans de Goede
2023-01-30 13:33 ` Hans de Goede
2023-01-30 14:30 ` Shyam Sundar S K
0 siblings, 2 replies; 3+ messages in thread
From: Hans de Goede @ 2023-01-30 13:25 UTC (permalink / raw)
To: Mark Gross, Andy Shevchenko
Cc: Hans de Goede, Mario Limonciello, Shyam Sundar S K, platform-driver-x86
As soon as the first handler or sysfs file is registered
the mutex may get used.
Move the initialization to before any handler registration /
sysfs file creation.
Likewise move the destruction of the mutex to after all
the de-initialization is done.
Fixes: da5ce22df5fe ("platform/x86/amd/pmf: Add support for PMF core layer")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/amd/pmf/core.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c
index c9f7bcef4ac8..da23639071d7 100644
--- a/drivers/platform/x86/amd/pmf/core.c
+++ b/drivers/platform/x86/amd/pmf/core.c
@@ -385,6 +385,9 @@ static int amd_pmf_probe(struct platform_device *pdev)
if (!dev->regbase)
return -ENOMEM;
+ mutex_init(&dev->lock);
+ mutex_init(&dev->update_mutex);
+
apmf_acpi_init(dev);
platform_set_drvdata(pdev, dev);
amd_pmf_init_features(dev);
@@ -394,8 +397,6 @@ static int amd_pmf_probe(struct platform_device *pdev)
dev->pwr_src_notifier.notifier_call = amd_pmf_pwr_src_notify_call;
power_supply_reg_notifier(&dev->pwr_src_notifier);
- mutex_init(&dev->lock);
- mutex_init(&dev->update_mutex);
dev_info(dev->dev, "registered PMF device successfully\n");
return 0;
@@ -406,11 +407,11 @@ static int amd_pmf_remove(struct platform_device *pdev)
struct amd_pmf_dev *dev = platform_get_drvdata(pdev);
power_supply_unreg_notifier(&dev->pwr_src_notifier);
- mutex_destroy(&dev->lock);
- mutex_destroy(&dev->update_mutex);
amd_pmf_deinit_features(dev);
apmf_acpi_deinit(dev);
amd_pmf_dbgfs_unregister(dev);
+ mutex_destroy(&dev->lock);
+ mutex_destroy(&dev->update_mutex);
kfree(dev->buf);
return 0;
}
--
2.39.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 6/6] platform/x86/amd/pmf: Ensure mutexes are initialized before use
2023-01-30 13:25 [PATCH 6/6] platform/x86/amd/pmf: Ensure mutexes are initialized before use Hans de Goede
@ 2023-01-30 13:33 ` Hans de Goede
2023-01-30 14:30 ` Shyam Sundar S K
1 sibling, 0 replies; 3+ messages in thread
From: Hans de Goede @ 2023-01-30 13:33 UTC (permalink / raw)
To: Mark Gross, Andy Shevchenko
Cc: Mario Limonciello, Shyam Sundar S K, platform-driver-x86
Hi All,
The subject prefix should be [PATCH 1/1], my bad.
On 1/30/23 14:25, Hans de Goede wrote:
> As soon as the first handler or sysfs file is registered
> the mutex may get used.
>
> Move the initialization to before any handler registration /
> sysfs file creation.
>
> Likewise move the destruction of the mutex to after all
> the de-initialization is done.
>
> Fixes: da5ce22df5fe ("platform/x86/amd/pmf: Add support for PMF core layer")
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
I've applied this to the pdx86 fixes branch now:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=fixes
and this will be included in my next fixes pull-req to Linus.
Regards,
Hans
> ---
> drivers/platform/x86/amd/pmf/core.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c
> index c9f7bcef4ac8..da23639071d7 100644
> --- a/drivers/platform/x86/amd/pmf/core.c
> +++ b/drivers/platform/x86/amd/pmf/core.c
> @@ -385,6 +385,9 @@ static int amd_pmf_probe(struct platform_device *pdev)
> if (!dev->regbase)
> return -ENOMEM;
>
> + mutex_init(&dev->lock);
> + mutex_init(&dev->update_mutex);
> +
> apmf_acpi_init(dev);
> platform_set_drvdata(pdev, dev);
> amd_pmf_init_features(dev);
> @@ -394,8 +397,6 @@ static int amd_pmf_probe(struct platform_device *pdev)
> dev->pwr_src_notifier.notifier_call = amd_pmf_pwr_src_notify_call;
> power_supply_reg_notifier(&dev->pwr_src_notifier);
>
> - mutex_init(&dev->lock);
> - mutex_init(&dev->update_mutex);
> dev_info(dev->dev, "registered PMF device successfully\n");
>
> return 0;
> @@ -406,11 +407,11 @@ static int amd_pmf_remove(struct platform_device *pdev)
> struct amd_pmf_dev *dev = platform_get_drvdata(pdev);
>
> power_supply_unreg_notifier(&dev->pwr_src_notifier);
> - mutex_destroy(&dev->lock);
> - mutex_destroy(&dev->update_mutex);
> amd_pmf_deinit_features(dev);
> apmf_acpi_deinit(dev);
> amd_pmf_dbgfs_unregister(dev);
> + mutex_destroy(&dev->lock);
> + mutex_destroy(&dev->update_mutex);
> kfree(dev->buf);
> return 0;
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 6/6] platform/x86/amd/pmf: Ensure mutexes are initialized before use
2023-01-30 13:25 [PATCH 6/6] platform/x86/amd/pmf: Ensure mutexes are initialized before use Hans de Goede
2023-01-30 13:33 ` Hans de Goede
@ 2023-01-30 14:30 ` Shyam Sundar S K
1 sibling, 0 replies; 3+ messages in thread
From: Shyam Sundar S K @ 2023-01-30 14:30 UTC (permalink / raw)
To: Hans de Goede, Mark Gross, Andy Shevchenko
Cc: Mario Limonciello, platform-driver-x86
Hi,
On 1/30/2023 6:55 PM, Hans de Goede wrote:
> As soon as the first handler or sysfs file is registered
> the mutex may get used.
>
> Move the initialization to before any handler registration /
> sysfs file creation.
>
> Likewise move the destruction of the mutex to after all
> the de-initialization is done.
>
> Fixes: da5ce22df5fe ("platform/x86/amd/pmf: Add support for PMF core layer")
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Looks good to me. Thank you.
Acked-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
> ---
> drivers/platform/x86/amd/pmf/core.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c
> index c9f7bcef4ac8..da23639071d7 100644
> --- a/drivers/platform/x86/amd/pmf/core.c
> +++ b/drivers/platform/x86/amd/pmf/core.c
> @@ -385,6 +385,9 @@ static int amd_pmf_probe(struct platform_device *pdev)
> if (!dev->regbase)
> return -ENOMEM;
>
> + mutex_init(&dev->lock);
> + mutex_init(&dev->update_mutex);
> +
> apmf_acpi_init(dev);
> platform_set_drvdata(pdev, dev);
> amd_pmf_init_features(dev);
> @@ -394,8 +397,6 @@ static int amd_pmf_probe(struct platform_device *pdev)
> dev->pwr_src_notifier.notifier_call = amd_pmf_pwr_src_notify_call;
> power_supply_reg_notifier(&dev->pwr_src_notifier);
>
> - mutex_init(&dev->lock);
> - mutex_init(&dev->update_mutex);
> dev_info(dev->dev, "registered PMF device successfully\n");
>
> return 0;
> @@ -406,11 +407,11 @@ static int amd_pmf_remove(struct platform_device *pdev)
> struct amd_pmf_dev *dev = platform_get_drvdata(pdev);
>
> power_supply_unreg_notifier(&dev->pwr_src_notifier);
> - mutex_destroy(&dev->lock);
> - mutex_destroy(&dev->update_mutex);
> amd_pmf_deinit_features(dev);
> apmf_acpi_deinit(dev);
> amd_pmf_dbgfs_unregister(dev);
> + mutex_destroy(&dev->lock);
> + mutex_destroy(&dev->update_mutex);
> kfree(dev->buf);
> return 0;
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-01-30 14:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-30 13:25 [PATCH 6/6] platform/x86/amd/pmf: Ensure mutexes are initialized before use Hans de Goede
2023-01-30 13:33 ` Hans de Goede
2023-01-30 14:30 ` Shyam Sundar S K
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.