u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Masahisa Kojima <masahisa.kojima@linaro.org>
To: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: u-boot@lists.denx.de, Heinrich Schuchardt <xypron.glpk@gmx.de>,
	 Simon Glass <sjg@chromium.org>,
	Takahiro Akashi <takahiro.akashi@linaro.org>,
	 Francois Ozog <francois.ozog@linaro.org>,
	Mark Kettenis <mark.kettenis@xs4all.nl>
Subject: Re: [PATCH v4 09/11] efi_loader: add menu-driven UEFI Boot Variable maintenance
Date: Thu, 14 Apr 2022 18:25:24 +0900	[thread overview]
Message-ID: <CADQ0-X8ZTqF_v2kbrwi=S-Bd=6paRAJzd8bH1tZ_JN7Xeq7QDw@mail.gmail.com> (raw)
In-Reply-To: <YkVm8PS1HJHLqmRV@hades>

Hi Ilias,

On Thu, 31 Mar 2022 at 17:31, Ilias Apalodimas
<ilias.apalodimas@linaro.org> wrote:
>
> Hi Kojima-san,
> On Thu, Mar 24, 2022 at 10:54:41PM +0900, Masahisa Kojima wrote:
> > +
>
> I haven't been able to get the patch working yet.  I'll send more feedback
> once I do.  Here's a few comments I have
>
> [...]
>
> > +struct efi_bootmenu_file_entry_data {
> > +     struct efi_bootmenu_boot_option *bo;
> > +     struct efi_file_info *f;
> > +};
> > +
> > +static efi_status_t efi_bootmenu_process_boot_selected(void *data, bool *exit);
> > +static efi_status_t efi_bootmenu_process_add_boot_option(void *data, bool *exit);
> > +static efi_status_t efi_bootmenu_process_delete_boot_option(void *data, bool *exit);
> > +static efi_status_t efi_bootmenu_process_change_boot_order(void *data, bool *exit);
>
> I think you can re-arrange some of the functions and get rid of the forward
> declarations
>
> > +
> > +static struct efi_bootmenu_item maintenance_menu_items[] = {
>
> const ?
>
> > +     {u"Add Boot Option", efi_bootmenu_process_add_boot_option},
> > +     {u"Delete Boot Option", efi_bootmenu_process_delete_boot_option},
> > +     {u"Change Boot Order", efi_bootmenu_process_change_boot_order},
> > +     {u"Quit", NULL},
> > +};
> > +
> > +static void efi_bootmenu_print_entry(void *data)
> > +{
> > +     struct efi_bootmenu_entry *entry = data;
>
> [...]
>
> > +             new_len = u16_strlen(info->bo->current_path) +
> > +                     /* TODO: show error notification to user */
> > +                     log_err("file path is too long\n");
> > +                     return EFI_INVALID_PARAMETER;
>
> Can we just check for new_len + 1 here and get rid of the follow up check ?

Sorry for the late reply.
If the selected entry is a file, not the directory, no u'\\' will be added.
Strictly speaking, checking for new_len + 1 here ends up that file path name
max size is (EFI_BOOTMENU_FILE_PATH_MAX -1).

>
> > +             }
> > +             u16_strlcat(info->bo->current_path, info->f->file_name, EFI_BOOTMENU_FILE_PATH_MAX);
> > +             if (info->f->attribute & EFI_FILE_DIRECTORY) {
> > +                     if (new_len + 1 >= EFI_BOOTMENU_FILE_PATH_MAX) {
> > +                             log_err("file path is too long\n");
> > +                             return EFI_INVALID_PARAMETER;
> > +                     }
> > +                     u16_strlcat(info->bo->current_path, u"\\", EFI_BOOTMENU_FILE_PATH_MAX);
> > +             } else {
> > +                     info->bo->file_selected = true;
> > +             }
>
> [...]
>
> > +             menu_item = calloc(count + 1, sizeof(struct efi_bootmenu_item));
> > +             if (!menu_item) {
> > +                     efi_file_close_int(f);
> > +                     free(dir_buf);
> > +                     ret = EFI_OUT_OF_RESOURCES;
> > +                     goto out;
> > +             }
> > +
> > +             /* read directory and construct menu structure */
> > +             efi_file_setpos_int(f, 0);
> > +             iter = menu_item;
> > +             ptr = (struct efi_file_info *)dir_buf;
>
> This will cause an unaligned access later on when you access
> ptr->attribute.  Any reason we can't allocate ptr directly?

I will fix other comments.

Thanks,
Masahisa Kojima


>
> > +             for (i = 0; i < count; i++) {
> > +                     int name_len;
> > +                     u16 *name;
> > +                     struct efi_bootmenu_file_entry_data *info;
> > +
> > +                     len = size;
> > +                     ret = efi_file_read_int(f, &len, ptr);
> > +                     if (ret != EFI_SUCCESS || len == 0)
> > +                             goto err;
> > +
> > +                     if (ptr->attribute & EFI_FILE_DIRECTORY) {
> > +                             /* append u'/' at the end of directory name */
> > +                             name_len = u16_strsize(ptr->file_name) + sizeof(u16);
> > +                             name = calloc(1, name_len);
> > +                             if (!name) {
> > +                                     ret = EFI_OUT_OF_RESOURCES;
> > +                                     goto err;
> > +                             }
> > +                             u16_strcpy(name, ptr->file_name);
> > +                             name[u16_strlen(ptr->file_name)] = u'/';
> > +                     } else {
> > +                             name_len = u16_strsize(ptr->file_name);
> > +                             name = calloc(1, name_len);
> > +                             if (!name) {
> > +                                     ret = EFI_OUT_OF_RESOURCES;
> > +                                     goto err;
> > +                             }
> > +                             u16_strcpy(name, ptr->file_name);
> > +                     }
> > +
> > +                     info = calloc(1, sizeof(struct efi_bootmenu_file_entry_data));
> > +                     if (!info) {
> > +                             ret = EFI_OUT_OF_RESOURCES;
> > +                             goto err;
> > +                     }
> > +                     info->f = ptr;
> > +                     info->bo = bo;
> > +                     iter->title = name;
> > +                     iter->func = efi_bootmenu_file_selected;
> > +                     iter->data = info;
> > +                     iter++;
> > +
> > +                     size -= len;
> > +                     ptr = (struct efi_file_info *)((char *)ptr + len);
>
> ditto
>
> > +             }
> > +
> > +             /* add "Quit" entry */
> > +             iter->title = u"Quit";
> > +             iter->func = NULL;
> > +             iter->data = NULL;
> > +             count += 1;
> > +
> > +             ret = efi_bootmenu_process_common(menu_item, count, -1);
> > +err:
> > +             efi_file_close_int(f);
> > +             iter = menu_item;
> > +             for (i = 0; i < count - 1; i++, iter++) {
> > +                     free(iter->title);
> > +                     free(iter->data);
> > +             }
> > +
> > +             free(dir_buf);
> > +             free(menu_item);
> > +
> > +             if (ret != EFI_SUCCESS)
> > +                     break;
> > +     }
> > +
> > +out:
> > +     free(buf);
> > +     return ret;
> > +}
> > +
>
> [...]
>
> Regards
> /Ilias

  reply	other threads:[~2022-04-14  9:25 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-24 13:54 [PATCH v4 00/11] enable menu-driven boot device selection Masahisa Kojima
2022-03-24 13:54 ` [PATCH v4 01/11] bootmenu: fix menu API error handling Masahisa Kojima
2022-03-30  8:55   ` Ilias Apalodimas
2022-03-24 13:54 ` [PATCH v4 02/11] lib/charset: add u16_strlcat() function Masahisa Kojima
2022-04-02  7:14   ` Heinrich Schuchardt
2022-04-04 14:50     ` Masahisa Kojima
2022-04-16  7:32   ` Heinrich Schuchardt
2022-04-18  7:47     ` Masahisa Kojima
2022-04-28  7:45       ` Masahisa Kojima
2022-03-24 13:54 ` [PATCH v4 03/11] test: unit test for u16_strlcat() Masahisa Kojima
2022-04-02  7:47   ` Heinrich Schuchardt
2022-04-04 14:54     ` Masahisa Kojima
2022-03-24 13:54 ` [PATCH v4 04/11] menu: always show the menu regardless of the number of entry Masahisa Kojima
2022-04-02  7:56   ` Heinrich Schuchardt
2022-03-24 13:54 ` [PATCH v4 05/11] efi_loader: export efi_locate_device_handle() Masahisa Kojima
2022-04-01  5:43   ` Ilias Apalodimas
2022-03-24 13:54 ` [PATCH v4 06/11] efi_loader: bootmgr: add booting from removable media Masahisa Kojima
2022-03-30 19:13   ` Ilias Apalodimas
2022-03-31  0:51     ` Masahisa Kojima
2022-03-31  6:25       ` Ilias Apalodimas
2022-04-02  6:12   ` Heinrich Schuchardt
2022-04-04  6:48     ` Masahisa Kojima
2022-04-04 21:54       ` Heinrich Schuchardt
2022-03-24 13:54 ` [PATCH v4 07/11] bootmenu: add UEFI and disto_boot entries Masahisa Kojima
2022-04-01  6:08   ` Ilias Apalodimas
2022-04-02  6:33   ` Heinrich Schuchardt
2022-04-04  8:10     ` Masahisa Kojima
2022-03-24 13:54 ` [PATCH v4 08/11] bootmenu: factor out the user input handling Masahisa Kojima
2022-03-24 13:54 ` [PATCH v4 09/11] efi_loader: add menu-driven UEFI Boot Variable maintenance Masahisa Kojima
2022-03-31  8:31   ` Ilias Apalodimas
2022-04-14  9:25     ` Masahisa Kojima [this message]
2022-03-24 13:54 ` [PATCH v4 10/11] bootmenu: add removable media entries Masahisa Kojima
2022-03-31  8:48   ` Ilias Apalodimas
2022-03-31 10:18     ` Masahisa Kojima
2022-04-04 22:00     ` Heinrich Schuchardt
2022-03-24 13:54 ` [PATCH v4 11/11] doc:bootmenu: add UEFI boot variable and distro boot support Masahisa Kojima
2022-04-02  5:51   ` Heinrich Schuchardt
2022-03-25  1:20 ` [PATCH v4 00/11] enable menu-driven boot device selection Takahiro Akashi
2022-03-25  6:57   ` Masahisa Kojima
2022-04-02  5:48 ` Heinrich Schuchardt
2022-04-04  6:10   ` Masahisa Kojima
2022-04-16  6:46 ` Heinrich Schuchardt
2022-04-28  7:35   ` Masahisa Kojima

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='CADQ0-X8ZTqF_v2kbrwi=S-Bd=6paRAJzd8bH1tZ_JN7Xeq7QDw@mail.gmail.com' \
    --to=masahisa.kojima@linaro.org \
    --cc=francois.ozog@linaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=mark.kettenis@xs4all.nl \
    --cc=sjg@chromium.org \
    --cc=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).