From 3ee625d74f0ad65608ec02062b52d5944ffc8208 Mon Sep 17 00:00:00 2001 From: Sven Schnelle Date: Mon, 8 Nov 2021 09:58:42 +0100 Subject: [PATCH] zipl: add check_common_ipl_data() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are two places where we check whether the initrd and kernel image is readably. Add one helper function that checks this. This is also a preparation for the extended command line handling, so that we have to add that code in only one location. Signed-off-by: Sven Schnelle Reviewed-by: Stefan Haberland Signed-off-by: Jan Höppner --- zipl/src/job.c | 56 +++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/zipl/src/job.c b/zipl/src/job.c index 40c61381..76356e1f 100644 --- a/zipl/src/job.c +++ b/zipl/src/job.c @@ -761,26 +761,37 @@ static void error_text_section(const char *text, const char *section, const char } +static int +check_common_ipl_data(struct job_common_ipl_data *common, const char *section) +{ + int rc; + + if (common->image != NULL) { + rc = misc_check_readable_file(common->image); + if (rc) { + error_text_section("Image file", section, common->image); + return rc; + } + } + if (common->ramdisk != NULL) { + rc = misc_check_readable_file(common->ramdisk); + if (rc) { + error_text_section("Ramdisk file", section, common->ramdisk); + return rc; + } + } + return 0; +} + static int check_job_ipl_data(struct job_ipl_data *ipl, char *name, struct job_envblk_data *envblk) { int rc; - if (ipl->common.image != NULL) { - rc = misc_check_readable_file(ipl->common.image); - if (rc) { - error_text_section("Image file", name, ipl->common.image); - return rc; - } - } - if (ipl->common.ramdisk != NULL) { - rc = misc_check_readable_file(ipl->common.ramdisk); - if (rc) { - error_text_section("Ramdisk file", name, ipl->common.ramdisk); - return rc; - } - } + rc = check_common_ipl_data(&ipl->common, name); + if (rc) + return rc; return finalize_ipl_address_data(ipl, name, envblk); } @@ -889,20 +900,9 @@ check_job_ipl_tape_data(struct job_ipl_tape_data *ipl, char* name) return rc; } } - if (ipl->common.image != NULL) { - rc = misc_check_readable_file(ipl->common.image); - if (rc) { - error_text_section("Image file", name, ipl->common.image); - return rc; - } - } - if (ipl->common.ramdisk != NULL) { - rc = misc_check_readable_file(ipl->common.ramdisk); - if (rc) { - error_text_section("Ramdisk file", name, ipl->common.ramdisk); - return rc; - } - } + rc = check_common_ipl_data(&ipl->common, name); + if (rc) + return rc; return finalize_common_address_data(&ipl->common, name); }