opaque_master: Use new API to register shutdown function
This allows opaque masters to register shutdown function in
opaque_master struct, which means there is no need to call
register_shutdown in init function, since this call is now a part
of register_opaque_master.
As a consequence of using new API, two things are happening here:
1) No resource leakage anymore in case register_shutdown() would fail,
2) Fixed propagation of register_opaque_master() return values.
Tested: 1) builds and ninja test including CB:56413
2) on ARMv7 device
flashrom -p linux_mtd -V
-> using linux_mtd, chip found
Change-Id: Id8471a117556edcbf9694752fabe05cf4501ce70
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/56825
Original-Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72230
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/linux_mtd.c b/linux_mtd.c
index 2f8bac5..b55cdc1 100644
--- a/linux_mtd.c
+++ b/linux_mtd.c
@@ -298,6 +298,8 @@
return 0;
}
+static int linux_mtd_shutdown(void *data);
+
static const struct opaque_master linux_mtd_opaque_master = {
/* max_data_{read,write} don't have any effect for this programmer */
.max_data_read = MAX_DATA_UNSPECIFIED,
@@ -306,6 +308,7 @@
.read = linux_mtd_read,
.write = linux_mtd_write,
.erase = linux_mtd_erase,
+ .shutdown = linux_mtd_shutdown,
};
/* Returns 0 if setup is successful, non-zero to indicate error */
@@ -421,14 +424,7 @@
return 1;
}
- if (register_shutdown(linux_mtd_shutdown, (void *)data)) {
- free(data);
- return 1;
- }
-
- register_opaque_master(&linux_mtd_opaque_master, data);
-
- return 0;
+ return register_opaque_master(&linux_mtd_opaque_master, data);
linux_mtd_init_exit:
free(param);
diff --git a/nicintel_eeprom.c b/nicintel_eeprom.c
index 6c18848..a8b9333 100644
--- a/nicintel_eeprom.c
+++ b/nicintel_eeprom.c
@@ -395,18 +395,24 @@
return nicintel_ee_write_82580(flash, NULL, addr, len);
}
+static int nicintel_ee_shutdown_82580(void *eecp);
+
static const struct opaque_master opaque_master_nicintel_ee_82580 = {
.probe = nicintel_ee_probe_82580,
.read = nicintel_ee_read,
.write = nicintel_ee_write_82580,
.erase = nicintel_ee_erase_82580,
+ .shutdown = nicintel_ee_shutdown_82580,
};
+static int nicintel_ee_shutdown_i210(void *arg);
+
static const struct opaque_master opaque_master_nicintel_ee_i210 = {
.probe = nicintel_ee_probe_i210,
.read = nicintel_ee_read,
.write = nicintel_ee_write_i210,
.erase = nicintel_ee_erase_i210,
+ .shutdown = nicintel_ee_shutdown_i210,
};
static int nicintel_ee_shutdown_i210(void *arg)
@@ -497,19 +503,13 @@
*eecp = eec;
}
- if (register_shutdown(nicintel_ee_shutdown_82580, eecp))
- return 1;
-
- return register_opaque_master(&opaque_master_nicintel_ee_82580, NULL);
+ return register_opaque_master(&opaque_master_nicintel_ee_82580, eecp);
} else {
nicintel_eebar = rphysmap("Intel i210 NIC w/ emulated EEPROM",
io_base_addr + 0x12000, MEMMAP_SIZE);
if (!nicintel_eebar)
return 1;
- if (register_shutdown(nicintel_ee_shutdown_i210, NULL))
- return 1;
-
return register_opaque_master(&opaque_master_nicintel_ee_i210, NULL);
}