1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 15:12:36 +02:00

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 <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/65240
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
This commit is contained in:
Anastasia Klimchuk 2022-06-20 13:31:21 +10:00
parent 970f9481ae
commit 6f610a8391

View File

@ -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;
}