nicintel_eeprom: Check UNPROG_DEVICE in 82580 shutdown
Previously shutdown function was registered conditionally for 82580,
only if the device was not UNPROG_DEVICE. This patch moves the check
for UNPROG_DEVICE into shutdown function itself, so that shutdown
function can be always registered for 82580.
This also fixes a memory leak in nicintel_ee_shutdown_82580.
No changes for i210 device init/shutdown, only for 82580.
And very importantly this unlocks API change which plans to move
register_shutdown inside register_opaque_master, similar to what's
done in CB:56103
Change-Id: I5c729a3a63d0106e65525a6a77b2f9104c96847f
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/56821
Original-Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Original-Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72227
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/nicintel_eeprom.c b/nicintel_eeprom.c
index 33c0b0f..6c18848 100644
--- a/nicintel_eeprom.c
+++ b/nicintel_eeprom.c
@@ -435,18 +435,26 @@
static int nicintel_ee_shutdown_82580(void *eecp)
{
- uint32_t old_eec = *(uint32_t *)eecp;
- /* Request bitbanging and unselect the chip first to be safe. */
- if (nicintel_ee_req() || nicintel_ee_bitset(EEC, EE_CS, 1))
- return -1;
+ int ret = 0;
- /* Try to restore individual bits we care about. */
- int ret = nicintel_ee_bitset(EEC, EE_SCK, old_eec & BIT(EE_SCK));
- ret |= nicintel_ee_bitset(EEC, EE_SI, old_eec & BIT(EE_SI));
- ret |= nicintel_ee_bitset(EEC, EE_CS, old_eec & BIT(EE_CS));
- /* REQ will be cleared by hardware anyway after 2 seconds of inactivity on the SPI pins (3.3.2.1). */
- ret |= nicintel_ee_bitset(EEC, EE_REQ, old_eec & BIT(EE_REQ));
+ if (nicintel_pci->device_id != UNPROG_DEVICE) {
+ uint32_t old_eec = *(uint32_t *)eecp;
+ /* Request bitbanging and unselect the chip first to be safe. */
+ if (nicintel_ee_req() || nicintel_ee_bitset(EEC, EE_CS, 1)) {
+ ret = -1;
+ goto out;
+ }
+ /* Try to restore individual bits we care about. */
+ ret = nicintel_ee_bitset(EEC, EE_SCK, old_eec & BIT(EE_SCK));
+ ret |= nicintel_ee_bitset(EEC, EE_SI, old_eec & BIT(EE_SI));
+ ret |= nicintel_ee_bitset(EEC, EE_CS, old_eec & BIT(EE_CS));
+ /* REQ will be cleared by hardware anyway after 2 seconds of inactivity
+ * on the SPI pins (3.3.2.1). */
+ ret |= nicintel_ee_bitset(EEC, EE_REQ, old_eec & BIT(EE_REQ));
+ }
+
+out:
free(eecp);
return ret;
}
@@ -469,6 +477,8 @@
if (!nicintel_eebar)
return 1;
+ uint32_t *eecp = NULL;
+
nicintel_pci = dev;
if (dev->device_id != UNPROG_DEVICE) {
uint32_t eec = pci_mmio_readl(nicintel_eebar + EEC);
@@ -481,15 +491,15 @@
return 1;
}
- uint32_t *eecp = malloc(sizeof(uint32_t));
+ eecp = malloc(sizeof(uint32_t));
if (eecp == NULL)
return 1;
*eecp = eec;
-
- if (register_shutdown(nicintel_ee_shutdown_82580, eecp))
- return 1;
}
+ if (register_shutdown(nicintel_ee_shutdown_82580, eecp))
+ return 1;
+
return register_opaque_master(&opaque_master_nicintel_ee_82580, NULL);
} else {
nicintel_eebar = rphysmap("Intel i210 NIC w/ emulated EEPROM",