[PATCH v3 12/18] tftp: refactor data processing
Enrico Scholz
enrico.scholz at sigma-chemnitz.de
Mon Aug 15 01:42:16 PDT 2022
move block handling into dedicated function
Signed-off-by: Enrico Scholz <enrico.scholz at sigma-chemnitz.de>
---
fs/tftp.c | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/fs/tftp.c b/fs/tftp.c
index 2ed62b77901b..2bb9361d8929 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -260,6 +260,26 @@ static void tftp_timer_reset(struct file_priv *priv)
priv->progress_timeout = priv->resend_timeout = get_time_ns();
}
+static void tftp_put_data(struct file_priv *priv, uint16_t block,
+ void const *pkt, size_t len)
+{
+ if (len > priv->blocksize) {
+ pr_warn("tftp: oversized packet (%zu > %d) received\n",
+ len, priv->blocksize);
+ return;
+ }
+
+ priv->last_block = block;
+
+ kfifo_put(priv->fifo, pkt, len);
+
+ if (len < priv->blocksize) {
+ tftp_send(priv);
+ priv->err = 0;
+ priv->state = STATE_DONE;
+ }
+}
+
static void tftp_recv(struct file_priv *priv,
uint8_t *pkt, unsigned len, uint16_t uh_sport)
{
@@ -339,23 +359,8 @@ static void tftp_recv(struct file_priv *priv,
/* Same block again; ignore it. */
break;
- if (len > priv->blocksize) {
- pr_warn("tftp: oversized packet (%u > %d) received\n",
- len, priv->blocksize);
- break;
- }
-
- priv->last_block = priv->block;
-
tftp_timer_reset(priv);
-
- kfifo_put(priv->fifo, pkt + 2, len);
-
- if (len < priv->blocksize) {
- tftp_send(priv);
- priv->err = 0;
- priv->state = STATE_DONE;
- }
+ tftp_put_data(priv, priv->block, pkt + 2, len);
break;
--
2.37.1
More information about the barebox
mailing list