From 989a7a8032db02eb0524bd78a674d3b087dea3a6 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 25 Jan 2021 16:18:28 +0000 Subject: [image] Provide image_memory() Consolidate the remaining logic common to initrd_init() and imgmem() into a shared image_memory() function. Signed-off-by: Michael Brown --- src/arch/x86/core/runtime.c | 44 +++++--------------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) (limited to 'src/arch') diff --git a/src/arch/x86/core/runtime.c b/src/arch/x86/core/runtime.c index 4de3bfafe..02072b5bf 100644 --- a/src/arch/x86/core/runtime.c +++ b/src/arch/x86/core/runtime.c @@ -179,7 +179,6 @@ static int cmdline_init ( void ) { */ static int initrd_init ( void ) { struct image *image; - int rc; /* Do nothing if no initrd was specified */ if ( ! initrd_phys ) { @@ -193,51 +192,18 @@ static int initrd_init ( void ) { DBGC ( colour, "RUNTIME found initrd at [%x,%x)\n", initrd_phys, ( initrd_phys + initrd_len ) ); - /* Allocate image */ - image = alloc_image ( NULL ); + /* Create initrd image */ + image = image_memory ( "", phys_to_user ( initrd_phys ), + initrd_len ); if ( ! image ) { - DBGC ( colour, "RUNTIME could not allocate image for " - "initrd\n" ); - rc = -ENOMEM; - goto err_alloc_image; - } - - /* Set image name */ - if ( ( rc = image_set_name ( image, "" ) ) != 0 ) { - DBGC ( colour, "RUNTIME could not set image name: %s\n", - strerror ( rc ) ); - goto err_set_name; - } - - /* Set image content */ - if ( ( rc = image_set_data ( image, phys_to_user ( initrd_phys ), - initrd_len ) ) != 0 ) { - DBGC ( colour, "RUNTIME could not set image data: %s\n", - strerror ( rc ) ); - goto err_set_data; + DBGC ( colour, "RUNTIME could not create initrd image\n" ); + return -ENOMEM; } /* Mark initrd as consumed */ initrd_phys = 0; - /* Register image */ - if ( ( rc = register_image ( image ) ) != 0 ) { - DBGC ( colour, "RUNTIME could not register initrd: %s\n", - strerror ( rc ) ); - goto err_register_image; - } - - /* Drop our reference to the image */ - image_put ( image ); - return 0; - - err_register_image: - err_set_data: - err_set_name: - image_put ( image ); - err_alloc_image: - return rc; } /** -- cgit v1.2.3-55-g7522