From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1RvDcR-0000TN-Mp for mharc-grub-devel@gnu.org; Wed, 08 Feb 2012 14:55:55 -0500 Received: from eggs.gnu.org ([140.186.70.92]:37127) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvDcK-0000Lh-3O for grub-devel@gnu.org; Wed, 08 Feb 2012 14:55:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RvDcF-0002Ag-Io for grub-devel@gnu.org; Wed, 08 Feb 2012 14:55:48 -0500 Received: from mail-ww0-f49.google.com ([74.125.82.49]:58119) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvDcF-0002AZ-BO for grub-devel@gnu.org; Wed, 08 Feb 2012 14:55:43 -0500 Received: by wgbdt13 with SMTP id dt13so707366wgb.30 for ; Wed, 08 Feb 2012 11:55:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=2wQmLk9dN/qchD8NaNwgWDn7nvyyEe5nz+JXwhWbvnY=; b=gnrk6bYcBUR7SJ2AyGF/BBvawWGJKp6D8Q3QA2OaKiuOCkjbzZSWxviTkL46mV5FGI Q7g1vVA5jlChUITVQIR/cJEf0rknnORs9aVGDkt+qO60xGCukaMCjyEoUMGGtmyqDZYy VnxT4pWanO9AT40/Fc1CTh4LieFBIcN1U24tc= Received: by 10.216.138.14 with SMTP id z14mr11232761wei.7.1328730942565; Wed, 08 Feb 2012 11:55:42 -0800 (PST) Received: from debian.x201.phnet (202-41.62-81.cust.bluewin.ch. [81.62.41.202]) by mx.google.com with ESMTPS id ho4sm2148858wib.3.2012.02.08.11.55.40 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 08 Feb 2012 11:55:41 -0800 (PST) Message-ID: <4F32D33B.80000@gmail.com> Date: Wed, 08 Feb 2012 20:55:39 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20120104 Icedove/8.0 MIME-Version: 1.0 To: The development of GNU GRUB Subject: Re: [PATCH 2/4] Add grub_efi_get_variable References: <1328719918-4789-1-git-send-email-mjg@redhat.com> <1328719918-4789-3-git-send-email-mjg@redhat.com> In-Reply-To: <1328719918-4789-3-git-send-email-mjg@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.49 Cc: Matthew Garrett X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Feb 2012 19:55:52 -0000 On 08.02.2012 17:51, Matthew Garrett wrote: > Code may wish to obtain system information from EFI variables. Add support > for making the platform call. > --- > ChangeLog | 6 ++++++ > grub-core/kern/efi/efi.c | 32 ++++++++++++++++++++++++++++++++ > include/grub/efi/api.h | 4 ++++ > include/grub/efi/efi.h | 3 ++- > 4 files changed, 44 insertions(+), 1 deletions(-) > > diff --git a/ChangeLog b/ChangeLog > index ca07786..e662f3d 100644 > --- a/ChangeLog > +++ b/ChangeLog > @@ -1,5 +1,11 @@ > 2012-02-08 Matthew Garrett > > + * grub-core/kern/efi/efi.c (grub_efi_get_variable): Add new function. > + * include/grub/efi/efi.h: Likewise. > + * include/grub/efi/api.h: Add guid for EFI-specified variables. > + > +2012-02-08 Matthew Garrett > + > * include/grub/efi/pci.h: New file to define EFI PCI protocols. > > 2012-02-07 Vladimir Serbinenko > diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c > index 9a2c5e6..d366f8a 100644 > --- a/grub-core/kern/efi/efi.c > +++ b/grub-core/kern/efi/efi.c > @@ -182,6 +182,38 @@ grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size, > return grub_error (GRUB_ERR_IO, "set_virtual_address_map failed"); > } > > +void * > +grub_efi_get_variable(grub_uint8_t *var, grub_efi_guid_t *guid) > +{ > + grub_efi_status_t status; > + grub_efi_uintn_t datasize = 0; > + grub_efi_runtime_services_t *r; > + grub_efi_char16_t *var16; > + int i; > + void *data; > + > + var16 = grub_malloc((grub_strlen((char *)var) +1) * 2); > + Indentation. You also don't check that malloc succeeded. Also I recommend using intermediary variable for length > + for (i=0; i<(int)grub_strlen((char *)var); i++) > + var16[i] = var[i]; > + var16[i] = '\0'; > + We use grub_utf8_to_utf16. Also don't forget to multiply the malloc length by GRUB_MAX_UTF16_PER_UTF8 ((GRUB_MAX_UTF16_PER_UTF8 * length + 1) * sizeof (var16[0])) > + r = grub_efi_system_table->runtime_services; > + > + status = efi_call_5 (r->get_variable, var16, guid, NULL,&datasize, NULL); > + > + data = grub_malloc(datasize); > + Again: no check for success. > + status = efi_call_5 (r->get_variable, var16, guid, NULL,&datasize, data); > + > + grub_free(var16); > + > + if (status == GRUB_EFI_SUCCESS) > + return data; -- Regards Vladimir 'φ-coder/phcoder' Serbinenko