[PATCH 3/3] net: tftp: Fix load_block offset calculation

Ramon Fried rfried.dev at gmail.com
Sun Sep 13 08:48:53 CEST 2020


On Tue, Aug 25, 2020 at 5:27 AM Ley Foon Tan <ley.foon.tan at intel.com> wrote:
>
> When load the last block, the "len" might not be a block size. This cause
> loading the incorrect last block data.
>
> The fix change "len" to tftp_block_size and minus one tftp_block_size
> for offset calculation.
>
> Use same offset calculation formula as in store_block().
>
> Signed-off-by: Ley Foon Tan <ley.foon.tan at intel.com>
> ---
>  net/tftp.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/tftp.c b/net/tftp.c
> index 6e68a427d4cf..292e7b4cddcf 100644
> --- a/net/tftp.c
> +++ b/net/tftp.c
> @@ -218,7 +218,8 @@ static void new_transfer(void)
>  static int load_block(unsigned block, uchar *dst, unsigned len)
>  {
>         /* We may want to get the final block from the previous set */
> -       ulong offset = ((int)block - 1) * len + tftp_block_wrap_offset;
> +       ulong offset = block * tftp_block_size + tftp_block_wrap_offset -
> +                      tftp_block_size;
>         ulong tosend = len;
>
>         tosend = min(net_boot_file_size - offset, tosend);
> --
> 2.19.0
>
Reviewed-By: Ramon Fried <rfried.dev at gmail.com>


More information about the U-Boot mailing list