spi_master: Add shutdown function in spi_master struct
With this, register_spi_master can take care of register_shutdown
as well, and every spi master only needs to call register_spi_master
instead of calling both register_spi_master and register_shutdown.
Testing:
In dummyflasher, comment out free(data) in shutdown. Test fails with error:
../dummyflasher.c:949: note: block 0x55e0727a6e40 allocated here
ERROR: dummy_init_and_shutdown_test_success leaked 1 block(s)
Means, shutdown function is invoked for drivers with "old" API
(so, transitioning from old to new API is not breaking anything).
Next patches in the chain converts spi masters to use new API.
Tested: builds and ninja test
Change-Id: I2dc80dceca2f8204bcd0dad1f51753d7e79f1af5
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/55932
Original-Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72226
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/programmer.h b/programmer.h
index 97c3a8a..4aa9eda 100644
--- a/programmer.h
+++ b/programmer.h
@@ -319,6 +319,7 @@
int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
int (*write_aai)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
+ int (*shutdown)(void *data);
void *data;
};
diff --git a/spi.c b/spi.c
index 5ee9a24..b7a7a21 100644
--- a/spi.c
+++ b/spi.c
@@ -133,6 +133,13 @@
{
struct registered_master rmst;
+ if (mst->shutdown) {
+ if (register_shutdown(mst->shutdown, data)) {
+ mst->shutdown(data); /* cleanup */
+ return 1;
+ }
+ }
+
if (!mst->write_aai || !mst->write_256 || !mst->read || !mst->command ||
!mst->multicommand ||
((mst->command == default_spi_send_command) &&