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 1/2] fs tftp: Only request a block once
Date: Wed, 24 Oct 2012 10:00:08 +0200	[thread overview]
Message-ID: <1351065609-22101-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1351065609-22101-1-git-send-email-s.hauer@pengutronix.de>

tftp_send is called often. Each time, when in STATE_RDATA, a packet
is requested from the tftp server, even if we requested the same packet
already.
Stop this by tracking which packet we requested.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/tftp.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/tftp.c b/fs/tftp.c
index ae57f95..d89272e 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -80,6 +80,7 @@ struct file_priv {
 	struct kfifo *fifo;
 	void *buf;
 	int blocksize;
+	int block_requested;
 };
 
 struct tftp_priv {
@@ -152,11 +153,14 @@ static int tftp_send(struct file_priv *priv)
 		break;
 
 	case STATE_RDATA:
+		if (priv->block == priv->block_requested)
+			return 0;
 	case STATE_OACK:
 		xp = pkt;
 		s = (uint16_t *)pkt;
 		*s++ = htons(TFTP_ACK);
 		*s++ = htons(priv->block);
+		priv->block_requested = priv->block;
 		pkt = (unsigned char *)s;
 		len = pkt - xp;
 		break;
@@ -199,6 +203,7 @@ static int tftp_poll(struct file_priv *priv)
 	if (is_timeout(priv->resend_timeout, TFTP_RESEND_TIMEOUT)) {
 		printf("T ");
 		priv->resend_timeout = get_time_ns();
+		priv->block_requested = -1;
 		return TFTP_ERR_RESEND;
 	}
 
@@ -392,6 +397,7 @@ static struct file_priv *tftp_do_open(struct device_d *dev,
 	priv->err = -EINVAL;
 	priv->filename = filename;
 	priv->blocksize = TFTP_BLOCK_SIZE;
+	priv->block_requested = -1;
 
 	priv->fifo = kfifo_alloc(4096);
 	if (!priv->fifo) {
-- 
1.7.10.4


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

  reply	other threads:[~2012-10-24  8:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-24  8:00 [PATCH] tftp fixes Sascha Hauer
2012-10-24  8:00 ` Sascha Hauer [this message]
2012-10-24  8:00 ` [PATCH 2/2] fs tftp: Fix possible fifo overflow Sascha Hauer

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=1351065609-22101-2-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