chipset_enable: Fix memory leaks introduced with AMD SPI100

The libpci function pci_get_dev() allocates a device struct that
needs to be free'd with pci_free_dev() manually.

Change-Id: Ic14f0931beb660b05cfe3f6e6d43b649dce8fff4
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/242
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
diff --git a/chipset_enable.c b/chipset_enable.c
index 1abc828..5883747 100644
--- a/chipset_enable.c
+++ b/chipset_enable.c
@@ -1425,7 +1425,10 @@
 		return ERROR_FATAL;
 	}
 
-	return enable_flash_sb600(prog, lpc, name);
+	const int ret = enable_flash_sb600(prog, lpc, name);
+
+	pci_free_dev(lpc);
+	return ret;
 }
 
 static int enable_flash_amd_spi100(struct flashprog_programmer *prog, struct pci_dev *const smbus, const char *const name)
@@ -1439,6 +1442,7 @@
 	const uint32_t spibar = pci_read_long(lpc, 0xa0);
 	if (spibar == 0xffffffff) {
 		msg_perr("SPI100 BAR reads all `ff', aborting.\n");
+		pci_free_dev(lpc);
 		return ERROR_FATAL;
 	}
 
@@ -1446,6 +1450,8 @@
 	msg_pdbg(", AbortEnable=%u, RouteTpm2Spi=%u", spibar >> 2 & 1, spibar >> 3 & 1);
 	msg_pdbg(", PspSpiMmioSel=%u\n", spibar >> 4 & 1);
 
+	pci_free_dev(lpc);
+
 	const bool spirom_enable = spibar & BIT(1);
 	if (spirom_enable) {
 		/* If SPI ROM is memory mapped, nothing else can be */