it should never happen due to the program logic; but detect a failed kfifo_put() just in case... Signed-off-by: Enrico Scholz <enrico.scholz@xxxxxxxxxxxxxxxxx> --- fs/tftp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/tftp.c b/fs/tftp.c index 2bb9361d8929..5c3e56a6cb22 100644 --- a/fs/tftp.c +++ b/fs/tftp.c @@ -263,6 +263,8 @@ static void tftp_timer_reset(struct file_priv *priv) static void tftp_put_data(struct file_priv *priv, uint16_t block, void const *pkt, size_t len) { + unsigned int sz; + if (len > priv->blocksize) { pr_warn("tftp: oversized packet (%zu > %d) received\n", len, priv->blocksize); @@ -271,9 +273,14 @@ static void tftp_put_data(struct file_priv *priv, uint16_t block, priv->last_block = block; - kfifo_put(priv->fifo, pkt, len); + sz = kfifo_put(priv->fifo, pkt, len); - if (len < priv->blocksize) { + if (sz != len) { + pr_err("tftp: not enough room in kfifo (only %u out of %zu written\n", + sz, len); + priv->err = -ENOMEM; + priv->state = STATE_DONE; + } else if (len < priv->blocksize) { tftp_send(priv); priv->err = 0; priv->state = STATE_DONE; -- 2.37.1