Linux kernel staging patches
 help / color / mirror / Atom feed
From: Akito Nakano <kero.io.frog@gmail.com>
To: gregkh@linuxfoundation.org
Cc: ovidiu.panait.oss@gmail.com, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Akito Nakano <kero.io.frog@gmail.com>
Subject: [PATCH] staging: axis-fifo: flush the whole packet on RX read errors
Date: Sun, 29 Nov 2026 16:59:21 +0900	[thread overview]
Message-ID: <20261129075921.2897492-1-kero.io.frog@gmail.com> (raw)

axis_fifo_read() flushes the remaining packet data from the RX FIFO
on errors so that stale data does not remain for the next packet.
The number of words to flush is computed as
bytes_available / sizeof(u32), which rounds down.

The RLR register reports the packet length in bytes. Packets whose
length is not a multiple of 4 are valid for this IP, for example
when TKEEP, the AXI4-Stream signal that marks the valid bytes of a
beat, covers only part of the last beat. For such a packet, the
driver reports "received a packet that isn't word-aligned" and
flushes the FIFO, but the rounded-down word count leaves the last
partial word in the FIFO. That leftover word is then returned as the
first word of the next packet.

This was observed on Zynq-7000 with AXI4-Stream FIFO v4.3. When a
source whose last beat has TKEEP=0001 sends 29 bytes, RLR is 29 and
RDFO is 8. After the failed read, sending the same packet again
gives RDFO=9 instead of 8, and the first word read is the leftover
one.

Round the word count up so that the error path flushes the entire
packet.

Fixes: 82a051e2553b ("staging: axis-fifo: flush RX FIFO on read errors")
Signed-off-by: Akito Nakano <kero.io.frog@gmail.com>
---
 drivers/staging/axis-fifo/axis-fifo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c
index 233d2b153934..96653e4afa3d 100644
--- a/drivers/staging/axis-fifo/axis-fifo.c
+++ b/drivers/staging/axis-fifo/axis-fifo.c
@@ -145,7 +145,7 @@ static ssize_t axis_fifo_read(struct file *f, char __user *buf,
 	}
 
 	bytes_available = ioread32(fifo->base_addr + XLLF_RLR_OFFSET);
-	words_available = bytes_available / sizeof(u32);
+	words_available = DIV_ROUND_UP(bytes_available, sizeof(u32));
 
 	if (bytes_available > len) {
 		ret = -EINVAL;
-- 
2.43.0


             reply	other threads:[~2026-11-29  7:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  7:59 Akito Nakano [this message]
2026-11-29 13:52 ` [PATCH] staging: axis-fifo: flush the whole packet on RX read errors Greg KH

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=20261129075921.2897492-1-kero.io.frog@gmail.com \
    --to=kero.io.frog@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=ovidiu.panait.oss@gmail.com \
    /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