From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kkq7v-0004Ug-QX for mharc-grub-devel@gnu.org; Thu, 03 Dec 2020 10:02:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkq7s-0004Pb-3f for grub-devel@gnu.org; Thu, 03 Dec 2020 10:02:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26321) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kkq7q-00022P-70 for grub-devel@gnu.org; Thu, 03 Dec 2020 10:02:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607007749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r6aYEDPrkyt6ovJxy4YfChWjz11OyR+TdGifGfl/Fcs=; b=SCgOe84gVdgO6wuaZVuEOgSmBKxWmhZoOhSFHvHovb46OGdMS+ooLnSRpV+cyVQPbQfadc IC5O0w50nR7r2B/kjpj0jdzTojNQUR9Xj1bGDZEiOEC4UhjWgY9Z8BUdrZqe8T9YxCWLof 65L8LKd3+uiHBQqHWF6pRtAzQcy3MSg= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-500-8gGLiJbkNkSRDraIfUN9_g-1; Thu, 03 Dec 2020 10:02:27 -0500 X-MC-Unique: 8gGLiJbkNkSRDraIfUN9_g-1 Received: by mail-wr1-f71.google.com with SMTP id w17so1344385wrl.8 for ; Thu, 03 Dec 2020 07:02:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r6aYEDPrkyt6ovJxy4YfChWjz11OyR+TdGifGfl/Fcs=; b=hpRLpGrQrnzuJxyvNuTE3/vq7pap8SGIrctoWPzGNlceSwEcorp3pKWaSnGURDVMYo 39vG9+vVc4gejiBz9vUvp64q5JPbpIODS2jNGccTnztSiHx4q9DYYiZcs6FWR39/rUzn lI/N8YrIjRqgLnygZXTbXoei80xILK5V9dJfP+8Ebkog8sXtciZULwUPNQAj6Vc70yi0 pqmiWVKjCX0tf/aqWadHd7lPds3AqqiGixJ+ImUcEM5m62Rn1bGpjzSmWAEEieLFRPF4 nEgEjH0wE43Qi9zQttoS4fF6yqNNHGMkESfVYPX7W8dIKLaDPRvmIK2LB3Hu3ZjwwcXr g2UQ== X-Gm-Message-State: AOAM533vavO63jDvPkc1F2b1JCvgsI/U4dtUY1w8/+jz6pKH38FjJIbs Wru0VrOxONHZ09jU4MyOzbnYZNFLkpvraXQ4BVzbDGHqG9gZtOGYUvEmaPUL8HbNuoo1gSiZrZ/ LlroSN/QdDaJoOEzg6l5l7E7dNReVvp+x8xDKCBzYw+xdTUClS9Syy1JTAw6MtA== X-Received: by 2002:adf:d0c6:: with SMTP id z6mr4258281wrh.10.1607007744280; Thu, 03 Dec 2020 07:02:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJwsiJE2hao0rC8X72ETngDQp/HNAxJiRFtel2P7vYRN8+wwEE9doZp20kmREBz69rzCJh1IRw== X-Received: by 2002:adf:d0c6:: with SMTP id z6mr4258243wrh.10.1607007744011; Thu, 03 Dec 2020 07:02:24 -0800 (PST) Received: from minerva.redhat.com ([92.176.231.106]) by smtp.gmail.com with ESMTPSA id n128sm1896759wmb.46.2020.12.03.07.02.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 07:02:23 -0800 (PST) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Ignat Korchagin , Michael Chang , Peter Jones , Marco A Benatto , Leif Lindholm , Daniel Kiper , Javier Martinez Canillas Subject: [PATCH 5/9] efi: Return grub_efi_status_t from grub_efi_get_variable() Date: Thu, 3 Dec 2020 16:01:46 +0100 Message-Id: <20201203150151.848077-6-javierm@redhat.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201203150151.848077-1-javierm@redhat.com> References: <20201203150151.848077-1-javierm@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=javierm@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Received-SPF: pass client-ip=63.128.21.124; envelope-from=javierm@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.495, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Dec 2020 15:02:32 -0000 From: Daniel Kiper This is needed to properly detect and report UEFI Secure Boot status to the x86 Linux kernel. The functionality will be added by subsequent patches. Signed-off-by: Daniel Kiper Signed-off-by: Marco A Benatto Signed-off-by: Javier Martinez Canillas --- grub-core/commands/efi/efifwsetup.c | 8 ++++---- grub-core/kern/efi/efi.c | 16 +++++++++------- grub-core/video/efi_gop.c | 2 +- include/grub/efi/efi.h | 7 ++++--- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/grub-core/commands/efi/efifwsetup.c b/grub-core/commands/efi/efifwsetup.c index 7a137a72a2f..eaca0328388 100644 --- a/grub-core/commands/efi/efifwsetup.c +++ b/grub-core/commands/efi/efifwsetup.c @@ -38,8 +38,8 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)), grub_size_t oi_size; grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID; - old_os_indications = grub_efi_get_variable ("OsIndications", &global, - &oi_size); + grub_efi_get_variable ("OsIndications", &global, &oi_size, + (void **) &old_os_indications); if (old_os_indications != NULL && oi_size == sizeof (os_indications)) os_indications |= *old_os_indications; @@ -63,8 +63,8 @@ efifwsetup_is_supported (void) grub_size_t oi_size = 0; grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID; - os_indications_supported = grub_efi_get_variable ("OsIndicationsSupported", - &global, &oi_size); + grub_efi_get_variable ("OsIndicationsSupported", &global, &oi_size, + (void **) &os_indications_supported); if (!os_indications_supported) return 0; diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index e0165e74c58..9403b12cd78 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -223,9 +223,9 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, return grub_error (GRUB_ERR_IO, "could not set EFI variable `%s'", var); } -void * +grub_efi_status_t grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, - grub_size_t *datasize_out) + grub_size_t *datasize_out, void **data_out) { grub_efi_status_t status; grub_efi_uintn_t datasize = 0; @@ -234,13 +234,14 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, void *data; grub_size_t len, len16; + *data_out = NULL; *datasize_out = 0; len = grub_strlen (var); len16 = len * GRUB_MAX_UTF16_PER_UTF8; var16 = grub_calloc (len16 + 1, sizeof (var16[0])); if (!var16) - return NULL; + return GRUB_EFI_OUT_OF_RESOURCES; len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); var16[len16] = 0; @@ -251,14 +252,14 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, if (status != GRUB_EFI_BUFFER_TOO_SMALL || !datasize) { grub_free (var16); - return NULL; + return status; } data = grub_malloc (datasize); if (!data) { grub_free (var16); - return NULL; + return GRUB_EFI_OUT_OF_RESOURCES; } status = efi_call_5 (r->get_variable, var16, guid, NULL, &datasize, data); @@ -266,12 +267,13 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, if (status == GRUB_EFI_SUCCESS) { + *data_out = data; *datasize_out = datasize; - return data; + return status; } grub_free (data); - return NULL; + return status; } #pragma GCC diagnostic ignored "-Wcast-align" diff --git a/grub-core/video/efi_gop.c b/grub-core/video/efi_gop.c index be446f8d291..7fe0cdabf50 100644 --- a/grub-core/video/efi_gop.c +++ b/grub-core/video/efi_gop.c @@ -316,7 +316,7 @@ grub_video_gop_get_edid (struct grub_video_edid_info *edid_info) char edidname[] = "agp-internal-edid"; grub_size_t datasize; grub_uint8_t *data; - data = grub_efi_get_variable (edidname, &efi_var_guid, &datasize); + grub_efi_get_variable (edidname, &efi_var_guid, &datasize, (void **) &data); if (data && datasize > 16) { copy_size = datasize - 16; diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index e90e00dc431..8b2a0f1f590 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -74,9 +74,10 @@ grub_err_t EXPORT_FUNC (grub_efi_set_virtual_address_map) (grub_efi_uintn_t memo grub_efi_uintn_t descriptor_size, grub_efi_uint32_t descriptor_version, grub_efi_memory_descriptor_t *virtual_map); -void *EXPORT_FUNC (grub_efi_get_variable) (const char *variable, - const grub_efi_guid_t *guid, - grub_size_t *datasize_out); +grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable) (const char *variable, + const grub_efi_guid_t *guid, + grub_size_t *datasize_out, + void **data_out); grub_err_t EXPORT_FUNC (grub_efi_set_variable) (const char *var, const grub_efi_guid_t *guid, -- 2.28.0