Anastasia Klimchuk has uploaded this change for review.
[RFC] 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.
This is alternative approach to CB:51761 which does not require
adding another argument to register_spi_master.
Testing: when I comment out free(data) in linux_spi_shutdown, test
fails with error
../linux_spi.c:235: note: block 0x55a4db276510 allocated here
ERROR: linux_spi_init_and_shutdown_test_success leaked 1 block(s)
Means, shutdown function is invoked.
Same for dummy: comment out free(data) in shutdown. It is also caught
in test
../dummyflasher.c:949: note: block 0x55e0727a6e40 allocated here
ERROR: dummy_init_and_shutdown_test_success leaked 1 block(s)
Means, shutdown function is invoked even for drivers with "old" API
(so, transition from old to new is not breaking anything).
Change-Id: I2dc80dceca2f8204bcd0dad1f51753d7e79f1af5
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
---
M linux_spi.c
M programmer.h
M spi.c
3 files changed, 10 insertions(+), 5 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/32/55932/1
diff --git a/linux_spi.c b/linux_spi.c
index 46779a0..16a83af 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -122,6 +122,7 @@
.read = linux_spi_read,
.write_256 = linux_spi_write_256,
.write_aai = default_spi_write_aai,
+ .shutdown = linux_spi_shutdown,
};
/* Read max buffer size from sysfs, or use page size as fallback. */
@@ -239,11 +240,8 @@
spi_data->fd = fd;
spi_data->max_kernel_buf_size = max_kernel_buf_size;
- if (register_shutdown(linux_spi_shutdown, spi_data)) {
- free(spi_data);
- goto init_err;
- }
- register_spi_master(&spi_master_linux, spi_data);
+ if (register_spi_master(&spi_master_linux, spi_data))
+ return 1; /* core does cleanup */
return 0;
init_err:
diff --git a/programmer.h b/programmer.h
index 95e2cda..ec55987 100644
--- a/programmer.h
+++ b/programmer.h
@@ -356,6 +356,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 4ac3914..99d036e 100644
--- a/spi.c
+++ b/spi.c
@@ -135,6 +135,12 @@
{
struct registered_master rmst = {0};
+ 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) &&
To view, visit change 55932. To unsubscribe, or for help writing mail filters, visit settings.