axis-fifo: use size_t for write size calculations
PATCH 1/1 axis-fifo: use size_t for write size calculations
The write length is provided as size_t, but words_to_write and the return value storage used narrower types. Use size_t for the word count and ssize_t for the return value to keep the types consistent with the write interface.
This avoids relying on implicit size limits when handling write sizes.
--- drivers/staging/axis-fifo/axis-fifo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/axis-fifo/axis-fifo.c +3 -3
@@ -214,9 +214,9 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf, size_t len, loff_t *off) { struct axis_fifo *fifo = f->private_data; -unsigned int words_to_write; +size_t words_to_write;u32 *txbuf; -int ret; +ssize_t ret; words_to_write = len /sizeof (u32);
@@ -257,7 +257,7 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf, goto end_unlock; } -for (int i =0 ; i < words_to_write; ++i) +for (size_t i =0 ; i < words_to_write; ++i)iowrite32 (txbuf[i], fifo->base_addr +XLLF_TDFD_OFFSET );iowrite32 (len, fifo->base_addr +XLLF_TLR_OFFSET );
Signature · 1 line
2.43.0
Quoted 9 lines · Lucas Jeffrey
The write length is provided as
size_t, butwords_to_writeand the return value storage used narrower types. Usesize_tfor the word count andssize_tfor the return value to keep the types consistent with the write interface.This avoids relying on implicit size limits when handling write sizes.
Signed-off-by Lucas Jeffrey <[email protected]>---
This doesn't affect real life because len is capped in rw_verify_area().
The commit message needs to make it clear that this is just a clean up and not a fix. If we pretended that the len value in read/write functions was an range from 0-ULONG_MAX then we would have a ton of integer overflow bugs etc.
regards,
dan carpenter
PATCH v2 1/1 staging: axis-fifo: use size_t for write size calculations
In reply to Lucas JeffreyThe write length is provided as size_t, but words_to_write and the return value storage used narrower types (int and unsigned int). Use size_t for the word count and ssize_t for the return value to keep the types consistent with the write interface.
This is purely a cleanup. The VFS already bounds the write length before the driver is called, so this does not change runtime behavior.
---
v2:
- Clarify that this is a cleanup.
- Mention that VFS already bounds write sizes.
drivers/staging/axis-fifo/axis-fifo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/axis-fifo/axis-fifo.c +3 -3
@@ -214,9 +214,9 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf, size_t len, loff_t *off) { struct axis_fifo *fifo = f->private_data; -unsigned int words_to_write; +size_t words_to_write;u32 *txbuf; -int ret; +ssize_t ret; words_to_write = len /sizeof (u32);
@@ -257,7 +257,7 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf, goto end_unlock; } -for (int i =0 ; i < words_to_write; ++i) +for (size_t i =0 ; i < words_to_write; ++i)iowrite32 (txbuf[i], fifo->base_addr +XLLF_TDFD_OFFSET );iowrite32 (len, fifo->base_addr +XLLF_TLR_OFFSET );
Signature · 1 line
2.43.0