diff options
author | Markus Armbruster <armbru@redhat.com> | 2019-12-04 10:36:14 +0100 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2019-12-18 08:36:15 +0100 |
commit | bc0e339b01b330c55532571ae6fce89b0f8a4a96 (patch) | |
tree | b46fbe66d2f58fcdc48a4a5da1718c51742948f4 /hw/core/loader-fit.c | |
parent | 49e3e11f8f27a75070062965c097e3feacc5d029 (diff) |
hw/core: Fix fit_load_fdt() error API violations
fit_load_fdt() passes @errp to fit_image_addr(), then recovers from
ENOENT failures. Passing @errp is wrong, because it works only as
long as @errp is neither @error_fatal nor @error_abort. Error
recovery dereferences @errp. That's also wrong; see the big comment
in error.h. Error recovery can leave *errp pointing to a freed
Error object. Wrong, it must be null on success. Messed up in
commit 3eb99edb48 "loader-fit: Wean off error_printf()".
No caller actually passes such values, or uses *errp on success.
Fix anyway: splice in a local Error *err, and error_propagate().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20191204093625.14836-8-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Diffstat (limited to 'hw/core/loader-fit.c')
-rw-r--r-- | hw/core/loader-fit.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/hw/core/loader-fit.c b/hw/core/loader-fit.c index 953b16bc82..c465921b8f 100644 --- a/hw/core/loader-fit.c +++ b/hw/core/loader-fit.c @@ -178,11 +178,12 @@ static int fit_load_fdt(const struct fit_loader *ldr, const void *itb, int cfg, void *opaque, const void *match_data, hwaddr kernel_end, Error **errp) { + Error *err = NULL; const char *name; const void *data; const void *load_data; hwaddr load_addr; - int img_off, err; + int img_off; size_t sz; int ret; @@ -197,13 +198,13 @@ static int fit_load_fdt(const struct fit_loader *ldr, const void *itb, return -EINVAL; } - err = fit_image_addr(itb, img_off, "load", &load_addr, errp); - if (err == -ENOENT) { + ret = fit_image_addr(itb, img_off, "load", &load_addr, &err); + if (ret == -ENOENT) { load_addr = ROUND_UP(kernel_end, 64 * KiB) + (10 * MiB); - error_free(*errp); - } else if (err) { - error_prepend(errp, "unable to read FDT load address from FIT: "); - ret = err; + error_free(err); + } else if (ret) { + error_propagate_prepend(errp, err, + "unable to read FDT load address from FIT: "); goto out; } |