iommu/amd: Only free resources once on init error
authorKevin Mitchell <kevmitch@arista.com>
Wed, 12 Jun 2019 21:52:05 +0000 (14:52 -0700)
committerJoerg Roedel <jroedel@suse.de>
Mon, 1 Jul 2019 12:03:07 +0000 (14:03 +0200)
commit5c90501a7290e8066a5530f491e764730791945a
tree13d2f56acf1122762ca7b7fcde9c382d72a9ad67
parentbf4bff46eac151c3fd299741d71c4216e45b5d8b
iommu/amd: Only free resources once on init error

When amd_iommu=off was specified on the command line, free_X_resources
functions were called immediately after early_amd_iommu_init. They were
then called again when amd_iommu_init also failed (as expected).

Instead, call them only once: at the end of state_next() whenever
there's an error. These functions should be safe to call any time and
any number of times. However, since state_next is never called again in
an error state, the cleanup will only ever be run once.

This also ensures that cleanup code is run as soon as possible after an
error is detected rather than waiting for amd_iommu_init() to be called.

Signed-off-by: Kevin Mitchell <kevmitch@arista.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/amd_iommu_init.c