1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-28 15:33:42 +02:00

ene_lpc.c: Extract params check into a function

This allows char *p to become a local variable in check_params,
and it is allocated and freed within check_params function.
Which means init function does not need char *p anymore,
in particular does not need to free it - and this makes cleanup
after failed init easier.

As a good side effect, init function becomes easier to read.

BUG=b:185191942
TEST=builds

Change-Id: I7c3b6dea0edbc7547f0b307a0508c7d2b2a6d370
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/52684
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Nico Huber <nico.h@gmx.de>
This commit is contained in:
Anastasia Klimchuk 2021-04-28 10:08:15 +10:00 committed by Nico Huber
parent 45d50a101e
commit 04fff28b46

View File

@ -513,11 +513,23 @@ static struct spi_master spi_master_ene = {
.write_256 = default_spi_write_256, .write_256 = default_spi_write_256,
}; };
static int check_params(void)
{
int ret = 0;
char *const p = extract_programmer_param("type");
if (p && strcmp(p, "ec")) {
msg_pdbg("ene_lpc only supports \"ec\" type devices\n");
ret = 1;
}
free(p);
return ret;
}
int ene_lpc_init() int ene_lpc_init()
{ {
uint8_t hwver, ediid, i; uint8_t hwver, ediid, i;
int ret = 0; int ret = 0;
char *p = NULL;
ene_lpc_data_t *ctx_data = NULL; ene_lpc_data_t *ctx_data = NULL;
msg_pdbg("%s\n", __func__); msg_pdbg("%s\n", __func__);
@ -529,9 +541,7 @@ int ene_lpc_init()
} }
ctx_data->ec_state = EC_STATE_NORMAL; ctx_data->ec_state = EC_STATE_NORMAL;
p = extract_programmer_param("type"); if (check_params()) {
if (p && strcmp(p, "ec")) {
msg_pdbg("ene_lpc only supports \"ec\" type devices\n");
ret = 1; ret = 1;
goto ene_probe_spi_flash_exit; goto ene_probe_spi_flash_exit;
} }
@ -572,7 +582,6 @@ int ene_lpc_init()
msg_pdbg("%s: successfully initialized ene\n", __func__); msg_pdbg("%s: successfully initialized ene\n", __func__);
ene_probe_spi_flash_exit: ene_probe_spi_flash_exit:
free(p);
if (ret) if (ret)
free(ctx_data); free(ctx_data);
return ret; return ret;