From 6f610a83918b9b1fe9d58578d0d9a8e51a407d6e Mon Sep 17 00:00:00 2001 From: Anastasia Klimchuk Date: Mon, 20 Jun 2022 13:31:21 +1000 Subject: [PATCH] dummyflasher: Handle invalid value of freq parameter 0 is an invalid value for freq parameter and caused floating point exception. This patch checks that freq is not 0 during initialisation. Fixes: https://ticket.coreboot.org/issues/366 TEST=the following scenarios 1) error $ ./flashrom -p dummy:emulate=W25Q128FV,freq=0 -V <...> init_data: invalid value 0 for freq parameter Unhandled programmer parameters (possibly due to another failure): emulate=W25Q128FV, Error: Programmer initialization failed. 2) successful $ ./flashrom -p dummy:emulate=W25Q128FV,freq=10 -V Found Winbond flash chip "W25Q128.V" (16384 kB, SPI). 3) default is also successful $ ./flashrom -p dummy:emulate=W25Q128FV -V Found Winbond flash chip "W25Q128.V" (16384 kB, SPI). Change-Id: I0a95495de0a677f0d4d7f4c2fc61dcbc00d6ad4c Signed-off-by: Anastasia Klimchuk Reviewed-on: https://review.coreboot.org/c/flashrom/+/65240 Tested-by: build bot (Jenkins) Reviewed-by: Edward O'Callaghan Reviewed-by: Felix Singer --- dummyflasher.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dummyflasher.c b/dummyflasher.c index b56350e7e..603e545e3 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -1102,6 +1102,11 @@ static int init_data(struct emu_data *data, enum chipbustype *dummy_buses_suppor } } + if (freq == 0) { + msg_perr("%s: invalid value 0 for freq parameter\n", __func__); + free(tmp); + return 1; + } /* Assume we only work with bytes and transfer at 1 bit/Hz */ data->delay_us = (1000000 * 8) / freq; }