summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-06-02 11:01:28 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-06-03 09:17:27 +0200
commit109e95cce7c77d8401d393831d26b33655759318 (patch)
treee9c3fbedb54b3793ad6c199dbc4b62a2217ec4d7 /common
parent960535d9bf19cb1a26517cf792c708743ec811b7 (diff)
downloadbarebox-109e95cce7c77d8401d393831d26b33655759318.tar.gz
barebox-109e95cce7c77d8401d393831d26b33655759318.tar.xz
bbu: use free(NULL) to simplify function cleanup
We will add a third allocated string in a follow up commit, so instead of having a third label to selectively free it, just initialize all the pointers to NULL and free them unconditionally to simplify the code. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220602090133.3190450-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/bbu.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/common/bbu.c b/common/bbu.c
index 6a47b21a55..4d92d70ff9 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -310,9 +310,8 @@ int bbu_mmcboot_handler(struct bbu_handler *handler, struct bbu_data *data,
{
struct bbu_data _data = *data;
int ret;
- char *bootpartvar;
+ char *devicefile = NULL, *bootpartvar = NULL;
const char *bootpart;
- char *devicefile;
const char *devname = devpath_to_name(data->devicefile);
ret = device_detect_by_name(devname);
@@ -328,7 +327,7 @@ int bbu_mmcboot_handler(struct bbu_handler *handler, struct bbu_data *data,
bootpart = getenv(bootpartvar);
if (!bootpart) {
ret = -ENOENT;
- goto free_bootpartvar;
+ goto out;
}
if (!strcmp(bootpart, "boot0")) {
@@ -339,21 +338,19 @@ int bbu_mmcboot_handler(struct bbu_handler *handler, struct bbu_data *data,
ret = asprintf(&devicefile, "/dev/%s.%s", devname, bootpart);
if (ret < 0)
- goto free_bootpartvar;
+ goto out;
_data.devicefile = devicefile;
ret = chained_handler(handler, &_data);
if (ret < 0)
- goto free_devicefile;
+ goto out;
/* on success switch boot source */
ret = setenv(bootpartvar, bootpart);
-free_devicefile:
+out:
free(devicefile);
-
-free_bootpartvar:
free(bootpartvar);
return ret;