1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-29 16:03:47 +02:00

mec1308.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.

TEST=builds and ninja test from 51487
BUG=b:185191942

Change-Id: If5be7709e93233a2e7ea9133de50382d2524a55f
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/52595
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-21 15:19:24 +10:00 committed by Nico Huber
parent 62fb7649c8
commit 914aa7e60e

View File

@ -406,13 +406,27 @@ static struct spi_master spi_master_mec1308 = {
.write_256 = default_spi_write_256, .write_256 = default_spi_write_256,
}; };
static int check_params(void)
{
int ret = 0;
char *p = NULL;
p = extract_programmer_param("type");
if (p && strcmp(p, "ec")) {
msg_pdbg("mec1308 only supports \"ec\" type devices\n");
ret = 1;
}
free(p);
return ret;
}
int mec1308_init(void) int mec1308_init(void)
{ {
uint16_t sio_port; uint16_t sio_port;
uint8_t device_id; uint8_t device_id;
uint8_t tmp8; uint8_t tmp8;
int ret = 0; int ret = 0;
char *p = NULL;
mec1308_data_t *ctx_data = NULL; mec1308_data_t *ctx_data = NULL;
msg_pdbg("%s(): entered\n", __func__); msg_pdbg("%s(): entered\n", __func__);
@ -423,9 +437,7 @@ int mec1308_init(void)
return 1; return 1;
} }
p = extract_programmer_param("type"); if (check_params()) {
if (p && strcmp(p, "ec")) {
msg_pdbg("mec1308 only supports \"ec\" type devices\n");
ret = 1; ret = 1;
goto mec1308_init_exit; goto mec1308_init_exit;
} }
@ -515,7 +527,6 @@ int mec1308_init(void)
msg_pdbg("%s(): successfully initialized mec1308\n", __func__); msg_pdbg("%s(): successfully initialized mec1308\n", __func__);
mec1308_init_exit: mec1308_init_exit:
free(p);
if (ret) if (ret)
free(ctx_data); free(ctx_data);
return ret; return ret;