mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-09 04:10:18 +09:00
tpm: Add a helper for checking hwrng enabled
commitcacc6e2293upstream. The same checks are repeated in three places to decide whether to use hwrng. Consolidate these into a helper. Also this fixes a case that one of them was missing a check in the cleanup path. Fixes:554b841d47("tpm: Disable RNG for all AMD fTPMs") Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
d8a7d6136c
commit
ccb1700ed6
@@ -518,10 +518,20 @@ static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
|
|||||||
return tpm_get_random(chip, data, max);
|
return tpm_get_random(chip, data, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool tpm_is_hwrng_enabled(struct tpm_chip *chip)
|
||||||
|
{
|
||||||
|
if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM))
|
||||||
|
return false;
|
||||||
|
if (tpm_is_firmware_upgrade(chip))
|
||||||
|
return false;
|
||||||
|
if (chip->flags & TPM_CHIP_FLAG_HWRNG_DISABLED)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static int tpm_add_hwrng(struct tpm_chip *chip)
|
static int tpm_add_hwrng(struct tpm_chip *chip)
|
||||||
{
|
{
|
||||||
if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM) || tpm_is_firmware_upgrade(chip) ||
|
if (!tpm_is_hwrng_enabled(chip))
|
||||||
chip->flags & TPM_CHIP_FLAG_HWRNG_DISABLED)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
snprintf(chip->hwrng_name, sizeof(chip->hwrng_name),
|
snprintf(chip->hwrng_name, sizeof(chip->hwrng_name),
|
||||||
@@ -626,7 +636,7 @@ int tpm_chip_register(struct tpm_chip *chip)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_hwrng:
|
out_hwrng:
|
||||||
if (IS_ENABLED(CONFIG_HW_RANDOM_TPM) && !tpm_is_firmware_upgrade(chip))
|
if (tpm_is_hwrng_enabled(chip))
|
||||||
hwrng_unregister(&chip->hwrng);
|
hwrng_unregister(&chip->hwrng);
|
||||||
out_ppi:
|
out_ppi:
|
||||||
tpm_bios_log_teardown(chip);
|
tpm_bios_log_teardown(chip);
|
||||||
@@ -651,8 +661,7 @@ EXPORT_SYMBOL_GPL(tpm_chip_register);
|
|||||||
void tpm_chip_unregister(struct tpm_chip *chip)
|
void tpm_chip_unregister(struct tpm_chip *chip)
|
||||||
{
|
{
|
||||||
tpm_del_legacy_sysfs(chip);
|
tpm_del_legacy_sysfs(chip);
|
||||||
if (IS_ENABLED(CONFIG_HW_RANDOM_TPM) && !tpm_is_firmware_upgrade(chip) &&
|
if (tpm_is_hwrng_enabled(chip))
|
||||||
!(chip->flags & TPM_CHIP_FLAG_HWRNG_DISABLED))
|
|
||||||
hwrng_unregister(&chip->hwrng);
|
hwrng_unregister(&chip->hwrng);
|
||||||
tpm_bios_log_teardown(chip);
|
tpm_bios_log_teardown(chip);
|
||||||
if (chip->flags & TPM_CHIP_FLAG_TPM2 && !tpm_is_firmware_upgrade(chip))
|
if (chip->flags & TPM_CHIP_FLAG_TPM2 && !tpm_is_firmware_upgrade(chip))
|
||||||
|
|||||||
Reference in New Issue
Block a user