Anastasia Klimchuk has uploaded this change for review.

View Change

mec1308.c: Untangle successful vs failed init paths

Label mec1308_init_exit now serves as failed init path,
it does cleanup and returns 1.

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>
---
M mec1308.c
1 file changed, 7 insertions(+), 18 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/96/52596/1
diff --git a/mec1308.c b/mec1308.c
index 682e7a9..c3b555d 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,14 +436,11 @@
return 1;
}

- if (check_params()) {
- ret = 1;
+ if (check_params())
goto mec1308_init_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;
}
device_id = sio_read(sio_port, MEC1308_DEVICE_ID_REG);
@@ -461,7 +457,6 @@
break;
default:
msg_pdbg("MEC1308 not found\n");
- ret = 1;
goto mec1308_init_exit;
}

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

@@ -494,20 +488,16 @@
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;
}

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

- if (register_shutdown(mec1308_shutdown, ctx_data)) {
- ret = 1;
+ if (register_shutdown(mec1308_shutdown, ctx_data))
goto mec1308_init_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;
+ if (enter_passthru_mode(ctx_data))
goto mec1308_init_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__);

+ return 0;
+
mec1308_init_exit:
- if (ret)
- free(ctx_data);
- return ret;
+ 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: 1
Gerrit-Owner: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-MessageType: newchange