mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 10/10] common: bootm: use switch-case
Date: Mon, 10 Oct 2022 08:11:22 +0200	[thread overview]
Message-ID: <20221010061122.2084009-11-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20221010061122.2084009-1-a.fatoum@pengutronix.de>

The switch statement is more readable and lends itself to be easily
extended for future file types, e.g. PE/COFF for EFI loading.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/bootm.c | 47 +++++++++++++++++++++++------------------------
 1 file changed, 23 insertions(+), 24 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index f507aece8c18..fb1ed36a26dc 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -577,16 +577,19 @@ static int bootm_open_fit(struct image_data *data)
 
 static int bootm_open_elf(struct image_data *data)
 {
+	struct elf_image *elf;
+
 	if (!IS_ENABLED(CONFIG_ELF))
 		return -ENOSYS;
 
-	data->elf = elf_open(data->os_file);
-	if (IS_ERR(data->elf))
-		return PTR_ERR(data->elf);
+	elf = elf_open(data->os_file);
+	if (IS_ERR(elf))
+		return PTR_ERR(elf);
 
-	pr_info("Entry Point:  %08llx\n", data->elf->entry);
+	pr_info("Entry Point:  %08llx\n", elf->entry);
 
-	data->os_address = data->elf->entry;
+	data->os_address = elf->entry;
+	data->elf = elf;
 
 	return 0;
 }
@@ -689,29 +692,25 @@ int bootm_boot(struct bootm_data *bootm_data)
 		}
 	}
 
-	if (os_type == filetype_oftree) {
+	switch (os_type) {
+	case filetype_oftree:
 		ret = bootm_open_fit(data);
-		if (ret)
-			return ret;
-	}
-
-	if (os_type == filetype_uimage) {
+		break;
+	case filetype_uimage:
 		ret = bootm_open_os_uimage(data);
-		if (ret) {
-			pr_err("Loading OS image failed with: %s\n",
-			       strerror(-ret));
-			goto err_out;
-		}
+		break;
+	case filetype_elf:
+		ret = bootm_open_elf(data);
+		break;
+	default:
+		ret = 0;
+		break;
 	}
 
-	if (os_type == filetype_elf) {
-		ret = bootm_open_elf(data);
-		if (ret) {
-			pr_err("Loading ELF image failed with: %s\n",
-			       strerror(-ret));
-			data->elf = NULL;
-			goto err_out;
-		}
+	if (ret) {
+		pr_err("Loading %s image failed with: %pe\n",
+		       file_type_to_short_string(os_type), ERR_PTR(ret));
+		goto err_out;
 	}
 
 	if (bootm_data->appendroot) {
-- 
2.30.2




  parent reply	other threads:[~2022-10-10  6:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-10  6:11 [PATCH 00/10] treewide: misc cleanup for efiloader prep Ahmad Fatoum
2022-10-10  6:11 ` [PATCH 01/10] block: have cdev_get_block_device accept const cdev Ahmad Fatoum
2022-10-10  6:11 ` [PATCH 02/10] treewide: replace errno_str() with %m printf format specifier Ahmad Fatoum
2022-10-10  6:11 ` [PATCH 03/10] common: misc: remove now unused errno_str Ahmad Fatoum
2022-10-10  6:11 ` [PATCH 04/10] driver: don't crash when dev_name/dev_id is called with NULL dev Ahmad Fatoum
2022-10-10  6:11 ` [PATCH 05/10] lds: introduce <asm/barebox.lds.h> Ahmad Fatoum
2022-10-10  6:11 ` [PATCH 06/10] lds: move OUTPUT_FORMAT/ARCH definition into header Ahmad Fatoum
2022-10-10  6:11 ` [PATCH 07/10] ARM: lds: define and use BAREBOX_RELOCATION_TABLE Ahmad Fatoum
2022-10-10  6:11 ` [PATCH 08/10] lib: random: add hwrng_get_crypto_bytes Ahmad Fatoum
2022-10-10  6:11 ` [PATCH 09/10] common: bootm: factor out FIT parsing code into bootm_open_bit Ahmad Fatoum
2022-10-10  6:11 ` Ahmad Fatoum [this message]
2022-10-11 14:46 ` [PATCH 00/10] treewide: misc cleanup for efiloader prep Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221010061122.2084009-11-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox