From: Simon Glass Date: Mon, 15 Mar 2021 18:11:08 +1300 Subject: [PATCH 03/19] sandbox: cros_ec: Only write EC state when the EC is probed In-Reply-To: <20210315051124.1940496-1-sjg@chromium.org> References: <20210315051124.1940496-1-sjg@chromium.org> Message-ID: <20210315051124.1940496-2-sjg@chromium.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de This can crash if the EC has not yet been probed. Add a check to prevent this. Signed-off-by: Simon Glass --- drivers/misc/cros_ec_sandbox.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c index cb8adc4495a..bc01df0904e 100644 --- a/drivers/misc/cros_ec_sandbox.c +++ b/drivers/misc/cros_ec_sandbox.c @@ -153,10 +153,14 @@ static int cros_ec_write_state(void *blob, int node) { struct ec_state *ec = g_state; + if (!g_state) + return 0; + /* We are guaranteed enough space to write basic properties */ fdt_setprop_u32(blob, node, "current-image", ec->current_image); fdt_setprop(blob, node, "vbnv-context", ec->vbnv_context, sizeof(ec->vbnv_context)); + return state_setprop(node, "flash-data", ec->flash_data, ec->ec_config.flash.length); } -- 2.31.0.rc2.261.g7f71774620-goog