[PATCH v3 12/18] pxe: Drop get_bootfile_path()

Ramon Fried rfried.dev at gmail.com
Tue Nov 9 09:09:34 CET 2021


On Thu, Oct 14, 2021 at 9:50 PM Simon Glass <sjg at chromium.org> wrote:
>
> This function no longer makes sense, since it is pretty easy to prepend
> the boot directory to the filename. Drop it and update its only caller.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> (no changes since v1)
>
>  boot/pxe_utils.c    | 53 +++++----------------------------------------
>  include/pxe_utils.h |  3 ++-
>  2 files changed, 7 insertions(+), 49 deletions(-)
>
> diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
> index c04be110ea4..f36f1f8a60c 100644
> --- a/boot/pxe_utils.c
> +++ b/boot/pxe_utils.c
> @@ -64,47 +64,6 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
>         return 1;
>  }
>
> -/**
> - * get_bootfile_path() - Figure out the path of a file to read
> - *
> - * Copies the boot directory into the supplied buffer. If there is no boot
> - * directory, set it to ""
> - *
> - * @ctx: PXE context
> - * @file_path: File path to read (relative to the PXE file)
> - * @bootfile_path: Place to put the bootfile path
> - * @bootfile_path_size: Size of @bootfile_path in bytes
> - * @allow_abs_path: true to allow an absolute path (where @file_path starts with
> - *     '/', false to return an empty path (and success) in that case
> - * Returns 1 for success, -ENOSPC if bootfile_path_size is to small to hold the
> - *     resulting path
> - */
> -static int get_bootfile_path(struct pxe_context *ctx, const char *file_path,
> -                            char *bootfile_path, size_t bootfile_path_size,
> -                            bool allow_abs_path)
> -{
> -       size_t path_len = 0;
> -
> -       /* Only syslinux allows absolute paths */
> -       if (file_path[0] == '/' && allow_abs_path)
> -               goto ret;
> -
> -       path_len = strlen(ctx->bootdir);
> -       if (bootfile_path_size < path_len + 1) {
> -               printf("bootfile_path too small. (%zd < %zd)\n",
> -                      bootfile_path_size, path_len);
> -
> -               return -ENOSPC;
> -       }
> -
> -       strncpy(bootfile_path, ctx->bootdir, path_len);
> -
> - ret:
> -       bootfile_path[path_len] = '\0';
> -
> -       return 1;
> -}
> -
>  /**
>   * get_relfile() - read a file relative to the PXE file
>   *
> @@ -124,15 +83,13 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path,
>         size_t path_len;
>         char relfile[MAX_TFTP_PATH_LEN + 1];
>         char addr_buf[18];
> -       int err;
>
> -       err = get_bootfile_path(ctx, file_path, relfile, sizeof(relfile),
> -                               ctx->allow_abs_path);
> -       if (err < 0)
> -               return err;
> +       if (file_path[0] == '/' && ctx->allow_abs_path)
> +               *relfile = '\0';
> +       else
> +               strncpy(relfile, ctx->bootdir, MAX_TFTP_PATH_LEN);
>
> -       path_len = strlen(file_path);
> -       path_len += strlen(relfile);
> +       path_len = strlen(file_path) + strlen(relfile);
>
>         if (path_len > MAX_TFTP_PATH_LEN) {
>                 printf("Base path too long (%s%s)\n", relfile, file_path);
> diff --git a/include/pxe_utils.h b/include/pxe_utils.h
> index 543d0245c8a..8b50f2e6861 100644
> --- a/include/pxe_utils.h
> +++ b/include/pxe_utils.h
> @@ -202,7 +202,8 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len);
>   * @allow_abs_path: true to allow absolute paths
>   * @bootfile: Bootfile whose directory loaded files are relative to, NULL if
>   *     none
> - * @return 0 if OK, -ENOMEM if out of memory
> + * @return 0 if OK, -ENOMEM if out of memory, -E2BIG if bootfile is larger than
> + *     MAX_TFTP_PATH_LEN bytes
>   */
>  int pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
>                   pxe_getfile_func getfile, void *userdata,
> --
> 2.33.0.1079.g6e70778dc9-goog
>
Reviewed-by: Ramon Fried <rfried.dev at gmail.com>


More information about the U-Boot mailing list