From e577d7d94a738282b4dc7562871198264e3927ce Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 11 Feb 2025 19:22:09 +0100 Subject: [PATCH] efi: modernize reconnect_all_drivers() a bit --- src/boot/drivers.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/boot/drivers.c b/src/boot/drivers.c index 078c6cb993..414e27a0f4 100644 --- a/src/boot/drivers.c +++ b/src/boot/drivers.c @@ -55,15 +55,23 @@ EFI_STATUS reconnect_all_drivers(void) { /* Reconnects all handles, so that any loaded drivers can take effect. */ - err = BS->LocateHandleBuffer(AllHandles, NULL, NULL, &n_handles, &handles); - if (err != EFI_SUCCESS) + err = BS->LocateHandleBuffer( + AllHandles, + /* Protocol= */ NULL, + /* SearchKey= */ NULL, + &n_handles, &handles); + if (!IN_SET(err, EFI_SUCCESS, EFI_NOT_FOUND)) return log_error_status(err, "Failed to get list of handles: %m"); - for (size_t i = 0; i < n_handles; i++) + FOREACH_ARRAY(h, handles, n_handles) /* Some firmware gives us some bogus handles (or they might become bad due to * reconnecting everything). Security policy may also prevent us from doing so too. * There is nothing we can realistically do on errors anyways, so just ignore them. */ - (void) BS->ConnectController(handles[i], NULL, NULL, true); + (void) BS->ConnectController( + *h, + /* DriverImageHandle= */ NULL, + /* RemainingDevicePath= */ NULL, + /* Recursive= */ true); return EFI_SUCCESS; }