From nobody Sat Feb 7 18:22:59 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 168321C07CF for ; Fri, 20 Dec 2024 11:22:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693761; cv=none; b=UKjtNvxd62jbq2MN4UujYILTR85gDeZRR8NVrW+RNrFEuQ0FQkWa1c+asjO+UUT7NQE8MjiDeIGgZg7HQaIQbTCirWs9GkpVbWQMCx0XDp9+EX44KEBvtPmcfmCp6P2IwK5WG5ADqy33hHd85zaA8s+eNHEjgtqgU9AWKvGyS9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693761; c=relaxed/simple; bh=aIauqGBYHpW4ez5NfIDLYO5bWWI87u7AWHcSTVi1nKM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OpMgjWmLTCmgay2tHj3IjhgfdEJt8VTyI63lUPgPW41lfCOuZQ0lrHU6hyCix77MtyxeiaCDAsE+Akem15bHWgdkC4wQbudFNoyr/yHV634rwdcy1TFpPmIGlD0/QmsecUBKbwpP2wGpy3921LAJ7TsE/27q1F5umccU5EPUlyI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Z63j0k5M; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Z63j0k5M" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-43635895374so14560515e9.0 for ; Fri, 20 Dec 2024 03:22:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734693758; x=1735298558; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=G4YTq/ftOlxzsFyBK5qpik8kRgidp3qaC0bsdTEKQfI=; b=Z63j0k5MRKPRnKB855cF0osTjU+cQLYfjz8awGx/5S8yUeOZ871wp/iQYsepTV+D7u FESBFzUnj3+ZiAwbppt/YW2HIUNlZRuv9SqwtDHKLI//OCYlaTgiekrH0tcKHPHc8IJK kncWxnhOYEXJfDiUE9P1Yn9vmieJDv5OhUs5BO1/e39zjQlKwARFbgHPYAVaJ5TFqGcs AlBE00gUo/8jfjQqWO4oTI5i/f7PdhE73ivAMh45jY+MCoVdcS6UVqXMEr+5b6CtjCit 3AWQkUZqHrypqn+F9/q9HZ1DMn5df2SzZbwpkqctLOHFH02UlO8Gi6GISAegFhF7009K AWqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734693758; x=1735298558; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=G4YTq/ftOlxzsFyBK5qpik8kRgidp3qaC0bsdTEKQfI=; b=GFcCKP/ic1I8S+9lTVkH/K96JQFNbjI1JypEBORbSYvvukpj741XiO7Elen7Lbhv6e 4EWvLRefZX9Or6z/4kNabjXNE1NUEVlnaLqamcRZdAZ+vf0YoN101RV99tUr07d8OCY5 PWBwnr+SJrmpF1NYVAon6CzfqzLzwaDHCSrLeuwAA//MrhubsIIxklvXDmdoq9DB40wN 7oRX58GvolaSm3L72sGV11vTxN47LeIjWGkYzbkXCzJPYaDe3uEZRSp0lJEY3hc/CWBo 8bXZl82MC+yE5VjDN2rE0edBVU7+08aDSYCg9geiYxNRpOw+35E5Rrk5CBIfZEAdiGgX 2+rA== X-Gm-Message-State: AOJu0YxKugcn5qHEgCvKJHyyNrDmFFC7Iv7zgBSMNv3icoeK0sc7dF5O 7NqMVhi8Lr1GcpGdEfcGiFapC/4fx5I7i+yjKHc0q645hn3KFQXP0HKPATuR5pxcSJz9IA== X-Google-Smtp-Source: AGHT+IEFIi4SExocJjw8kszjhCQw70qFejd1sU8fWDynz2b6RMGHYdSgLx1AafOwUuQhZpTI//tUZJaS X-Received: from wmbjj16.prod.google.com ([2002:a05:600c:6a10:b0:434:e9fe:f913]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3b8c:b0:434:ff08:202e with SMTP id 5b1f17b1804b1-436699ff9famr20916095e9.8.1734693758603; Fri, 20 Dec 2024 03:22:38 -0800 (PST) Date: Fri, 20 Dec 2024 12:22:16 +0100 In-Reply-To: <20241220112214.2598872-9-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220112214.2598872-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=6232; i=ardb@kernel.org; h=from:subject; bh=cMbTqyf6fcVFSGOV1gvDHpolf1J3659U3OaWiXwGbLI=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT01ONP46G6h5UVddxZM8VPZ1L0k90xTVue95YYxeqGtg c0ZdUEdpSwMYhwMsmKKLAKz/77beXqiVK3zLFmYOaxMIEMYuDgFYCIHxBh+s/8+VDZdZuvPlDiJ B13pp9/GT3l3KSzNLLA700DqcOjNUIa/oj8bC14ej7XfYPF4q1BbP0/EylObXM+Khuo4xkz8zT6 PBQA= X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220112214.2598872-10-ardb+git@google.com> Subject: [PATCH 1/7] x86/efistub: Drop long obsolete UGA support From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel UGA is the EFI graphical output protocol that preceded GOP, and has been long obsolete. Drop support for it from the x86 implementation of the EFI stub - other architectures never bothered to implement it (save for ia64) Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/efi.c | 2 - drivers/firmware/efi/libstub/x86-stub.c | 90 -------------------- include/linux/efi.h | 2 - 3 files changed, 94 deletions(-) diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index a7ff189421c3..41fc2254f007 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -60,7 +60,6 @@ static unsigned long efi_runtime, efi_nr_tables; unsigned long efi_fw_vendor, efi_config_table; =20 static const efi_config_table_type_t arch_tables[] __initconst =3D { - {UGA_IO_PROTOCOL_GUID, &uga_phys, "UGA" }, #ifdef CONFIG_X86_UV {UV_SYSTEM_TABLE_GUID, &uv_systab_phys, "UVsystab" }, #endif @@ -72,7 +71,6 @@ static const unsigned long * const efi_tables[] =3D { &efi.acpi20, &efi.smbios, &efi.smbios3, - &uga_phys, #ifdef CONFIG_X86_UV &uv_systab_phys, #endif diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index 188c8000d245..0c51d8307000 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -405,96 +405,13 @@ static void setup_quirks(struct boot_params *boot_par= ams) } } =20 -/* - * See if we have Universal Graphics Adapter (UGA) protocol - */ -static efi_status_t -setup_uga(struct screen_info *si, efi_guid_t *uga_proto, unsigned long siz= e) -{ - efi_status_t status; - u32 width, height; - void **uga_handle =3D NULL; - efi_uga_draw_protocol_t *uga =3D NULL, *first_uga; - efi_handle_t handle; - int i; - - status =3D efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, - (void **)&uga_handle); - if (status !=3D EFI_SUCCESS) - return status; - - status =3D efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, - uga_proto, NULL, &size, uga_handle); - if (status !=3D EFI_SUCCESS) - goto free_handle; - - height =3D 0; - width =3D 0; - - first_uga =3D NULL; - for_each_efi_handle(handle, uga_handle, size, i) { - efi_guid_t pciio_proto =3D EFI_PCI_IO_PROTOCOL_GUID; - u32 w, h, depth, refresh; - void *pciio; - - status =3D efi_bs_call(handle_protocol, handle, uga_proto, - (void **)&uga); - if (status !=3D EFI_SUCCESS) - continue; - - pciio =3D NULL; - efi_bs_call(handle_protocol, handle, &pciio_proto, &pciio); - - status =3D efi_call_proto(uga, get_mode, &w, &h, &depth, &refresh); - if (status =3D=3D EFI_SUCCESS && (!first_uga || pciio)) { - width =3D w; - height =3D h; - - /* - * Once we've found a UGA supporting PCIIO, - * don't bother looking any further. - */ - if (pciio) - break; - - first_uga =3D uga; - } - } - - if (!width && !height) - goto free_handle; - - /* EFI framebuffer */ - si->orig_video_isVGA =3D VIDEO_TYPE_EFI; - - si->lfb_depth =3D 32; - si->lfb_width =3D width; - si->lfb_height =3D height; - - si->red_size =3D 8; - si->red_pos =3D 16; - si->green_size =3D 8; - si->green_pos =3D 8; - si->blue_size =3D 8; - si->blue_pos =3D 0; - si->rsvd_size =3D 8; - si->rsvd_pos =3D 24; - -free_handle: - efi_bs_call(free_pool, uga_handle); - - return status; -} - static void setup_graphics(struct boot_params *boot_params) { efi_guid_t graphics_proto =3D EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; struct screen_info *si; - efi_guid_t uga_proto =3D EFI_UGA_PROTOCOL_GUID; efi_status_t status; unsigned long size; void **gop_handle =3D NULL; - void **uga_handle =3D NULL; =20 si =3D &boot_params->screen_info; memset(si, 0, sizeof(*si)); @@ -505,13 +422,6 @@ static void setup_graphics(struct boot_params *boot_pa= rams) if (status =3D=3D EFI_BUFFER_TOO_SMALL) status =3D efi_setup_gop(si, &graphics_proto, size); =20 - if (status !=3D EFI_SUCCESS) { - size =3D 0; - status =3D efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, - &uga_proto, NULL, &size, uga_handle); - if (status =3D=3D EFI_BUFFER_TOO_SMALL) - setup_uga(si, &uga_proto, size); - } } =20 =20 diff --git a/include/linux/efi.h b/include/linux/efi.h index e5815867aba9..234200469146 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -363,7 +363,6 @@ void efi_native_runtime_setup(void); #define ACPI_20_TABLE_GUID EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0= x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81) #define SMBIOS_TABLE_GUID EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x= 16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d) #define SMBIOS3_TABLE_GUID EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0= x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94) -#define UGA_IO_PROTOCOL_GUID EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b, 0xb9,= 0x22, 0xa8, 0x6e, 0xed, 0x0b, 0x07, 0xa2) #define EFI_GLOBAL_VARIABLE_GUID EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0x= aa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c) #define UV_SYSTEM_TABLE_GUID EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd, 0x93,= 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93) #define LINUX_EFI_CRASH_GUID EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97,= 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0) @@ -373,7 +372,6 @@ void efi_native_runtime_setup(void); #define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID EFI_GUID(0x8b843e20, 0x8132,= 0x4852, 0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c) #define EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID EFI_GUID(0x05c99a21, 0xc70= f, 0x4ad2, 0x8a, 0x5f, 0x35, 0xdf, 0x33, 0x43, 0xf5, 0x1e) #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID EFI_GUID(0x9042a9de, 0x23dc, 0x4= a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a) -#define EFI_UGA_PROTOCOL_GUID EFI_GUID(0x982c298b, 0xf4fa, 0x41cb, 0xb8= , 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39) #define EFI_PCI_IO_PROTOCOL_GUID EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5, 0x= 9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a) #define EFI_FILE_INFO_ID EFI_GUID(0x09576e92, 0x6d3f, 0x11d2, 0x8e, 0x3= 9, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) #define EFI_SYSTEM_RESOURCE_TABLE_GUID EFI_GUID(0xb122a263, 0x3661, 0x4f6= 8, 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80) --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Sat Feb 7 18:22:59 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FB471C4A29 for ; Fri, 20 Dec 2024 11:22:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693763; cv=none; b=pZo4UElAE3iMcjlNzthrWUWMBmikeAnwXiMGJxAZNCvYXWUc0dETiy09kHSSXf/TKg28KxhfcLAGxdZNqKU3tE5Ptq/V/63P9sfU+c97ZUSwlW5sbXonprzxG/Rl+UPokr1q41WTKI9nJmpFdoWYfP4xnAKQa6DRHUntFrbRlVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693763; c=relaxed/simple; bh=yjKDfnWFkEuDhw362m3wgv7Ngw+SdWNENil+UmGcXVs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EWiAIlmvZwDQWzX5WFmLOrKHbfdKldjLcEvGRxiYS1NTvlSNKLMuRlwW0qL1Y4EUVH+0U3HXczTrCUA6j/JQ3ZwwUXTXh0Ke1rz9fE3OklpszUMg6Uyldp2F3B0kQaumKYA2tLZjXnSD4Xi/JX3BI14BtYT1DfubUe+HpqY+N1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=q/2nIDpT; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="q/2nIDpT" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4359eb032c9so15622945e9.2 for ; Fri, 20 Dec 2024 03:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734693760; x=1735298560; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6YYXdY4bN82dG0pvzgxsem1o3f0Ml+EYY91hq0XrqIE=; b=q/2nIDpTe6APAW4FJPuobzwo3R88HCNkllCAfxg3hSPHxf9dkbn6cMwKvmrNB9dZjI VbyRh9EZfT5POuxrAYKhDZNk3kKMvySeuqfovTW7euDDZqzN+1qNQIBqelbS0CTF9UAp H4mMmIAvu5RJYWT84bwlJ3VcGhTFffu9ue5ErHwBC19+0mc2A2zLYnHOeXswroVW9TuW kUVHCHtxFRJO43O63jaLekAQxwi/KKDpvvPmlXlatCl6CWxtOEz5jp92VmxrvlVlKM4/ fZ4JK+5QHSW5pyqaQWY1fFNeJEjKrJks2OkU6lsgsZeGdYK2Y3Wd/oawBUO35m4Uk5ow bOjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734693760; x=1735298560; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6YYXdY4bN82dG0pvzgxsem1o3f0Ml+EYY91hq0XrqIE=; b=v63sLGxNAfZt4pcmJg0WnyUfQIfYx6/cTO8KJaxMGNA7yF0UPJ6UmKXCRHGZl5h1AM Nc9BW7hCnaUNmptm7JR/gqOWVIyCzl8iqiJ1ohkqk05jTMdcJjJ1WJkUk4QLi58fZney 6Y4M7tjj9IL7WO6F23M69HxP8/aJTf4qP/HKjDedXmt6nZ2AmDLqz5/6UecMdPG9JG2z kGc8p5tmz5n8w9NFdKV89WZS0OankC9K06jrFZxPR7U11Q+TDpV2eojuA/Z7aZsUhPZt KLCAQFXxUZTB/xtIrGuG6OsCBMEC04E28BFRhsxH4AWBCkqRyVMeTzXcNMw4VJAAsjBY kHSQ== X-Gm-Message-State: AOJu0YyYjaD24I+Xr3eX1lkylcuQkLK6cWy69YaawlOZZx+1j/VxHUtf wr1c2/Olb/eN5wuYpnQZFS5Fc3skUAoHHHfTU019T3iUY02QTC2vu5qem/E27zr+KRcArg== X-Google-Smtp-Source: AGHT+IEPtd6fv8n48QLQArvWtpQjRGaa1iszuXudfaVHD/pL8rJJFKuWgJzijdPiBSgexJW7kzhFRQ8s X-Received: from wmqb1.prod.google.com ([2002:a05:600c:4e01:b0:434:ef30:4be3]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:35d2:b0:435:d22:9c9e with SMTP id 5b1f17b1804b1-43668646335mr21268535e9.19.1734693760586; Fri, 20 Dec 2024 03:22:40 -0800 (PST) Date: Fri, 20 Dec 2024 12:22:17 +0100 In-Reply-To: <20241220112214.2598872-9-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220112214.2598872-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4129; i=ardb@kernel.org; h=from:subject; bh=cg25M7jhCCiFzPMmRlAcGna2O6HkPSkC46Z5HoI87BA=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT01OOt0W3/L5lCLSsW9HtkP5tgVXBeXtls1dU28L8/Ch KOnns7sKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABOxmc7wP4kje8/G8++OSllx y7CVP53lYuxa1WiSfs1ia8X0iusHOxn+1x2a+WNqe9v3d7dt37FPn3H54PoAOd8TSwK/BB/ab+7 FzAIA X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220112214.2598872-11-ardb+git@google.com> Subject: [PATCH 2/7] efi/libstub: Use C99-style for loop to traverse handle buffer From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Tweak the for_each_efi_handle() macro in order to avoid the need on the part of the caller to provide a loop counter variable. Also move efi_get_handle_num() to the callers, so that each occurrence can be replaced with the actual number returned by the simplified LocateHandleBuffer API. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efistub.h | 9 ++++----- drivers/firmware/efi/libstub/gop.c | 3 +-- drivers/firmware/efi/libstub/pci.c | 5 ++--- drivers/firmware/efi/libstub/x86-stub.c | 3 +-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/= libstub/efistub.h index d0989e072b2b..c321735eb237 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -123,11 +123,10 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handl= e, #define efi_get_handle_num(size) \ ((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32))) =20 -#define for_each_efi_handle(handle, array, size, i) \ - for (i =3D 0; \ - i < efi_get_handle_num(size) && \ - ((handle =3D efi_get_handle_at((array), i)) || true); \ - i++) +#define for_each_efi_handle(handle, array, num) \ + for (int __i =3D 0; __i < (num) && \ + ((handle =3D efi_get_handle_at((array), __i)) || true); \ + __i++) =20 static inline void efi_set_u64_split(u64 data, u32 *lo, u32 *hi) diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libs= tub/gop.c index ea5da307d542..8eef63c48288 100644 --- a/drivers/firmware/efi/libstub/gop.c +++ b/drivers/firmware/efi/libstub/gop.c @@ -466,11 +466,10 @@ find_gop(efi_guid_t *proto, unsigned long size, void = **handles) { efi_graphics_output_protocol_t *first_gop; efi_handle_t h; - int i; =20 first_gop =3D NULL; =20 - for_each_efi_handle(h, handles, size, i) { + for_each_efi_handle(h, handles, efi_get_handle_num(size)) { efi_status_t status; =20 efi_graphics_output_protocol_t *gop; diff --git a/drivers/firmware/efi/libstub/pci.c b/drivers/firmware/efi/libs= tub/pci.c index 99fb25d2bcf5..b0ba372c26c5 100644 --- a/drivers/firmware/efi/libstub/pci.c +++ b/drivers/firmware/efi/libstub/pci.c @@ -21,7 +21,6 @@ void efi_pci_disable_bridge_busmaster(void) efi_handle_t handle; efi_status_t status; u16 class, command; - int i; =20 status =3D efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, &pci_proto, NULL, &pci_handle_size, NULL); @@ -46,7 +45,7 @@ void efi_pci_disable_bridge_busmaster(void) goto free_handle; } =20 - for_each_efi_handle(handle, pci_handle, pci_handle_size, i) { + for_each_efi_handle(handle, pci_handle, efi_get_handle_num(pci_handle_siz= e)) { efi_pci_io_protocol_t *pci; unsigned long segment_nr, bus_nr, device_nr, func_nr; =20 @@ -82,7 +81,7 @@ void efi_pci_disable_bridge_busmaster(void) efi_bs_call(disconnect_controller, handle, NULL, NULL); } =20 - for_each_efi_handle(handle, pci_handle, pci_handle_size, i) { + for_each_efi_handle(handle, pci_handle, efi_get_handle_num(pci_handle_siz= e)) { efi_pci_io_protocol_t *pci; =20 status =3D efi_bs_call(handle_protocol, handle, &pci_proto, diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index 0c51d8307000..71173471faf6 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -124,7 +124,6 @@ static void setup_efi_pci(struct boot_params *params) unsigned long size =3D 0; struct setup_data *data; efi_handle_t h; - int i; =20 status =3D efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, &pci_proto, NULL, &size, pci_handle); @@ -150,7 +149,7 @@ static void setup_efi_pci(struct boot_params *params) while (data && data->next) data =3D (struct setup_data *)(unsigned long)data->next; =20 - for_each_efi_handle(h, pci_handle, size, i) { + for_each_efi_handle(h, pci_handle, efi_get_handle_num(size)) { efi_pci_io_protocol_t *pci =3D NULL; struct pci_setup_rom *rom; =20 --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Sat Feb 7 18:22:59 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5CB291C5CC2 for ; Fri, 20 Dec 2024 11:22:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693766; cv=none; b=XNBwO0+ZU9y/C2Ic1NcC9nkgGqP86eejilcfFOJ/h6G8phvzfhVS1B8T0R0+ZlZvsZSbHE3RTqvU4lfdc3XCkBVnno/fK84R0O821tVI0NVzisAC2GyZjqFlYd2+5RiSH3R0LoZzhCllQvhOqLWOm5aGzEybTe3AitXXCOAb21M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693766; c=relaxed/simple; bh=0KQw1DNiKBnqryYgDBurqGjOmCFqhEOFJLSA0mjA9yk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PNCXqOvaW9bpMWEM3oe3FjIKYSV9StQL9yYNIKGyQb5sEcBLQacGm0H7A6tUCMVdL63inirH2TT2iboowB15B/JQMasJcuBafWKQxSnWcmKbVKgMIeSaioH5y2vdWLSHWdcBUC7j56mzEe4ws3tniu1Hsogdo7LtQXVo5YI5ZQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rYENQi76; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rYENQi76" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-385e1fd40acso1034952f8f.3 for ; Fri, 20 Dec 2024 03:22:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734693763; x=1735298563; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cNSJ8HGXQNdXuP3+AktVsISDb7HTO/BmfoYSJrTO9ls=; b=rYENQi764ppB9qdKmb3cVHJwbk9CS5trZZssQlYrh6SIw2yp8PCImG1R+Z9a/5Xfoc 9QivdlG4h1pIQcV3N8RyWfl74nLIF4hDXPWqrBr+ZkYZ4cMIQBNmMlDUw8TqbPM5oU7j gYTmk3ioxFL4HcBwGolh7i5y1e8+CiqwYFPcfPtMQPwksNvWrPWEnnqwCaeNBbfgDJto Rzd8A4ykPeVYwteBPAa2P17TkGha6Pbl5qD3aYN08epGQx16nlbz+LlXDM+b04S0GUut 6St6KNq6hv+oHY/enJLEo9mgUGdKjG9x/Yx9sklm4XJrWO3oFCCbITKBmrfEhWe0zPZE 0dLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734693763; x=1735298563; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cNSJ8HGXQNdXuP3+AktVsISDb7HTO/BmfoYSJrTO9ls=; b=oREdfEFserqb0qnfkN063i6Dm9mvhULvNBCLW3StJwnYcYllTIgH9X4dnUBxIVMrSb NZD6PcgpmMEgsZpPfJzxjT0pmjPfrxBzvwAY1kDeMTiMB6/cuyj2LXdwQCvwAiPfM/gP tuyC4qiCVJHM0mZp5Pt2n+ZgT4cG9xL6gwHdvx+Z+f6VfxFqexaSWINpusECYQkYoVLe Y5qKWrKmvEBOEkHhhXPbPnHnnduJ8VmMFkktqmMh4Tl2h9cVqd7zYe9+uL/ra86P6YDi E9DsCs+a9odbNU9MlwuDHiDGivr40EelzCoklCMlGTXvXM71+r1W/M9lOSILcnqY8nE8 eTaA== X-Gm-Message-State: AOJu0Yxu2fmouM2nAr0qb6Kr/ixj3xWm4ap4emWUq8yFVotueP245o31 hnal82f6dUGkaxC+wYTYZlx3jBrT7TtO+yNK2sQrIAV2fV4x7Xa5W3tVQyg8y785WCYW0Q== X-Google-Smtp-Source: AGHT+IF8zUGLe6aA2WdSo/5UrRsQij4BJK0HhPCJwGp9RoMVXlZcaAC1wTrHc2l53LJ8kJfl0nK1b59/ X-Received: from wmbjj20.prod.google.com ([2002:a05:600c:6a14:b0:434:fc6f:e8c3]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:598d:0:b0:385:fa3d:1988 with SMTP id ffacd0b85a97d-38a221e2f07mr2467165f8f.8.1734693762878; Fri, 20 Dec 2024 03:22:42 -0800 (PST) Date: Fri, 20 Dec 2024 12:22:18 +0100 In-Reply-To: <20241220112214.2598872-9-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220112214.2598872-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=7976; i=ardb@kernel.org; h=from:subject; bh=rYysZblB1Mm5gOU2h843vOCeOHNVXYgW6tmjcsWmdn4=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT01OKdZpLkvZuGDufPfx9nHCtw4YLRe0ru3vV+PWW7zh 4tsL/I6SlkYxDgYZMUUWQRm/3238/REqVrnWbIwc1iZQIYwcHEKwEQ0ExgZ1mW/9uJOZp4wS+K2 /MOjMZ8WZrzzdom/e/L5qTszXn2eP4Xhf2nXgi9Cvpc7pjXVHbqlLKl2zyx66jFRkV99wVoyBjb 7eAA= X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220112214.2598872-12-ardb+git@google.com> Subject: [PATCH 3/7] efi/libstub: Simplify GOP handling code From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Use the LocateHandleBuffer() API and a __free() function to simplify the logic that allocates a handle buffer to iterate over all GOP protocols in the EFI database. Signed-off-by: Ard Biesheuvel --- arch/x86/include/asm/efi.h | 3 ++ drivers/firmware/efi/libstub/efi-stub.c | 28 ++++------ drivers/firmware/efi/libstub/efistub.h | 7 +-- drivers/firmware/efi/libstub/gop.c | 57 +++++++------------- drivers/firmware/efi/libstub/x86-stub.c | 17 +----- 5 files changed, 38 insertions(+), 74 deletions(-) diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index 521aad70e41b..f227a70ac91f 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -250,6 +250,9 @@ static inline u32 efi64_convert_status(efi_status_t sta= tus) #define __efi64_argmap_allocate_pool(type, size, buffer) \ ((type), (size), efi64_zero_upper(buffer)) =20 +#define __efi64_argmap_locate_handle_buffer(type, proto, key, num, buf) \ + ((type), (proto), (key), efi64_zero_upper(num), efi64_zero_upper(buf)) + #define __efi64_argmap_create_event(type, tpl, f, c, event) \ ((type), (tpl), (f), (c), efi64_zero_upper(event)) =20 diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi= /libstub/efi-stub.c index 382b54f40603..90e06a6b1a45 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -10,6 +10,7 @@ */ =20 #include +#include #include =20 #include "efistub.h" @@ -53,25 +54,16 @@ void __weak free_screen_info(struct screen_info *si) =20 static struct screen_info *setup_graphics(void) { - efi_guid_t gop_proto =3D EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; - efi_status_t status; - unsigned long size; - void **gop_handle =3D NULL; - struct screen_info *si =3D NULL; + struct screen_info *si, tmp =3D {}; =20 - size =3D 0; - status =3D efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, - &gop_proto, NULL, &size, gop_handle); - if (status =3D=3D EFI_BUFFER_TOO_SMALL) { - si =3D alloc_screen_info(); - if (!si) - return NULL; - status =3D efi_setup_gop(si, &gop_proto, size); - if (status !=3D EFI_SUCCESS) { - free_screen_info(si); - return NULL; - } - } + if (efi_setup_gop(&tmp) !=3D EFI_SUCCESS) + return NULL; + + si =3D alloc_screen_info(); + if (!si) + return NULL; + + *si =3D tmp; return si; } =20 diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/= libstub/efistub.h index c321735eb237..a7c24f0a2e5e 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -314,7 +314,9 @@ union efi_boot_services { void *close_protocol; void *open_protocol_information; void *protocols_per_handle; - void *locate_handle_buffer; + efi_status_t (__efiapi *locate_handle_buffer)(int, efi_guid_t *, + void *, unsigned long *, + efi_handle_t *); efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *, void **); efi_status_t (__efiapi *install_multiple_protocol_interfaces)(efi_handle= _t *, ...); @@ -1083,8 +1085,7 @@ efi_status_t efi_parse_options(char const *cmdline); =20 void efi_parse_option_graphics(char *option); =20 -efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto, - unsigned long size); +efi_status_t efi_setup_gop(struct screen_info *si); =20 efi_status_t handle_cmdline_files(efi_loaded_image_t *image, const efi_char16_t *optstr, diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libs= tub/gop.c index 8eef63c48288..fce28488c76c 100644 --- a/drivers/firmware/efi/libstub/gop.c +++ b/drivers/firmware/efi/libstub/gop.c @@ -461,25 +461,25 @@ setup_pixel_info(struct screen_info *si, u32 pixels_p= er_scan_line, } } =20 -static efi_graphics_output_protocol_t * -find_gop(efi_guid_t *proto, unsigned long size, void **handles) +static efi_graphics_output_protocol_t *find_gop(unsigned long num, + const efi_handle_t handles[]) { efi_graphics_output_protocol_t *first_gop; efi_handle_t h; =20 first_gop =3D NULL; =20 - for_each_efi_handle(h, handles, efi_get_handle_num(size)) { + for_each_efi_handle(h, handles, num) { efi_status_t status; =20 efi_graphics_output_protocol_t *gop; efi_graphics_output_protocol_mode_t *mode; efi_graphics_output_mode_info_t *info; - - efi_guid_t conout_proto =3D EFI_CONSOLE_OUT_DEVICE_GUID; void *dummy =3D NULL; =20 - status =3D efi_bs_call(handle_protocol, h, proto, (void **)&gop); + status =3D efi_bs_call(handle_protocol, h, + &EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, + (void **)&gop); if (status !=3D EFI_SUCCESS) continue; =20 @@ -499,7 +499,8 @@ find_gop(efi_guid_t *proto, unsigned long size, void **= handles) * Once we've found a GOP supporting ConOut, * don't bother looking any further. */ - status =3D efi_bs_call(handle_protocol, h, &conout_proto, &dummy); + status =3D efi_bs_call(handle_protocol, h, + &EFI_CONSOLE_OUT_DEVICE_GUID, &dummy); if (status =3D=3D EFI_SUCCESS) return gop; =20 @@ -510,16 +511,22 @@ find_gop(efi_guid_t *proto, unsigned long size, void = **handles) return first_gop; } =20 -static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto, - unsigned long size, void **handles) +efi_status_t efi_setup_gop(struct screen_info *si) { - efi_graphics_output_protocol_t *gop; + efi_handle_t *handles __free(efi_pool) =3D NULL; efi_graphics_output_protocol_mode_t *mode; efi_graphics_output_mode_info_t *info; + efi_graphics_output_protocol_t *gop; + efi_status_t status; + unsigned long num; =20 - gop =3D find_gop(proto, size, handles); + status =3D efi_bs_call(locate_handle_buffer, EFI_LOCATE_BY_PROTOCOL, + &EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, NULL, &num, + (void **)&handles); + if (status !=3D EFI_SUCCESS) + return status; =20 - /* Did we find any GOPs? */ + gop =3D find_gop(num, handles); if (!gop) return EFI_NOT_FOUND; =20 @@ -551,29 +558,3 @@ static efi_status_t setup_gop(struct screen_info *si, = efi_guid_t *proto, =20 return EFI_SUCCESS; } - -/* - * See if we have Graphics Output Protocol - */ -efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto, - unsigned long size) -{ - efi_status_t status; - void **gop_handle =3D NULL; - - status =3D efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, - (void **)&gop_handle); - if (status !=3D EFI_SUCCESS) - return status; - - status =3D efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, proto, NULL, - &size, gop_handle); - if (status !=3D EFI_SUCCESS) - goto free_handle; - - status =3D setup_gop(si, proto, size, gop_handle); - -free_handle: - efi_bs_call(free_pool, gop_handle); - return status; -} diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index 71173471faf6..53da6b5be739 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -406,24 +406,11 @@ static void setup_quirks(struct boot_params *boot_par= ams) =20 static void setup_graphics(struct boot_params *boot_params) { - efi_guid_t graphics_proto =3D EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; - struct screen_info *si; - efi_status_t status; - unsigned long size; - void **gop_handle =3D NULL; - - si =3D &boot_params->screen_info; - memset(si, 0, sizeof(*si)); - - size =3D 0; - status =3D efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, - &graphics_proto, NULL, &size, gop_handle); - if (status =3D=3D EFI_BUFFER_TOO_SMALL) - status =3D efi_setup_gop(si, &graphics_proto, size); + struct screen_info *si =3D memset(&boot_params->screen_info, 0, sizeof(*s= i)); =20 + efi_setup_gop(si); } =20 - static void __noreturn efi_exit(efi_handle_t handle, efi_status_t status) { efi_bs_call(exit, handle, status, 0, NULL); --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Sat Feb 7 18:22:59 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65E561C5F13 for ; Fri, 20 Dec 2024 11:22:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693768; cv=none; b=u3bGXnxsENb6eLgqNfjfHFh19e9aXO2E3CzkUJla8LpZCafl8Wwvd/w7P0FfDQpQ/Bif71ZmrZxv3WYOVFPqpmcRYCrQxUaBkS61reV75QKxH9r84ktRYcrsaaPTIYtAxdXH1+H8on+mfqsjqgz/UAiTIjv/l1j68iTcI4wsr88= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693768; c=relaxed/simple; bh=SGrSiYKH1Bc7AsR64Qp4yCfTjgTd1Def+HVGEElIkAE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AISi6w2dKtuH7kn/avXq+Uxf3eHFtAj6PBbvcpgFUQ/4v6+05vp4aX4/+AV5/zQ++H8pNVl4oTDbiANn9NsBQaKf0TAUovYroFyIYdPvoOBRq9dPOcWkfeyxWx/xWA3jp8HsEuIQggEUpJledHx2NWwWZzptiujG4C/LwvJN4pU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Q0Gx189z; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Q0Gx189z" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4361efc9d1fso14092535e9.2 for ; Fri, 20 Dec 2024 03:22:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734693765; x=1735298565; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KivZZf0CGt5YZd1N5rZVDN/3bZWGDmqhLF0VCWNrGlI=; b=Q0Gx189zFX12xNCOP/UbaQycAJiNiZ2jkRn/VYyRkLrKPq35hmL+fduAjXW/NTPkRA 3yCMKSjb7CWMjfdy2i+A26ty+NJ6NuZe+ZH6byNlZgmz6HOHqqfbbhlx3XAervWsbQu2 oOg2X7qG1WiocgX/oBul4OuTrMgYtuh9kZAZ31ntc4VScrCu5wqikqRAbvbxld1uuBqL b8Z+q1MR7sV2uv4S1IkwpLeW7o6bJOJct9IJGCSF4+Sh+AQrB+zJfhz2IT5ug01yGuEb k1XueW7+n2SYI8C8PSSkzLO7EVVezHIA59hGWF+fOEVsnTDs/Vw2wNoPS5aYbhdDjSCi n8Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734693765; x=1735298565; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KivZZf0CGt5YZd1N5rZVDN/3bZWGDmqhLF0VCWNrGlI=; b=LnJafTC/u8MmkqxkxYlvU3NU3436hd2WbyTPhXv/+kOk+vdwyKh6jgmVVXa78caFFH DxJc/s3/1H5gg+cFpHo5KW7jFXpq2rHZW1j71fGA/klynXqSoLJJF8DK73F555XOXmFA 0xlRgwLuwNDHkLq6Hobrxze5hIkgCi+KVQ5ShNnfD7IQUOh+xZom7FrTaZBeexHDtote herSEcQz5K/iVmc5Yfbhl3xnggPNETh6XpHkiMEjAo2fLZ+8IDjehOkf5jhRIlT8Crxz vyjif0sfVLQRBx65qAFtTRKkhSXjhr+6RxpgP0Lj0FSvrf55sN737cC7dcaLGsPEH0Zo OxkA== X-Gm-Message-State: AOJu0Yxg2hqiHyyNLjlhtu5s38bGGajJM1Ef3xLYQJySKAxsdzRYezp3 GZ+uxZ0Py54Wb2wgFlC0Kh7y/NTVYk9OjpCZgW0o9oDh0dyhN0q2s+DQh2jcYJTnWi2nNQ== X-Google-Smtp-Source: AGHT+IHC2StE8w43211zdACLPVBjHL2cKB1h4Sdbs6jqqq4BEWyOvYApZkjHXnA7nXifadO5sC+79YM5 X-Received: from wmbay20.prod.google.com ([2002:a05:600c:1e14:b0:436:1995:1888]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:294c:b0:436:51bb:7a53 with SMTP id 5b1f17b1804b1-43668643ba9mr22260165e9.12.1734693764897; Fri, 20 Dec 2024 03:22:44 -0800 (PST) Date: Fri, 20 Dec 2024 12:22:19 +0100 In-Reply-To: <20241220112214.2598872-9-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220112214.2598872-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=10137; i=ardb@kernel.org; h=from:subject; bh=Ic6NiX9fQ6lT7lNuflzIZfufNkdIR4/g+eMpwHkmBdc=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT01ODfiYuCGtftmZ942vuz2cdP/xeusj0hMTtz4cra2Z dPG6CdTO0pZGMQ4GGTFFFkEZv99t/P0RKla51myMHNYmUCGMHBxCsBETuczMsyuMvhQYLVNZkng 8h3p2t47ndYyWW+vfvjt1stfE5/Jrq5l+Kce9Hnd05LQCMFDj97+/BPu+1BffzHbrRuJ678u/BM suZIXAA== X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220112214.2598872-13-ardb+git@google.com> Subject: [PATCH 4/7] efi/libstub: Refactor and cleanup GOP resolution picker code From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel The EFI stub implements various ways of setting the resolution of the EFI framebuffer at boot, which duplicate a lot of boilerplate for iterating over the supported modes and extracting the resolution and color depth. Refactor this into a single helper that takes a callback, and use it for the 'auto', 'list' and 'res' selection methods. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/gop.c | 265 ++++++++------------ 1 file changed, 103 insertions(+), 162 deletions(-) diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libs= tub/gop.c index fce28488c76c..1e1ec0113904 100644 --- a/drivers/firmware/efi/libstub/gop.c +++ b/drivers/firmware/efi/libstub/gop.c @@ -133,13 +133,11 @@ void efi_parse_option_graphics(char *option) =20 static u32 choose_mode_modenum(efi_graphics_output_protocol_t *gop) { - efi_status_t status; - + efi_graphics_output_mode_info_t *info __free(efi_pool) =3D NULL; efi_graphics_output_protocol_mode_t *mode; - efi_graphics_output_mode_info_t *info; unsigned long info_size; - u32 max_mode, cur_mode; + efi_status_t status; int pf; =20 mode =3D efi_table_attr(gop, mode); @@ -154,17 +152,13 @@ static u32 choose_mode_modenum(efi_graphics_output_pr= otocol_t *gop) return cur_mode; } =20 - status =3D efi_call_proto(gop, query_mode, cmdline.mode, - &info_size, &info); + status =3D efi_call_proto(gop, query_mode, cmdline.mode, &info_size, &inf= o); if (status !=3D EFI_SUCCESS) { efi_err("Couldn't get mode information\n"); return cur_mode; } =20 pf =3D info->pixel_format; - - efi_bs_call(free_pool, info); - if (pf =3D=3D PIXEL_BLT_ONLY || pf >=3D PIXEL_FORMAT_MAX) { efi_err("Invalid PixelFormat\n"); return cur_mode; @@ -173,6 +167,28 @@ static u32 choose_mode_modenum(efi_graphics_output_pro= tocol_t *gop) return cmdline.mode; } =20 +static u32 choose_mode(efi_graphics_output_protocol_t *gop, + bool (*match)(const efi_graphics_output_mode_info_t *, u32, void = *), + void *ctx) +{ + efi_graphics_output_protocol_mode_t *mode =3D efi_table_attr(gop, mode); + u32 max_mode =3D efi_table_attr(mode, max_mode); + + for (u32 m =3D 0; m < max_mode; m++) { + efi_graphics_output_mode_info_t *info __free(efi_pool) =3D NULL; + unsigned long info_size; + efi_status_t status; + + status =3D efi_call_proto(gop, query_mode, m, &info_size, &info); + if (status !=3D EFI_SUCCESS) + continue; + + if (match(info, m, ctx)) + return m; + } + return (unsigned long)ctx; +} + static u8 pixel_bpp(int pixel_format, efi_pixel_bitmask_t pixel_info) { if (pixel_format =3D=3D PIXEL_BIT_MASK) { @@ -185,192 +201,117 @@ static u8 pixel_bpp(int pixel_format, efi_pixel_bit= mask_t pixel_info) return 32; } =20 -static u32 choose_mode_res(efi_graphics_output_protocol_t *gop) +static bool match_res(const efi_graphics_output_mode_info_t *info, u32 mod= e, void *ctx) { - efi_status_t status; + efi_pixel_bitmask_t pi =3D info->pixel_information; + int pf =3D info->pixel_format; =20 - efi_graphics_output_protocol_mode_t *mode; - efi_graphics_output_mode_info_t *info; - unsigned long info_size; - - u32 max_mode, cur_mode; - int pf; - efi_pixel_bitmask_t pi; - u32 m, w, h; + if (pf =3D=3D PIXEL_BLT_ONLY || pf >=3D PIXEL_FORMAT_MAX) + return false; =20 - mode =3D efi_table_attr(gop, mode); + return cmdline.res.width =3D=3D info->horizontal_resolution && + cmdline.res.height =3D=3D info->vertical_resolution && + (cmdline.res.format < 0 || cmdline.res.format =3D=3D pf) && + (!cmdline.res.depth || cmdline.res.depth =3D=3D pixel_bpp(pf, pi)); +} =20 - cur_mode =3D efi_table_attr(mode, mode); - info =3D efi_table_attr(mode, info); - pf =3D info->pixel_format; - pi =3D info->pixel_information; - w =3D info->horizontal_resolution; - h =3D info->vertical_resolution; +static u32 choose_mode_res(efi_graphics_output_protocol_t *gop) +{ + efi_graphics_output_protocol_mode_t *mode =3D efi_table_attr(gop, mode); + unsigned long cur_mode =3D efi_table_attr(mode, mode); =20 - if (w =3D=3D cmdline.res.width && h =3D=3D cmdline.res.height && - (cmdline.res.format < 0 || cmdline.res.format =3D=3D pf) && - (!cmdline.res.depth || cmdline.res.depth =3D=3D pixel_bpp(pf, pi))) + if (match_res(efi_table_attr(mode, info), cur_mode, NULL)) return cur_mode; =20 - max_mode =3D efi_table_attr(mode, max_mode); - - for (m =3D 0; m < max_mode; m++) { - if (m =3D=3D cur_mode) - continue; - - status =3D efi_call_proto(gop, query_mode, m, - &info_size, &info); - if (status !=3D EFI_SUCCESS) - continue; + return choose_mode(gop, match_res, (void *)cur_mode); +} =20 - pf =3D info->pixel_format; - pi =3D info->pixel_information; - w =3D info->horizontal_resolution; - h =3D info->vertical_resolution; +struct match { + u32 mode; + u32 area; + u8 depth; +}; =20 - efi_bs_call(free_pool, info); +static bool match_auto(const efi_graphics_output_mode_info_t *info, u32 mo= de, void *ctx) +{ + u32 area =3D info->horizontal_resolution * info->vertical_resolution; + efi_pixel_bitmask_t pi =3D info->pixel_information; + int pf =3D info->pixel_format; + u8 depth =3D pixel_bpp(pf, pi); + struct match *m =3D ctx; =20 - if (pf =3D=3D PIXEL_BLT_ONLY || pf >=3D PIXEL_FORMAT_MAX) - continue; - if (w =3D=3D cmdline.res.width && h =3D=3D cmdline.res.height && - (cmdline.res.format < 0 || cmdline.res.format =3D=3D pf) && - (!cmdline.res.depth || cmdline.res.depth =3D=3D pixel_bpp(pf, pi))) - return m; - } + if (pf =3D=3D PIXEL_BLT_ONLY || pf >=3D PIXEL_FORMAT_MAX) + return false; =20 - efi_err("Couldn't find requested mode\n"); + if (area > m->area || (area =3D=3D m->area && depth > m->depth)) + *m =3D (struct match){ mode, area, depth }; =20 - return cur_mode; + return false; } =20 static u32 choose_mode_auto(efi_graphics_output_protocol_t *gop) { - efi_status_t status; + struct match match =3D {}; =20 - efi_graphics_output_protocol_mode_t *mode; - efi_graphics_output_mode_info_t *info; - unsigned long info_size; + choose_mode(gop, match_auto, &match); =20 - u32 max_mode, cur_mode, best_mode, area; - u8 depth; - int pf; - efi_pixel_bitmask_t pi; - u32 m, w, h, a; - u8 d; - - mode =3D efi_table_attr(gop, mode); - - cur_mode =3D efi_table_attr(mode, mode); - max_mode =3D efi_table_attr(mode, max_mode); - - info =3D efi_table_attr(mode, info); - - pf =3D info->pixel_format; - pi =3D info->pixel_information; - w =3D info->horizontal_resolution; - h =3D info->vertical_resolution; - - best_mode =3D cur_mode; - area =3D w * h; - depth =3D pixel_bpp(pf, pi); - - for (m =3D 0; m < max_mode; m++) { - if (m =3D=3D cur_mode) - continue; - - status =3D efi_call_proto(gop, query_mode, m, - &info_size, &info); - if (status !=3D EFI_SUCCESS) - continue; + return match.mode; +} =20 - pf =3D info->pixel_format; - pi =3D info->pixel_information; - w =3D info->horizontal_resolution; - h =3D info->vertical_resolution; +static bool match_list(const efi_graphics_output_mode_info_t *info, u32 mo= de, void *ctx) +{ + efi_pixel_bitmask_t pi =3D info->pixel_information; + u32 cur_mode =3D (unsigned long)ctx; + int pf =3D info->pixel_format; + const char *dstr; + bool valid; + u8 depth; =20 - efi_bs_call(free_pool, info); + valid =3D !(pf =3D=3D PIXEL_BLT_ONLY || pf >=3D PIXEL_FORMAT_MAX); =20 - if (pf =3D=3D PIXEL_BLT_ONLY || pf >=3D PIXEL_FORMAT_MAX) - continue; - a =3D w * h; - if (a < area) - continue; - d =3D pixel_bpp(pf, pi); - if (a > area || d > depth) { - best_mode =3D m; - area =3D a; - depth =3D d; - } + switch (pf) { + case PIXEL_RGB_RESERVED_8BIT_PER_COLOR: + dstr =3D "rgb"; + break; + case PIXEL_BGR_RESERVED_8BIT_PER_COLOR: + dstr =3D "bgr"; + break; + case PIXEL_BIT_MASK: + dstr =3D ""; + depth =3D pixel_bpp(pf, pi); + break; + case PIXEL_BLT_ONLY: + dstr =3D "blt"; + break; + default: + dstr =3D "xxx"; + break; } =20 - return best_mode; + efi_printk("Mode %3u %c%c: Resolution %ux%u-%s%.0hhu\n", + mode, + (mode =3D=3D cur_mode) ? '*' : ' ', + !valid ? '-' : ' ', + info->horizontal_resolution, + info->vertical_resolution, + dstr, depth); + + return false; } =20 static u32 choose_mode_list(efi_graphics_output_protocol_t *gop) { - efi_status_t status; - - efi_graphics_output_protocol_mode_t *mode; - efi_graphics_output_mode_info_t *info; - unsigned long info_size; - - u32 max_mode, cur_mode; - int pf; - efi_pixel_bitmask_t pi; - u32 m, w, h; - u8 d; - const char *dstr; - bool valid; + efi_graphics_output_protocol_mode_t *mode =3D efi_table_attr(gop, mode); + unsigned long cur_mode =3D efi_table_attr(mode, mode); + u32 max_mode =3D efi_table_attr(mode, max_mode); efi_input_key_t key; - - mode =3D efi_table_attr(gop, mode); - - cur_mode =3D efi_table_attr(mode, mode); - max_mode =3D efi_table_attr(mode, max_mode); + efi_status_t status; =20 efi_printk("Available graphics modes are 0-%u\n", max_mode-1); efi_puts(" * =3D current mode\n" " - =3D unusable mode\n"); - for (m =3D 0; m < max_mode; m++) { - status =3D efi_call_proto(gop, query_mode, m, - &info_size, &info); - if (status !=3D EFI_SUCCESS) - continue; =20 - pf =3D info->pixel_format; - pi =3D info->pixel_information; - w =3D info->horizontal_resolution; - h =3D info->vertical_resolution; - - efi_bs_call(free_pool, info); - - valid =3D !(pf =3D=3D PIXEL_BLT_ONLY || pf >=3D PIXEL_FORMAT_MAX); - d =3D 0; - switch (pf) { - case PIXEL_RGB_RESERVED_8BIT_PER_COLOR: - dstr =3D "rgb"; - break; - case PIXEL_BGR_RESERVED_8BIT_PER_COLOR: - dstr =3D "bgr"; - break; - case PIXEL_BIT_MASK: - dstr =3D ""; - d =3D pixel_bpp(pf, pi); - break; - case PIXEL_BLT_ONLY: - dstr =3D "blt"; - break; - default: - dstr =3D "xxx"; - break; - } - - efi_printk("Mode %3u %c%c: Resolution %ux%u-%s%.0hhu\n", - m, - m =3D=3D cur_mode ? '*' : ' ', - !valid ? '-' : ' ', - w, h, dstr, d); - } + choose_mode(gop, match_list, (void *)cur_mode); =20 efi_puts("\nPress any key to continue (or wait 10 seconds)\n"); status =3D efi_wait_for_key(10 * EFI_USEC_PER_SEC, &key); --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Sat Feb 7 18:22:59 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5670C1C5F28 for ; Fri, 20 Dec 2024 11:22:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693770; cv=none; b=AVIyCwUvHTEsEAkJ5aeZIRIXPYgYGcJrhc1HfyGih8CP6+u1mEZqO8yRq15j3Z5xeekOvcxTg/Gl92J1g2wjGmC6JgMwYCj3NDdFyPSqD8px7BNx4W2whNmKOyipdFJBO4D8KmTQvH3hcG12yBsN+7Qw8rVJv3uZnnyfR//NpM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693770; c=relaxed/simple; bh=jQFPnAR/lQIH41XKJNrgOYB+xxnzwuDMJoLacFjQ9Rg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ow02vIC2bamVpyQAR3Q+Xav/nxOgHYovr10BTYUUfzLAOYlASX8EQzljEsd6vvMBi8mSQwPxyZKjjMib5WuJ15mU/MOfv7fBorT9JGSrynmZ90bC4hI3CDj70mPPgKB/KfH1B2MqyG+P0DEBEoxy0ZKgwB9FJOVhLDSV02GGgeI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Lthm7nYl; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Lthm7nYl" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-43582d49dacso13975455e9.2 for ; Fri, 20 Dec 2024 03:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734693767; x=1735298567; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4ZdfudFQMgX/SPnuBiPXL83yln9iyupuULighNWJ+Tk=; b=Lthm7nYlaizzC5fYhDMLy5wq/qv6kgIrADGeewIxg5NXyjM8MJM552lHyHZd4fIgzp xS8PDxCZ5ifQ9rN4zSduix085J1pomssYh/HcZyeXw5TOT9hQmIP/G7Ohc+B2SbDCKRM 2+gt25aMJgIChJeJMG5PBbsz8pfMlRdtHxR1LH6ING6EzeRi7yU3LdNigQoprdGUFdP+ bZz+q5ANdcYDsX6Q5uPtY7yTiSJzeFkQmAm+KDPUW7pLSY9O8FB1kdVxkWo0HuScgYk3 k6/bFRLwOQ6vHOzkLZiW04I3vU0Eh5L2L08+z8uylCHPOCQZnsIu1mpl778HNHpOB4qE OuKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734693767; x=1735298567; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4ZdfudFQMgX/SPnuBiPXL83yln9iyupuULighNWJ+Tk=; b=tyryjEADsak4/lMt05+0HXebmuaPNbd/ux3Gm8vwcQ0bnOR7PV6oEPzNbaXrygTNMQ OVwiJXYzmy3JhEEq4EAhsU6vsM0DxTie2OZULIrrK4FJsTrnXXtIwMYjw+HajjD74K4C r01uZTa0+muacH0OTfS38mqBu27ZOOchWJLjWtqwBLf+wDezl2UtW+o7M8c5lpEq1LcS XGj+odHUTbrKx3Dm0q9xf3SdN5n4JUz7RbqOoAhvBvRsT/9NWetVqsSZR8LYWDzRRjTp pnjh6wsUzhEw8B/631mEYZf0hr45g4URegrgOzuegNyl2EUnzaTCMexyGFTXOyJp2ceY exJg== X-Gm-Message-State: AOJu0YxGGJGwQKJHI+YrJSpkAi1p3wn/4Q8Xk1iBJMCgN/Sdk9rWSiR3 n9ap+E5uPTAJSBDZ84FK2HnjH18WHj2sV+uUIyd720ezXBoiqTar/8HvWdrGb+KJbfJm4Q== X-Google-Smtp-Source: AGHT+IHImMIL/xdHSaYtb96ILTwp8HE90q+uERYMRCTtZuhOxoziiMyV2AhqGsbIAkkH0hOTaJxgqEkG X-Received: from wmbjn12.prod.google.com ([2002:a05:600c:6b0c:b0:435:4bd2:1dcd]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4f0d:b0:432:cbe5:4f09 with SMTP id 5b1f17b1804b1-43671247b46mr135995e9.4.1734693766818; Fri, 20 Dec 2024 03:22:46 -0800 (PST) Date: Fri, 20 Dec 2024 12:22:20 +0100 In-Reply-To: <20241220112214.2598872-9-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220112214.2598872-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4607; i=ardb@kernel.org; h=from:subject; bh=/nPnk008oitHG0r/EWed5C0pBvsJuMEBmFXGRgsWLSY=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT01OO+93t8LRY/mx0t1/z/ZcN/bTHdNtaiz7r95X93/f RT+UCLbUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACbys5GRYa9ydezH/SHZuUny nZcesfR/jRU6fMW0btNbWR6vyXqTnRn+ypbIHJf3V7fPUO0M3b1yE9ObHS6feZfLhrM9LFjitNS XAQA= X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220112214.2598872-14-ardb+git@google.com> Subject: [PATCH 5/7] efi/libstub: Simplify PCI I/O handle buffer traversal From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Use LocateHandleBuffer() and a __free() cleanup helper to simplify the PCI I/O handle buffer traversal code. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/pci.c | 33 +++++--------------- drivers/firmware/efi/libstub/x86-stub.c | 29 ++++------------- 2 files changed, 13 insertions(+), 49 deletions(-) diff --git a/drivers/firmware/efi/libstub/pci.c b/drivers/firmware/efi/libs= tub/pci.c index b0ba372c26c5..e32d1fdb1fc7 100644 --- a/drivers/firmware/efi/libstub/pci.c +++ b/drivers/firmware/efi/libstub/pci.c @@ -16,36 +16,20 @@ void efi_pci_disable_bridge_busmaster(void) { efi_guid_t pci_proto =3D EFI_PCI_IO_PROTOCOL_GUID; - unsigned long pci_handle_size =3D 0; - efi_handle_t *pci_handle =3D NULL; + efi_handle_t *pci_handle __free(efi_pool) =3D NULL; + unsigned long pci_handle_num; efi_handle_t handle; efi_status_t status; u16 class, command; =20 - status =3D efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, &pci_proto, - NULL, &pci_handle_size, NULL); - - if (status !=3D EFI_BUFFER_TOO_SMALL) { - if (status !=3D EFI_SUCCESS && status !=3D EFI_NOT_FOUND) - efi_err("Failed to locate PCI I/O handles'\n"); - return; - } - - status =3D efi_bs_call(allocate_pool, EFI_LOADER_DATA, pci_handle_size, - (void **)&pci_handle); - if (status !=3D EFI_SUCCESS) { - efi_err("Failed to allocate memory for 'pci_handle'\n"); - return; - } - - status =3D efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, &pci_proto, - NULL, &pci_handle_size, pci_handle); + status =3D efi_bs_call(locate_handle_buffer, EFI_LOCATE_BY_PROTOCOL, + &pci_proto, NULL, &pci_handle_num, pci_handle); if (status !=3D EFI_SUCCESS) { efi_err("Failed to locate PCI I/O handles'\n"); - goto free_handle; + return; } =20 - for_each_efi_handle(handle, pci_handle, efi_get_handle_num(pci_handle_siz= e)) { + for_each_efi_handle(handle, pci_handle, pci_handle_num) { efi_pci_io_protocol_t *pci; unsigned long segment_nr, bus_nr, device_nr, func_nr; =20 @@ -81,7 +65,7 @@ void efi_pci_disable_bridge_busmaster(void) efi_bs_call(disconnect_controller, handle, NULL, NULL); } =20 - for_each_efi_handle(handle, pci_handle, efi_get_handle_num(pci_handle_siz= e)) { + for_each_efi_handle(handle, pci_handle, pci_handle_num) { efi_pci_io_protocol_t *pci; =20 status =3D efi_bs_call(handle_protocol, handle, &pci_proto, @@ -107,7 +91,4 @@ void efi_pci_disable_bridge_busmaster(void) if (status !=3D EFI_SUCCESS) efi_err("Failed to disable PCI busmastering\n"); } - -free_handle: - efi_bs_call(free_pool, pci_handle); } diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index 53da6b5be739..4a3487e5dfc8 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -119,37 +119,23 @@ preserve_pci_rom_image(efi_pci_io_protocol_t *pci, st= ruct pci_setup_rom **__rom) static void setup_efi_pci(struct boot_params *params) { efi_status_t status; - void **pci_handle =3D NULL; + efi_handle_t *pci_handle __free(efi_pool) =3D NULL; efi_guid_t pci_proto =3D EFI_PCI_IO_PROTOCOL_GUID; - unsigned long size =3D 0; struct setup_data *data; + unsigned long num; efi_handle_t h; =20 - status =3D efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, - &pci_proto, NULL, &size, pci_handle); - - if (status =3D=3D EFI_BUFFER_TOO_SMALL) { - status =3D efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, - (void **)&pci_handle); - - if (status !=3D EFI_SUCCESS) { - efi_err("Failed to allocate memory for 'pci_handle'\n"); - return; - } - - status =3D efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, - &pci_proto, NULL, &size, pci_handle); - } - + status =3D efi_bs_call(locate_handle_buffer, EFI_LOCATE_BY_PROTOCOL, + &pci_proto, NULL, &num, pci_handle); if (status !=3D EFI_SUCCESS) - goto free_handle; + return; =20 data =3D (struct setup_data *)(unsigned long)params->hdr.setup_data; =20 while (data && data->next) data =3D (struct setup_data *)(unsigned long)data->next; =20 - for_each_efi_handle(h, pci_handle, efi_get_handle_num(size)) { + for_each_efi_handle(h, pci_handle, num) { efi_pci_io_protocol_t *pci =3D NULL; struct pci_setup_rom *rom; =20 @@ -169,9 +155,6 @@ static void setup_efi_pci(struct boot_params *params) =20 data =3D (struct setup_data *)rom; } - -free_handle: - efi_bs_call(free_pool, pci_handle); } =20 static void retrieve_apple_device_properties(struct boot_params *boot_para= ms) --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Sat Feb 7 18:22:59 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A8AF1C68BE for ; Fri, 20 Dec 2024 11:22:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693772; cv=none; b=OoqiEeDoj7W9YyWSUtecZ1suRZUzN6CYBxJRc3DjcyLornwhCmN4EYg06Pwkfz0R3l9FzAah1HVaJoXmOGwbOzR8Q/N4HlKjauZ7DMjLQ9P9KDNcXSZCGydbG7tO5FLmkYHqwz2TMQpjvnsreG4QizQ2gG61IF/Xy2zP/AE5yDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693772; c=relaxed/simple; bh=lVMPdicFtyOL832rAMJvK98velTQ2FkjUowJ3Igxmkg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=t6gmCYlkORyPFEbYNwUSE2TJYFmK1yRiCMJ0K5iys7uJ1GwdRFPPzppclrKCQCBzqS3Ztr6VkaXxg8ZFy3/4hEletT6SDz4Yus7zjbea3DtoqQOjdFiRgBCUpYuQFWTCEno8eg/71zLMT/Bga+F9RKO5gFwX189vjtV3g7xc8dE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fJGRjDyM; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fJGRjDyM" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-38639b4f19cso1222936f8f.0 for ; Fri, 20 Dec 2024 03:22:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734693768; x=1735298568; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5Mq2zGEkSU736hh4kdcV8OEsSkyXvgmpNv1UZJcoKL4=; b=fJGRjDyM4GeJvfeW4RgSE8/NG5UoIK751E/KDX0pGsj28sKtIY6f6WTCaxMlpaIVyd AAweczYCW9oLZkc+q4vtTs/avBWpPc0MBjIjk2bu96gbW7LwH6wJZNfZNQaXgA8enVyu YDDEv/jlRg2bwrkDMmtAq6u1ZakaBydKPkAkw+hsj4NFVtEQimZncVjF4tYrqyRfgwJU erHrpJz0bGg01QOyztcN7Lixk8v1/Kq8/sVhy1mJU6g3QWl/IM1IFmJs2bm17f5nvMGI MrcvJr2JFS1YrhdxbjectcJ/nDyEERuySWMZMw1zbzAUXo2H+9K7bzNnDpCmWmRIXKtN LM+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734693768; x=1735298568; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5Mq2zGEkSU736hh4kdcV8OEsSkyXvgmpNv1UZJcoKL4=; b=qNrsidcPnYu9lWVeCkFDPtnbkjqwsHxfSBUxIbiqgYaOJVABKjWINI/g5+lD3bp7kI 9ORToW9mz1De+QyVLaEezCJeRd5NIsEFkaM33iWu2sF+tYu+nVdOTR/kkUcxvPaSZTNt V9ZWo8nOUih9XqfSKhheh81FLnM65o3Pk3q8aVbVD6V5MKvyJAgrEc8fAbgRSCpBbab4 uh7MgoR7I7ukXVEHEieUZnyoptEBsxiF6VZLyZL0V8XmDGFf06569m4sy0DveTJh1m4K jjFZ0nJxPNdrZmFQ+oNxTqKCjrpNwqkHIno7iMcWaPLjv7zqawXTnZaR8tZ2fFSxwOND hYKQ== X-Gm-Message-State: AOJu0YzmNWORFuG0VzM+RZ6RnlE0BfO3WHWYwqulF1ixlZPEVetyAy5j k3D7niYXBsc27g28DSGj425r4tdsorhalVl2tyVpY6vGWu10WuTWmfdZ6lP6b2Upa6vj0w== X-Google-Smtp-Source: AGHT+IHEnq1PDrJx6ZoitqXOfRW6JfLWhdmj4+pCY+eWOZ7BG4KZEaQvyMHTmEkr7l76dh8wiKxxSpq3 X-Received: from wmbhn29.prod.google.com ([2002:a05:600c:a39d:b0:434:fe74:1bd5]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:18a9:b0:386:3835:9fff with SMTP id ffacd0b85a97d-38a22406d43mr2840931f8f.59.1734693768819; Fri, 20 Dec 2024 03:22:48 -0800 (PST) Date: Fri, 20 Dec 2024 12:22:21 +0100 In-Reply-To: <20241220112214.2598872-9-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220112214.2598872-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=5660; i=ardb@kernel.org; h=from:subject; bh=YLK9emTD2b7V0uTyYE0d8W4Cjh6Qxt9ydF/yoBPkTls=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT01uGA9p+/C/+d1M41rLlxd19jocPr/Arv0U/Fzxee3a JYbb1zSUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACYiP4+RYcKhTeIZahGT3r+I zW6wdkhVfM74zO53rdXvrQ/s1+11DGX477fiu1NYxLHJp1Ke7WBcccz00szb/HunLPzXt/xmI8P JjcwA X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220112214.2598872-15-ardb+git@google.com> Subject: [PATCH 6/7] efi/libstub: Use cleanup helpers for freeing copies of the memory map From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel The EFI stub may obtain the memory map from the firmware numerous times, and this involves doing a EFI pool allocation first, which needs to be freed after use. Streamline this using a cleanup helper, which makes the code easier to follow. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/kaslr.c | 4 +--- drivers/firmware/efi/libstub/mem.c | 20 ++++++++------------ drivers/firmware/efi/libstub/randomalloc.c | 4 +--- drivers/firmware/efi/libstub/relocate.c | 10 ++++------ drivers/firmware/efi/libstub/x86-stub.c | 11 ++++++----- 5 files changed, 20 insertions(+), 29 deletions(-) diff --git a/drivers/firmware/efi/libstub/kaslr.c b/drivers/firmware/efi/li= bstub/kaslr.c index 6318c40bda38..4bc963e999eb 100644 --- a/drivers/firmware/efi/libstub/kaslr.c +++ b/drivers/firmware/efi/libstub/kaslr.c @@ -57,7 +57,7 @@ u32 efi_kaslr_get_phys_seed(efi_handle_t image_handle) */ static bool check_image_region(u64 base, u64 size) { - struct efi_boot_memmap *map; + struct efi_boot_memmap *map __free(efi_pool) =3D NULL; efi_status_t status; bool ret =3D false; int map_offset; @@ -80,8 +80,6 @@ static bool check_image_region(u64 base, u64 size) } } =20 - efi_bs_call(free_pool, map); - return ret; } =20 diff --git a/drivers/firmware/efi/libstub/mem.c b/drivers/firmware/efi/libs= tub/mem.c index 4f1fa302234d..9c82259eea81 100644 --- a/drivers/firmware/efi/libstub/mem.c +++ b/drivers/firmware/efi/libstub/mem.c @@ -20,10 +20,10 @@ efi_status_t efi_get_memory_map(struct efi_boot_memmap **map, bool install_cfg_tbl) { + struct efi_boot_memmap tmp, *m __free(efi_pool) =3D NULL; int memtype =3D install_cfg_tbl ? EFI_ACPI_RECLAIM_MEMORY : EFI_LOADER_DATA; efi_guid_t tbl_guid =3D LINUX_EFI_BOOT_MEMMAP_GUID; - struct efi_boot_memmap *m, tmp; efi_status_t status; unsigned long size; =20 @@ -48,24 +48,20 @@ efi_status_t efi_get_memory_map(struct efi_boot_memmap = **map, */ status =3D efi_bs_call(install_configuration_table, &tbl_guid, m); if (status !=3D EFI_SUCCESS) - goto free_map; + return status; } =20 m->buff_size =3D m->map_size =3D size; status =3D efi_bs_call(get_memory_map, &m->map_size, m->map, &m->map_key, &m->desc_size, &m->desc_ver); - if (status !=3D EFI_SUCCESS) - goto uninstall_table; + if (status !=3D EFI_SUCCESS) { + if (install_cfg_tbl) + efi_bs_call(install_configuration_table, &tbl_guid, NULL); + return status; + } =20 - *map =3D m; + *map =3D no_free_ptr(m); return EFI_SUCCESS; - -uninstall_table: - if (install_cfg_tbl) - efi_bs_call(install_configuration_table, &tbl_guid, NULL); -free_map: - efi_bs_call(free_pool, m); - return status; } =20 /** diff --git a/drivers/firmware/efi/libstub/randomalloc.c b/drivers/firmware/= efi/libstub/randomalloc.c index c41e7b2091cd..e5872e38d9a4 100644 --- a/drivers/firmware/efi/libstub/randomalloc.c +++ b/drivers/firmware/efi/libstub/randomalloc.c @@ -59,9 +59,9 @@ efi_status_t efi_random_alloc(unsigned long size, unsigned long alloc_min, unsigned long alloc_max) { + struct efi_boot_memmap *map __free(efi_pool) =3D NULL; unsigned long total_slots =3D 0, target_slot; unsigned long total_mirrored_slots =3D 0; - struct efi_boot_memmap *map; efi_status_t status; int map_offset; =20 @@ -130,7 +130,5 @@ efi_status_t efi_random_alloc(unsigned long size, break; } =20 - efi_bs_call(free_pool, map); - return status; } diff --git a/drivers/firmware/efi/libstub/relocate.c b/drivers/firmware/efi= /libstub/relocate.c index d694bcfa1074..99b45d1cd624 100644 --- a/drivers/firmware/efi/libstub/relocate.c +++ b/drivers/firmware/efi/libstub/relocate.c @@ -23,14 +23,14 @@ efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align, unsigned long *addr, unsigned long min) { - struct efi_boot_memmap *map; + struct efi_boot_memmap *map __free(efi_pool) =3D NULL; efi_status_t status; unsigned long nr_pages; int i; =20 status =3D efi_get_memory_map(&map, false); if (status !=3D EFI_SUCCESS) - goto fail; + return status; =20 /* * Enforce minimum alignment that EFI or Linux requires when @@ -79,11 +79,9 @@ efi_status_t efi_low_alloc_above(unsigned long size, uns= igned long align, } =20 if (i =3D=3D map->map_size / map->desc_size) - status =3D EFI_NOT_FOUND; + return EFI_NOT_FOUND; =20 - efi_bs_call(free_pool, map); -fail: - return status; + return EFI_SUCCESS; } =20 /** diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index 4a3487e5dfc8..4dfd25e6ac71 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -616,7 +616,7 @@ static efi_status_t allocate_e820(struct boot_params *p= arams, struct setup_data **e820ext, u32 *e820ext_size) { - struct efi_boot_memmap *map; + struct efi_boot_memmap *map __free(efi_pool) =3D NULL; efi_status_t status; __u32 nr_desc; =20 @@ -630,13 +630,14 @@ static efi_status_t allocate_e820(struct boot_params = *params, EFI_MMAP_NR_SLACK_SLOTS; =20 status =3D alloc_e820ext(nr_e820ext, e820ext, e820ext_size); + if (status !=3D EFI_SUCCESS) + return status; } =20 - if (IS_ENABLED(CONFIG_UNACCEPTED_MEMORY) && status =3D=3D EFI_SUCCESS) - status =3D allocate_unaccepted_bitmap(nr_desc, map); + if (IS_ENABLED(CONFIG_UNACCEPTED_MEMORY)) + return allocate_unaccepted_bitmap(nr_desc, map); =20 - efi_bs_call(free_pool, map); - return status; + return EFI_SUCCESS; } =20 struct exit_boot_struct { --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Sat Feb 7 18:22:59 2026 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33A2E1CBE96 for ; Fri, 20 Dec 2024 11:22:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693774; cv=none; b=eiDIVrFaApjyy9OiMwC4csWnd/jb/jGNeemX/fgqJXa0ThLggk2XkT7levvIVLP4AYMuCK6PoYlbMTvgsjhBlrhIwDS27zaLiekt19V8N2Ex4sVBL/mEGkzQRNDBqysHEH+xuIhOLOxcAGuai/CDoCCS9YWXhXkzXMaWw0B1lq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693774; c=relaxed/simple; bh=16iKVImPte4Q3WShcCqcfMjR3u7rPsH1PIwZqgFwKNU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ufuPJcmT6R4nCvT9DLCVAAoOd0q8DomeC6zksjdpWJmhy6EMznIGvlD+jZYlJFi9R1Htmi5agLP+bJUO0em+OQk9mO6mf+jSgdkKvbaiKt53m2+EaP7bgmMgfE0RwVqy4wK6XCWsLJcWNExyeN3mMj0FmHfu5qmzzTGLu+0VN9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DYpQNhje; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DYpQNhje" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4361a8fc3bdso10132315e9.2 for ; Fri, 20 Dec 2024 03:22:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734693770; x=1735298570; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lHLbvVQPBhBByrX4m9XvjRmmcb5HxLT/kjwhrJBKnr8=; b=DYpQNhjeEDEiUnoJxAcG+L81Un3/6XRajjPC7O0W8Ncxgc54ggiNTegpygcQ7guESI ilabIEi1IRTuV6xEQTDo3mlpdh73hf2U7hBFeoY6aGqyULZWE0OYox4wCr3y1kgG006R stKYXMGSWfU0UIIu1c1f0GrCVMspWV2z8f/RWissyAXKkbCDQ+V99h7YV/1qf4/T/0Z8 5D/ErscZwa9smHRvaqBq0hjAIuTVU/Aee7+XzBbmHkBrlLS00rMzAr++Bsoywn1eDyG9 b1o8l6idFNnmHNhEPuP0+jwZXfNnG2PbLTLuYByq4G6yG1zzHlWyF+SOmlmRzao5ixpE YJ1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734693770; x=1735298570; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lHLbvVQPBhBByrX4m9XvjRmmcb5HxLT/kjwhrJBKnr8=; b=folxxLjsQVhDWze0zyUjejX6vgN+MnAqWWibr15H7lO1sUB1xKPTFjfkaNRtK74ub/ nAdTazVSU3U9oMvxCbM0Eeox3ANjzQFol5UgtdW0PGehqFGLjyzjjvQ07PbnFuLDLrLM CwPmPJb6laBtjeOlBn3hkABQetCMibPMm0pNJbJafZRIXVK+LpMvvMbkvLE3GzpHIASN zS/9OjOT1jPvO7fyiOT/CaKiw9EqxxrKJjKZJNVq4TBC2SUBDYLB2voB1rPAqxwHMY2Q 7jBTrVP948mAwvxflDtwX+m83pHgAkZimfDTNI7BMEpVdnNEgdClDAskjcpwc0yesmIs PEdA== X-Gm-Message-State: AOJu0YymaGG18IYwyB6NuVKFPJPZowMK3ZMGTlrcuxPhlFnrdHKN/FoL Dm4F/9sLpqn1xm79SlbLDmg/0ExqGmYVT1SgYo+qpy1QGvXqL7KvAo3xM0cfudNh1J/PUw== X-Google-Smtp-Source: AGHT+IFfpcbxYvQshEs3e4Dk4tdzJxIzJwuNEo5SczSb3OkxWUkg2WxGa3gNNsxnoBpvBrIqnw0afadc X-Received: from wmox17.prod.google.com ([2002:a05:600c:1791:b0:436:164a:763e]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:a0a:b0:434:f0df:9f6 with SMTP id 5b1f17b1804b1-4366854737fmr22340085e9.3.1734693770825; Fri, 20 Dec 2024 03:22:50 -0800 (PST) Date: Fri, 20 Dec 2024 12:22:22 +0100 In-Reply-To: <20241220112214.2598872-9-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220112214.2598872-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=5256; i=ardb@kernel.org; h=from:subject; bh=duZrOElq0qpO0f9uxS54lPTgiTD/koygRLoGgpOpZdc=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT01uLDWStpYa5qlDMtEp/ZIhlWGookL9kYISh69GqrcL 92aubWjlIVBjINBVkyRRWD233c7T0+UqnWeJQszh5UJZAgDF6cATIQjkeF/Ro1n+43ZphkPVx0q m7zuYnXKS3PP1J2KE3+cvFy8JO0iB8N/l3W2Sj3f4472Tczw28Fxf3/NbNk3zgoiFcq3+y7d1ut nBwA= X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220112214.2598872-16-ardb+git@google.com> Subject: [PATCH 7/7] efi/libstub: Use __free() helper for pool deallocations From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Annotate some local buffer allocations as __free(efi_pool) and simplify the associated error handling accordingly. This removes a couple of gotos and simplifies the code. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efi-stub-helper.c | 9 ++++----- drivers/firmware/efi/libstub/efi-stub.c | 21 ++++++++++---------- drivers/firmware/efi/libstub/x86-stub.c | 16 ++++++--------- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmw= are/efi/libstub/efi-stub-helper.c index c0c81ca4237e..fd6dc790c5a8 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -47,9 +47,10 @@ bool __pure __efi_soft_reserve_enabled(void) */ efi_status_t efi_parse_options(char const *cmdline) { - size_t len; + char *buf __free(efi_pool) =3D NULL; efi_status_t status; - char *str, *buf; + size_t len; + char *str; =20 if (!cmdline) return EFI_SUCCESS; @@ -102,7 +103,6 @@ efi_status_t efi_parse_options(char const *cmdline) efi_parse_option_graphics(val + strlen("efifb:")); } } - efi_bs_call(free_pool, buf); return EFI_SUCCESS; } =20 @@ -250,7 +250,7 @@ static efi_status_t efi_measure_tagged_event(unsigned l= ong load_addr, u64, const union efistub_event *); struct { u32 hash_log_extend_event; } mixed_mode; } method; - struct efistub_measured_event *evt; + struct efistub_measured_event *evt __free(efi_pool) =3D NULL; int size =3D struct_size(evt, tagged_event.tagged_event_data, events[event].event_data_len); efi_guid_t tcg2_guid =3D EFI_TCG2_PROTOCOL_GUID; @@ -312,7 +312,6 @@ static efi_status_t efi_measure_tagged_event(unsigned l= ong load_addr, =20 status =3D efi_fn_call(&method, hash_log_extend_event, protocol, 0, load_addr, load_size, &evt->event_data); - efi_bs_call(free_pool, evt); =20 if (status =3D=3D EFI_SUCCESS) return EFI_SUCCESS; diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi= /libstub/efi-stub.c index 90e06a6b1a45..874f63b4a383 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -104,8 +104,8 @@ static u32 get_supported_rt_services(void) =20 efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_= ptr) { + char *cmdline __free(efi_pool) =3D NULL; efi_status_t status; - char *cmdline; =20 /* * Get the command line from EFI, using the LOADED_IMAGE @@ -120,25 +120,24 @@ efi_status_t efi_handle_cmdline(efi_loaded_image_t *i= mage, char **cmdline_ptr) =20 if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { status =3D efi_parse_options(cmdline); - if (status !=3D EFI_SUCCESS) - goto fail_free_cmdline; + if (status !=3D EFI_SUCCESS) { + efi_err("Failed to parse EFI load options\n"); + return status; + } } =20 if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || IS_ENABLED(CONFIG_CMDLINE_FORCE) || cmdline[0] =3D=3D 0) { status =3D efi_parse_options(CONFIG_CMDLINE); - if (status !=3D EFI_SUCCESS) - goto fail_free_cmdline; + if (status !=3D EFI_SUCCESS) { + efi_err("Failed to parse built-in command line\n"); + return status; + } } =20 - *cmdline_ptr =3D cmdline; + *cmdline_ptr =3D no_free_ptr(cmdline); return EFI_SUCCESS; - -fail_free_cmdline: - efi_err("Failed to parse options\n"); - efi_bs_call(free_pool, cmdline); - return status; } =20 efi_status_t efi_stub_common(efi_handle_t handle, diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index 4dfd25e6ac71..6fa1d4f62e81 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -42,7 +42,7 @@ union sev_memory_acceptance_protocol { static efi_status_t preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **= __rom) { - struct pci_setup_rom *rom =3D NULL; + struct pci_setup_rom *rom __free(efi_pool) =3D NULL; efi_status_t status; unsigned long size; uint64_t romsize; @@ -75,14 +75,13 @@ preserve_pci_rom_image(efi_pci_io_protocol_t *pci, stru= ct pci_setup_rom **__rom) rom->data.len =3D size - sizeof(struct setup_data); rom->data.next =3D 0; rom->pcilen =3D romsize; - *__rom =3D rom; =20 status =3D efi_call_proto(pci, pci.read, EfiPciIoWidthUint16, PCI_VENDOR_ID, 1, &rom->vendor); =20 if (status !=3D EFI_SUCCESS) { efi_err("Failed to read rom->vendor\n"); - goto free_struct; + return status; } =20 status =3D efi_call_proto(pci, pci.read, EfiPciIoWidthUint16, @@ -90,21 +89,18 @@ preserve_pci_rom_image(efi_pci_io_protocol_t *pci, stru= ct pci_setup_rom **__rom) =20 if (status !=3D EFI_SUCCESS) { efi_err("Failed to read rom->devid\n"); - goto free_struct; + return status; } =20 status =3D efi_call_proto(pci, get_location, &rom->segment, &rom->bus, &rom->device, &rom->function); =20 if (status !=3D EFI_SUCCESS) - goto free_struct; + return status; =20 memcpy(rom->romdata, romimage, romsize); - return status; - -free_struct: - efi_bs_call(free_pool, rom); - return status; + *__rom =3D no_free_ptr(rom); + return EFI_SUCCESS; } =20 /* --=20 2.47.1.613.gc27f4b7a9f-goog