mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH] tftp: reset timer on progress
Date: Sun, 20 Jan 2013 17:03:25 +0100	[thread overview]
Message-ID: <1358697805-28117-1-git-send-email-s.hauer@pengutronix.de> (raw)

When during tftp receive operation a ACK packet can't successfully be sent
the timer was resetted directly after send resulting in a deadlock.

This patch changes the timer reset operation in a way that it is only resetted
when the actually is progress, namely in the TFTP_ACK/TFTP_DATA pathes in the
tftp handler.

Reported-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Tested-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 fs/tftp.c |   21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/fs/tftp.c b/fs/tftp.c
index 98cbb37..4d32b0d 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -246,6 +246,11 @@ static void tftp_parse_oack(struct file_priv *priv, unsigned char *pkt, int len)
 	}
 }
 
+static void tftp_timer_reset(struct file_priv *priv)
+{
+	priv->progress_timeout = priv->resend_timeout = get_time_ns();
+}
+
 static void tftp_handler(void *ctx, char *packet, unsigned len)
 {
 	struct file_priv *priv = ctx;
@@ -282,6 +287,9 @@ static void tftp_handler(void *ctx, char *packet, unsigned len)
 		}
 
 		priv->block++;
+
+		tftp_timer_reset(priv);
+
 		if (priv->state == STATE_LAST) {
 			priv->state = STATE_DONE;
 			break;
@@ -335,6 +343,8 @@ static void tftp_handler(void *ctx, char *packet, unsigned len)
 
 		priv->last_block = priv->block;
 
+		tftp_timer_reset(priv);
+
 		kfifo_put(priv->fifo, pkt + 2, len);
 
 		if (len < priv->blocksize) {
@@ -364,11 +374,6 @@ static void tftp_handler(void *ctx, char *packet, unsigned len)
 	}
 }
 
-static void tftp_timer_reset(struct file_priv *priv)
-{
-	priv->progress_timeout = priv->resend_timeout = get_time_ns();
-}
-
 static struct file_priv *tftp_do_open(struct device_d *dev,
 		int accmode, const char *filename)
 {
@@ -549,8 +554,6 @@ static int tftp_read(struct device_d *dev, FILE *f, void *buf, size_t insize)
 
 	debug("%s %d\n", __func__, insize);
 
-	tftp_timer_reset(priv);
-
 	while (insize) {
 		now = kfifo_get(priv->fifo, buf, insize);
 		if (priv->state == STATE_DONE)
@@ -561,10 +564,8 @@ static int tftp_read(struct device_d *dev, FILE *f, void *buf, size_t insize)
 			insize -= now;
 		}
 
-		if (TFTP_FIFO_SIZE - kfifo_len(priv->fifo) >= priv->blocksize) {
+		if (TFTP_FIFO_SIZE - kfifo_len(priv->fifo) >= priv->blocksize)
 			tftp_send(priv);
-			tftp_timer_reset(priv);
-		}
 
 		ret = tftp_poll(priv);
 		if (ret == TFTP_ERR_RESEND)
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

                 reply	other threads:[~2013-01-20 16:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1358697805-28117-1-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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