Skip to content

Commit 7441d70

Browse files
ovpanaitgregkh
authored andcommitted
staging: axis-fifo: fix TX handling on copy_from_user() failure
commit 6d07bee upstream. If copy_from_user() fails, write() currently returns -EFAULT, but any partially written data leaves the TX FIFO in an inconsistent state. Subsequent write() calls then fail with "transmit length mismatch" errors. Once partial data is written to the hardware FIFO, it cannot be removed without a TX reset. Commit c6e8d85 ("staging: axis-fifo: Remove hardware resets for user errors") removed a full FIFO reset for this case, which fixed a potential RX data loss, but introduced this TX issue. Fix this by introducing a bounce buffer: copy the full packet from userspace first, and write to the hardware FIFO only if the copy was successful. Fixes: c6e8d85 ("staging: axis-fifo: Remove hardware resets for user errors") Cc: stable@vger.kernel.org Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com> Link: https://lore.kernel.org/r/20250912101322.1282507-1-ovidiu.panait.oss@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cc9cfbf commit 7441d70

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

drivers/staging/axis-fifo/axis-fifo.c

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#define DRIVER_NAME "axis_fifo"
4343

4444
#define READ_BUF_SIZE 128U /* read buffer length in words */
45-
#define WRITE_BUF_SIZE 128U /* write buffer length in words */
4645

4746
/* ----------------------------
4847
* IP register offsets
@@ -466,11 +465,8 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf,
466465
{
467466
struct axis_fifo *fifo = (struct axis_fifo *)f->private_data;
468467
unsigned int words_to_write;
469-
unsigned int copied;
470-
unsigned int copy;
471-
unsigned int i;
468+
u32 *txbuf;
472469
int ret;
473-
u32 tmp_buf[WRITE_BUF_SIZE];
474470

475471
if (len % sizeof(u32)) {
476472
dev_err(fifo->dt_device,
@@ -535,32 +531,20 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf,
535531
}
536532
}
537533

538-
/* write data from an intermediate buffer into the fifo IP, refilling
539-
* the buffer with userspace data as needed
540-
*/
541-
copied = 0;
542-
while (words_to_write > 0) {
543-
copy = min(words_to_write, WRITE_BUF_SIZE);
544-
545-
if (copy_from_user(tmp_buf, buf + copied * sizeof(u32),
546-
copy * sizeof(u32))) {
547-
ret = -EFAULT;
548-
goto end_unlock;
549-
}
550-
551-
for (i = 0; i < copy; i++)
552-
iowrite32(tmp_buf[i], fifo->base_addr +
553-
XLLF_TDFD_OFFSET);
554-
555-
copied += copy;
556-
words_to_write -= copy;
534+
txbuf = vmemdup_user(buf, len);
535+
if (IS_ERR(txbuf)) {
536+
ret = PTR_ERR(txbuf);
537+
goto end_unlock;
557538
}
558539

559-
ret = copied * sizeof(u32);
540+
for (int i = 0; i < words_to_write; ++i)
541+
iowrite32(txbuf[i], fifo->base_addr + XLLF_TDFD_OFFSET);
560542

561543
/* write packet size to fifo */
562-
iowrite32(ret, fifo->base_addr + XLLF_TLR_OFFSET);
544+
iowrite32(len, fifo->base_addr + XLLF_TLR_OFFSET);
563545

546+
ret = len;
547+
kvfree(txbuf);
564548
end_unlock:
565549
mutex_unlock(&fifo->write_lock);
566550

0 commit comments

Comments
 (0)