Nico Huber submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Angel Pons: Looks good to me, approved Edward O'Callaghan: Looks good to me, approved
linux_mtd: Free param right after its last usage

Param is only used in the first half of init function, and it is
local, so there is no need to keep it until the end. This makes
handling error paths in the second half of init function shorter,
because those paths can just return 1 instead of going to a label.

BUG=b:185191942
TEST=builds and ninja test from CB:56413

Change-Id: I126a8d06297ef4d42bc93a73f7067ccc1352d1e9
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56822
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
---
M linux_mtd.c
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/linux_mtd.c b/linux_mtd.c
index 284cde4..7780feb 100644
--- a/linux_mtd.c
+++ b/linux_mtd.c
@@ -404,27 +404,29 @@
msg_pdbg("%s does not exist\n", sysfs_path);
goto linux_mtd_init_exit;
}
+ free(param);

data = calloc(1, sizeof(*data));
if (!data) {
msg_perr("Unable to allocate memory for linux_mtd_data\n");
- goto linux_mtd_init_exit;
+ return 1;
}

/* Get MTD info and store it in `data` */
if (linux_mtd_setup(dev_num, data)) {
free(data);
- goto linux_mtd_init_exit;
+ return 1;
}

if (register_shutdown(linux_mtd_shutdown, (void *)data)) {
free(data);
- goto linux_mtd_init_exit;
+ return 1;
}

register_opaque_master(&linux_mtd_opaque_master, data);

- ret = 0;
+ return 0;
+
linux_mtd_init_exit:
free(param);
return ret;

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I126a8d06297ef4d42bc93a73f7067ccc1352d1e9
Gerrit-Change-Number: 56822
Gerrit-PatchSet: 2
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: Paul Menzel <paulepanter@mailbox.org>
Gerrit-MessageType: merged