Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

platform/x86/amd/pmf: Ensure mutexes are initialized before use

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>
Link: https://lore.kernel.org/r/20230130132554.696025-1-hdegoede@redhat.com

+5 -4
+5 -4
drivers/platform/x86/amd/pmf/core.c
··· 385 385 if (!dev->regbase) 386 386 return -ENOMEM; 387 387 388 + mutex_init(&dev->lock); 389 + mutex_init(&dev->update_mutex); 390 + 388 391 apmf_acpi_init(dev); 389 392 platform_set_drvdata(pdev, dev); 390 393 amd_pmf_init_features(dev); ··· 397 394 dev->pwr_src_notifier.notifier_call = amd_pmf_pwr_src_notify_call; 398 395 power_supply_reg_notifier(&dev->pwr_src_notifier); 399 396 400 - mutex_init(&dev->lock); 401 - mutex_init(&dev->update_mutex); 402 397 dev_info(dev->dev, "registered PMF device successfully\n"); 403 398 404 399 return 0; ··· 407 406 struct amd_pmf_dev *dev = platform_get_drvdata(pdev); 408 407 409 408 power_supply_unreg_notifier(&dev->pwr_src_notifier); 410 - mutex_destroy(&dev->lock); 411 - mutex_destroy(&dev->update_mutex); 412 409 amd_pmf_deinit_features(dev); 413 410 apmf_acpi_deinit(dev); 414 411 amd_pmf_dbgfs_unregister(dev); 412 + mutex_destroy(&dev->lock); 413 + mutex_destroy(&dev->update_mutex); 415 414 kfree(dev->buf); 416 415 return 0; 417 416 }