|
43 | 43 | #define DRIVER_NAME "axis_fifo" |
44 | 44 |
|
45 | 45 | #define READ_BUF_SIZE 128U /* read buffer length in words */ |
46 | | -#define WRITE_BUF_SIZE 128U /* write buffer length in words */ |
47 | 46 |
|
48 | 47 | #define AXIS_FIFO_DEBUG_REG_NAME_MAX_LEN 4 |
49 | 48 |
|
@@ -302,11 +301,8 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf, |
302 | 301 | { |
303 | 302 | struct axis_fifo *fifo = (struct axis_fifo *)f->private_data; |
304 | 303 | unsigned int words_to_write; |
305 | | - unsigned int copied; |
306 | | - unsigned int copy; |
307 | | - unsigned int i; |
| 304 | + u32 *txbuf; |
308 | 305 | int ret; |
309 | | - u32 tmp_buf[WRITE_BUF_SIZE]; |
310 | 306 |
|
311 | 307 | if (len % sizeof(u32)) { |
312 | 308 | dev_err(fifo->dt_device, |
@@ -371,32 +367,20 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf, |
371 | 367 | } |
372 | 368 | } |
373 | 369 |
|
374 | | - /* write data from an intermediate buffer into the fifo IP, refilling |
375 | | - * the buffer with userspace data as needed |
376 | | - */ |
377 | | - copied = 0; |
378 | | - while (words_to_write > 0) { |
379 | | - copy = min(words_to_write, WRITE_BUF_SIZE); |
380 | | - |
381 | | - if (copy_from_user(tmp_buf, buf + copied * sizeof(u32), |
382 | | - copy * sizeof(u32))) { |
383 | | - ret = -EFAULT; |
384 | | - goto end_unlock; |
385 | | - } |
386 | | - |
387 | | - for (i = 0; i < copy; i++) |
388 | | - iowrite32(tmp_buf[i], fifo->base_addr + |
389 | | - XLLF_TDFD_OFFSET); |
390 | | - |
391 | | - copied += copy; |
392 | | - words_to_write -= copy; |
| 370 | + txbuf = vmemdup_user(buf, len); |
| 371 | + if (IS_ERR(txbuf)) { |
| 372 | + ret = PTR_ERR(txbuf); |
| 373 | + goto end_unlock; |
393 | 374 | } |
394 | 375 |
|
395 | | - ret = copied * sizeof(u32); |
| 376 | + for (int i = 0; i < words_to_write; ++i) |
| 377 | + iowrite32(txbuf[i], fifo->base_addr + XLLF_TDFD_OFFSET); |
396 | 378 |
|
397 | 379 | /* write packet size to fifo */ |
398 | | - iowrite32(ret, fifo->base_addr + XLLF_TLR_OFFSET); |
| 380 | + iowrite32(len, fifo->base_addr + XLLF_TLR_OFFSET); |
399 | 381 |
|
| 382 | + ret = len; |
| 383 | + kvfree(txbuf); |
400 | 384 | end_unlock: |
401 | 385 | mutex_unlock(&fifo->write_lock); |
402 | 386 |
|
|
0 commit comments