From 1e01eefcba573c436d55b863c7972b3029564215 Mon Sep 17 00:00:00 2001 From: Edward O'Callaghan Date: Mon, 17 Oct 2022 12:31:59 +1100 Subject: tree/: Replace NULL-case of programmer_delay() with internal_delay Replace `programmer_delay(NULL, [..])` calls with direct `internal_delay([..])` dispatches explicitly. Custom driver delays remain hooked as well as core flashrom logic. The NULL base case of 'programmer_delay()' then becomes a condition to validate for layering violations or invalid flash contexts. Change-Id: I1da230804d5e8f47a6e281feb66f381514dc6861 Signed-off-by: Edward O'Callaghan Reviewed-on: https://review.coreboot.org/c/flashrom/+/68434 Reviewed-by: Anastasia Klimchuk Tested-by: build bot (Jenkins) --- flashrom.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'flashrom.c') diff --git a/flashrom.c b/flashrom.c index d0f0d2d4..3e75eb35 100644 --- a/flashrom.c +++ b/flashrom.c @@ -259,8 +259,20 @@ void programmer_delay(const struct flashctx *flash, unsigned int usecs) if (usecs == 0) return; - if (!flash) + /** + * Drivers should either use internal_delay() directly or their + * own custom delay. Only core flashrom logic calls programmer_delay() + * which should always have a valid flash context. A NULL context + * more than likely indicates a layering violation or BUG however + * for now dispatch a internal_delay() as a safe default for the NULL + * base case. + */ + if (!flash) { + msg_perr("%s called with NULL flash context. " + "Please report a bug at flashrom@flashrom.org\n", + __func__); return internal_delay(usecs); + } if (flash->mst->buses_supported & BUS_SPI) { if (flash->mst->spi.delay) -- cgit v1.2.3