|
42 | 42 | #define DRIVER_NAME "axis_fifo" |
43 | 43 |
|
44 | 44 | #define READ_BUF_SIZE 128U /* read buffer length in words */ |
45 | | -#define WRITE_BUF_SIZE 128U /* write buffer length in words */ |
46 | 45 |
|
47 | 46 | /* ---------------------------- |
48 | 47 | * IP register offsets |
@@ -466,11 +465,8 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf, |
466 | 465 | { |
467 | 466 | struct axis_fifo *fifo = (struct axis_fifo *)f->private_data; |
468 | 467 | unsigned int words_to_write; |
469 | | - unsigned int copied; |
470 | | - unsigned int copy; |
471 | | - unsigned int i; |
| 468 | + u32 *txbuf; |
472 | 469 | int ret; |
473 | | - u32 tmp_buf[WRITE_BUF_SIZE]; |
474 | 470 |
|
475 | 471 | if (len % sizeof(u32)) { |
476 | 472 | dev_err(fifo->dt_device, |
@@ -535,32 +531,20 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf, |
535 | 531 | } |
536 | 532 | } |
537 | 533 |
|
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; |
557 | 538 | } |
558 | 539 |
|
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); |
560 | 542 |
|
561 | 543 | /* write packet size to fifo */ |
562 | | - iowrite32(ret, fifo->base_addr + XLLF_TLR_OFFSET); |
| 544 | + iowrite32(len, fifo->base_addr + XLLF_TLR_OFFSET); |
563 | 545 |
|
| 546 | + ret = len; |
| 547 | + kvfree(txbuf); |
564 | 548 | end_unlock: |
565 | 549 | mutex_unlock(&fifo->write_lock); |
566 | 550 |
|
|
0 commit comments