From patchwork Thu May 7 21:55:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ravik Hasija X-Patchwork-Id: 1286032 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=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.a=rsa-sha256 header.s=default header.b=C7MRvHpf; dkim-atps=neutral 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49JSSz0gn6z9sSm for ; Fri, 8 May 2020 21:16:19 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3D5E381674; Fri, 8 May 2020 13:16:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="C7MRvHpf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EEFF581E17; Thu, 7 May 2020 23:56:04 +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=-9.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.2 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by phobos.denx.de (Postfix) with ESMTP id 23E7481E17 for ; Thu, 7 May 2020 23:56:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rahasij@linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1062) id D37B820B717B; Thu, 7 May 2020 14:56:00 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D37B820B717B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1588888560; bh=iUhzdoxzETN7g0OhsczrsxB2CGa82QxJoqXJ4/ffI8s=; h=From:To:Cc:Subject:Date:From; b=C7MRvHpf7kAa0b1fqBSZvx6Jo7BpFfcovIgPMZB7bqNdyOropJo8lAEU6qaqKwUhz Oswr6Nex+MhS/I6YySqKzVJg4NO43ZZfUeAt54D3Wv7HgHWqehvK71rrTxLB1CQmyQ tjctPnYubcFmL/G/rAP3QhREeSDpYzMGh6As38r8= From: Ravik Hasija To: u-boot@lists.denx.de Cc: dphadke@linux.microsoft.com, Ravik Hasija Subject: [PATCH] net: tftp: fix progress marker for file transfer Date: Thu, 7 May 2020 14:55:32 -0700 Message-Id: <1588888532-88945-1-git-send-email-rahasij@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 X-Mailman-Approved-At: Fri, 08 May 2020 13:16:02 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.2 at phobos.denx.de X-Virus-Status: Clean During packet sequence number wraparound the show_block_marker() API was not called, as a result the progress marker doesn't stay within column boundary. Use position in file instead of sequence number to align the marker. Signed-off-by: Ravik Hasija Reviewed-By: Ramon Fried --- net/tftp.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/net/tftp.c b/net/tftp.c index 34488b76c8..8039694ef2 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -229,9 +229,11 @@ static void tftp_timeout_handler(void); static void show_block_marker(void) { + ulong pos; + #ifdef CONFIG_TFTP_TSIZE if (tftp_tsize) { - ulong pos = tftp_cur_block * tftp_block_size + + pos = tftp_cur_block * tftp_block_size + tftp_block_wrap_offset; if (pos > tftp_tsize) pos = tftp_tsize; @@ -243,9 +245,11 @@ static void show_block_marker(void) } else #endif { - if (((tftp_cur_block - 1) % 10) == 0) + pos = (tftp_cur_block - 1) + + (tftp_block_wrap * TFTP_SEQUENCE_SIZE); + if ((pos % 10) == 0) putc('#'); - else if ((tftp_cur_block % (10 * HASHES_PER_LINE)) == 0) + else if (((pos + 1) % (10 * HASHES_PER_LINE)) == 0) puts("\n\t "); } } @@ -278,9 +282,8 @@ static void update_block_number(void) tftp_block_wrap++; tftp_block_wrap_offset += tftp_block_size * TFTP_SEQUENCE_SIZE; timeout_count = 0; /* we've done well, reset the timeout */ - } else { - show_block_marker(); } + show_block_marker(); } /* The TFTP get or put is complete */ @@ -514,8 +517,6 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip, len -= 2; tftp_cur_block = ntohs(*(__be16 *)pkt); - update_block_number(); - if (tftp_state == STATE_SEND_RRQ) debug("Server did not acknowledge timeout option!\n"); @@ -541,6 +542,7 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip, break; } + update_block_number(); tftp_prev_block = tftp_cur_block; timeout_count_max = tftp_timeout_count_max; net_set_timeout_handler(timeout_ms, tftp_timeout_handler);