summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Deacon <will.deacon@arm.com>2018-12-06 15:02:45 +0000
committerWill Deacon <will.deacon@arm.com>2018-12-06 15:16:58 +0000
commit121ca8e56551e4c52fdb37e8771eddc9ef44c880 (patch)
tree3817852d0982a4272d46c1622e3fbb0a375f0622
parent884143f60c89acf8f2d06de4113d5e3057791701 (diff)
arm64: kexec_file: Refactor setup_dtb() to consolidate error checking
setup_dtb() is a little difficult to read. This is largely because it duplicates the FDT -> Linux errno conversion for every intermediate return value, but also because of silly cosmetic things like naming and formatting. Given that this is all brand new, refactor the function to get us off on the right foot. Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r--arch/arm64/kernel/machine_kexec_file.c64
1 files changed, 34 insertions, 30 deletions
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index 0972c6d2c5bb..3c2c8a687149 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -22,10 +22,10 @@
#include <asm/byteorder.h>
/* relevant device tree properties */
-#define FDT_PSTR_INITRD_STA "linux,initrd-start"
-#define FDT_PSTR_INITRD_END "linux,initrd-end"
-#define FDT_PSTR_BOOTARGS "bootargs"
-#define FDT_PSTR_KASLR_SEED "kaslr-seed"
+#define FDT_PROP_INITRD_START "linux,initrd-start"
+#define FDT_PROP_INITRD_END "linux,initrd-end"
+#define FDT_PROP_BOOTARGS "bootargs"
+#define FDT_PROP_KASLR_SEED "kaslr-seed"
const struct kexec_file_ops * const kexec_file_loaders[] = {
&kexec_image_ops,
@@ -44,61 +44,65 @@ static int setup_dtb(struct kimage *image,
unsigned long initrd_load_addr, unsigned long initrd_len,
char *cmdline, void *dtb)
{
- int nodeoffset;
- int ret;
+ int off, ret;
+
+ ret = fdt_path_offset(dtb, "/chosen");
+ if (ret < 0)
+ goto out;
- nodeoffset = fdt_path_offset(dtb, "/chosen");
- if (nodeoffset < 0)
- return -EINVAL;
+ off = ret;
/* add bootargs */
if (cmdline) {
- ret = fdt_setprop_string(dtb, nodeoffset, FDT_PSTR_BOOTARGS,
- cmdline);
+ ret = fdt_setprop_string(dtb, off, FDT_PROP_BOOTARGS, cmdline);
if (ret)
- return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
+ goto out;
} else {
- ret = fdt_delprop(dtb, nodeoffset, FDT_PSTR_BOOTARGS);
+ ret = fdt_delprop(dtb, off, FDT_PROP_BOOTARGS);
if (ret && (ret != -FDT_ERR_NOTFOUND))
- return -EINVAL;
+ goto out;
}
/* add initrd-* */
if (initrd_load_addr) {
- ret = fdt_setprop_u64(dtb, nodeoffset, FDT_PSTR_INITRD_STA,
- initrd_load_addr);
+ ret = fdt_setprop_u64(dtb, off, FDT_PROP_INITRD_START,
+ initrd_load_addr);
if (ret)
- return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
+ goto out;
- ret = fdt_setprop_u64(dtb, nodeoffset, FDT_PSTR_INITRD_END,
- initrd_load_addr + initrd_len);
+ ret = fdt_setprop_u64(dtb, off, FDT_PROP_INITRD_END,
+ initrd_load_addr + initrd_len);
if (ret)
- return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
+ goto out;
} else {
- ret = fdt_delprop(dtb, nodeoffset, FDT_PSTR_INITRD_STA);
+ ret = fdt_delprop(dtb, off, FDT_PROP_INITRD_START);
if (ret && (ret != -FDT_ERR_NOTFOUND))
- return -EINVAL;
+ goto out;
- ret = fdt_delprop(dtb, nodeoffset, FDT_PSTR_INITRD_END);
+ ret = fdt_delprop(dtb, off, FDT_PROP_INITRD_END);
if (ret && (ret != -FDT_ERR_NOTFOUND))
- return -EINVAL;
+ goto out;
}
/* add kaslr-seed */
- ret = fdt_delprop(dtb, nodeoffset, FDT_PSTR_KASLR_SEED);
+ ret = fdt_delprop(dtb, off, FDT_PROP_KASLR_SEED);
if (ret && (ret != -FDT_ERR_NOTFOUND))
- return -EINVAL;
+ goto out;
if (rng_is_initialized()) {
- u64 r = get_random_u64();
- ret = fdt_setprop_u64(dtb, nodeoffset, FDT_PSTR_KASLR_SEED, r);
+ u64 seed = get_random_u64();
+ ret = fdt_setprop_u64(dtb, off, FDT_PROP_KASLR_SEED, seed);
if (ret)
- return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
+ goto out;
} else {
pr_notice("RNG is not initialised: omitting \"%s\" property\n",
- FDT_PSTR_KASLR_SEED);
+ FDT_PROP_KASLR_SEED);
}
+out:
+ if (ret)
+ return (ret == -FDT_ERR_NOSPACE) ? -ENOMEM : -EINVAL;
+
return 0;
}