From patchwork Tue Aug 25 02:26:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ley Foon Tan X-Patchwork-Id: 1350764 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BbCZB0mQRz9sTX for ; Tue, 25 Aug 2020 12:27:30 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1F2F181C1D; Tue, 25 Aug 2020 04:27:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 1C3C781B79; Tue, 25 Aug 2020 04:26:50 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2EBBF81A2A for ; Tue, 25 Aug 2020 04:26:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ley.foon.tan@intel.com IronPort-SDR: QRyYrUgpiTOW6dERevl9pkxbPA4WPZK8TyzneTU4K4r8vd1JAQ1bKn4/Fv6BU4L+JvDiVTg0GA OdprtsQZNJbw== X-IronPort-AV: E=McAfee;i="6000,8403,9723"; a="174065641" X-IronPort-AV: E=Sophos;i="5.76,350,1592895600"; d="scan'208";a="174065641" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2020 19:26:45 -0700 IronPort-SDR: 9fOyvcJudPN0IR1E1ZoSwE0RpwS+lzeJHTsuhQmH3HFoIWiPN/Tl4swWnRQZbmXlabVM1gXN5X qB2jSvfx/kSQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,350,1592895600"; d="scan'208";a="402564641" Received: from ppglcf0024.png.intel.com ([10.226.229.44]) by fmsmga001.fm.intel.com with ESMTP; 24 Aug 2020 19:26:44 -0700 From: Ley Foon Tan To: u-boot@lists.denx.de Cc: Joe Hershberger , Ley Foon Tan , Chin Liang See , Ley Foon Tan Subject: [PATCH 3/3] net: tftp: Fix load_block offset calculation Date: Tue, 25 Aug 2020 10:26:37 +0800 Message-Id: <20200825022637.93123-4-ley.foon.tan@intel.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20200825022637.93123-1-ley.foon.tan@intel.com> References: <20200825022637.93123-1-ley.foon.tan@intel.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean 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 Reviewed-By: Ramon Fried --- 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);