All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Cc: Matthew Garrett <mjg@redhat.com>
Subject: Re: [PATCH 2/4] Add grub_efi_get_variable
Date: Wed, 08 Feb 2012 20:55:39 +0100	[thread overview]
Message-ID: <4F32D33B.80000@gmail.com> (raw)
In-Reply-To: <1328719918-4789-3-git-send-email-mjg@redhat.com>

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<mjg@redhat.com>
>
> +	* 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<mjg@redhat.com>
> +
>   	* include/grub/efi/pci.h: New file to define EFI PCI protocols.
>
>   2012-02-07  Vladimir Serbinenko<phcoder@gmail.com>
> 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



  reply	other threads:[~2012-02-08 19:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-08 16:51 Some improvements to EFI GOP support Matthew Garrett
2012-02-08 16:51 ` [PATCH 1/4] Add PCI protocols Matthew Garrett
2012-02-08 19:51   ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-02-08 16:51 ` [PATCH 2/4] Add grub_efi_get_variable Matthew Garrett
2012-02-08 19:55   ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]
2012-02-08 20:04     ` Matthew Garrett
2012-02-08 20:09       ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-02-08 20:19         ` Matthew Garrett
2012-02-08 20:29           ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-02-08 16:51 ` [PATCH 3/4] Prefer GOP devices which implement the pci_io protocol Matthew Garrett
2012-02-08 19:59   ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-02-08 16:51 ` [PATCH 4/4] Add support for getting EDID via EFI Matthew Garrett
2012-02-08 20:07   ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-02-08 17:02 ` Some improvements to EFI GOP support Keshav P R

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F32D33B.80000@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    --cc=mjg@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.