Nico Huber submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Nico Huber: Looks good to me, approved
mec1308.c: Untangle successful vs failed init paths

Label mec1308_init_exit now serves as failed init path, it does
cleanup and returns 1, so it is renamed into init_err_exit.

Since all error paths return 1, and successful init is separated
from failure, there is no need to have ret variable anymore.

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

Change-Id: Ibf35335501e59636c544af124ad7a04a186790b4
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/52596
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
---
M mec1308.c
1 file changed, 16 insertions(+), 27 deletions(-)

diff --git a/mec1308.c b/mec1308.c
index 682e7a9..641f5f8 100644
--- a/mec1308.c
+++ b/mec1308.c
@@ -426,7 +426,6 @@
uint16_t sio_port;
uint8_t device_id;
uint8_t tmp8;
- int ret = 0;
mec1308_data_t *ctx_data = NULL;

msg_pdbg("%s(): entered\n", __func__);
@@ -437,15 +436,12 @@
return 1;
}

- if (check_params()) {
- ret = 1;
- goto mec1308_init_exit;
- }
+ if (check_params())
+ goto init_err_exit;

if (mec1308_get_sio_index(ctx_data, &sio_port) < 0) {
msg_pdbg("MEC1308 not found (probe failed).\n");
- ret = 1;
- goto mec1308_init_exit;
+ goto init_err_exit;
}
device_id = sio_read(sio_port, MEC1308_DEVICE_ID_REG);
switch(device_id) {
@@ -461,8 +457,7 @@
break;
default:
msg_pdbg("MEC1308 not found\n");
- ret = 1;
- goto mec1308_init_exit;
+ goto init_err_exit;
}

/*
@@ -486,28 +481,23 @@
* command to finish.*/
if (mbx_wait(ctx_data) != 0) {
msg_perr("%s: mailbox is not available\n", __func__);
- ret = 1;
- goto mec1308_init_exit;
+ goto init_err_exit;
}

/* Further setup -- disable SMI and ACPI.
FIXME: is there an ordering dependency? */
if (mbx_write(ctx_data, MEC1308_MBX_CMD, MEC1308_CMD_ACPI_DISABLE)) {
msg_pdbg("%s: unable to disable ACPI\n", __func__);
- ret = 1;
- goto mec1308_init_exit;
+ goto init_err_exit;
}

if (mbx_write(ctx_data, MEC1308_MBX_CMD, MEC1308_CMD_SMI_DISABLE)) {
msg_pdbg("%s: unable to disable SMI\n", __func__);
- ret = 1;
- goto mec1308_init_exit;
+ goto init_err_exit;
}

- if (register_shutdown(mec1308_shutdown, ctx_data)) {
- ret = 1;
- goto mec1308_init_exit;
- }
+ if (register_shutdown(mec1308_shutdown, ctx_data))
+ goto init_err_exit;

/*
* Enter SPI Pass-Thru Mode after commands which do not require access
@@ -516,19 +506,18 @@
*/
mec1308_exit_passthru_mode(ctx_data);

- if (enter_passthru_mode(ctx_data)) {
- ret = 1;
- goto mec1308_init_exit;
- }
+ if (enter_passthru_mode(ctx_data))
+ goto init_err_exit;

internal_buses_supported |= BUS_LPC; /* for LPC <--> SPI bridging */
spi_master_mec1308.data = ctx_data;
register_spi_master(&spi_master_mec1308);
msg_pdbg("%s(): successfully initialized mec1308\n", __func__);

-mec1308_init_exit:
- if (ret)
- free(ctx_data);
- return ret;
+ return 0;
+
+init_err_exit:
+ free(ctx_data);
+ return 1;
}
#endif

To view, visit change 52596. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ibf35335501e59636c544af124ad7a04a186790b4
Gerrit-Change-Number: 52596
Gerrit-PatchSet: 4
Gerrit-Owner: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Miklós Márton <martonmiklosqdev@gmail.com>
Gerrit-CC: Victor Ding <victording@google.com>
Gerrit-MessageType: merged