Bladeren bron

[efi] Unload started images only on failure

If the StartImage() call returns with no error, then the image must
have been started and returned successfully.  It either unloaded
itself, or it intended to remain loaded (e.g. it was a driver).  We
therefore do not unload successful images.

If there was an error, we attempt to unload the image.  This may not
work.  In particular, there is no way to tell whether an error
returned from StartImage() was due to being unable to start the image
(in which case we probably should call UnloadImage()), or due to the
image itself returning an error (in which case we probably should not
call UnloadImage()).  We therefore ignore any failures from the
UnloadImage() call itself.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 jaren geleden
bovenliggende
commit
b53d4ae398
1 gewijzigde bestanden met toevoegingen van 17 en 9 verwijderingen
  1. 17
    9
      src/image/efi_image.c

+ 17
- 9
src/image/efi_image.c Bestand weergeven

229
 	/* Start the image */
229
 	/* Start the image */
230
 	if ( ( efirc = bs->StartImage ( handle, NULL, NULL ) ) != 0 ) {
230
 	if ( ( efirc = bs->StartImage ( handle, NULL, NULL ) ) != 0 ) {
231
 		rc = -EEFI_START ( efirc );
231
 		rc = -EEFI_START ( efirc );
232
-		DBGC ( image, "EFIIMAGE %p returned with status %s\n",
233
-		       image, strerror ( rc ) );
232
+		DBGC ( image, "EFIIMAGE %p could not start (or returned with "
233
+		       "error): %s\n", image, strerror ( rc ) );
234
 		goto err_start_image;
234
 		goto err_start_image;
235
 	}
235
 	}
236
 
236
 
240
  err_start_image:
240
  err_start_image:
241
 	efi_snp_claim();
241
 	efi_snp_claim();
242
  err_open_protocol:
242
  err_open_protocol:
243
-	/* Unload the image.  We can't leave it loaded, because we
244
-	 * have no "unload" operation.
243
+	/* If there was no error, then the image must have been
244
+	 * started and returned successfully.  It either unloaded
245
+	 * itself, or it intended to remain loaded (e.g. it was a
246
+	 * driver).  We therefore do not unload successful images.
247
+	 *
248
+	 * If there was an error, attempt to unload the image.  This
249
+	 * may not work.  In particular, there is no way to tell
250
+	 * whether an error returned from StartImage() was due to
251
+	 * being unable to start the image (in which case we probably
252
+	 * should call UnloadImage()), or due to the image itself
253
+	 * returning an error (in which case we probably should not
254
+	 * call UnloadImage()).  We therefore ignore any failures from
255
+	 * the UnloadImage() call itself.
245
 	 */
256
 	 */
246
-	if ( ( efirc = bs->UnloadImage ( handle ) ) != 0 ) {
247
-		rc = -EEFI ( efirc );
248
-		DBGC ( image, "EFIIMAGE %p could not unload: %s\n",
249
-		       image, strerror ( rc ) );
250
-	}
257
+	if ( rc != 0 )
258
+		bs->UnloadImage ( handle );
251
  err_load_image:
259
  err_load_image:
252
 	free ( cmdline );
260
 	free ( cmdline );
253
  err_cmdline:
261
  err_cmdline:

Laden…
Annuleren
Opslaan