Skip to contentSkip to conversation

kfifo: kfifo_copy_{to,from}_user: Fix copied bytes calculation

PATCH New Lars-Peter Clausen 1 participant 1 message Sep 16, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kfifo: kfifo_copy_{to,from}_user: Fix copied bytes calculation

'copied' and 'len' are in bytes, while 'ret' is in elements, so we need to multiply 'ret' with the size of one element to get the correct result.

---
 lib/kfifo.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/kfifo.c +2 -2
index 7b7f830..d79b9d2 100644
@@ -215,7 +215,7 @@ static unsigned long kfifo_copy_from_user(struct __kfifo *fifo,
 	 * incrementing the fifo->in index counter
 	 */
 	smp_wmb();
-	*copied = len - ret;
+	*copied = len - ret * esize;
 	/* return the number of elements which are not copied */
 	return ret;
 }
@@ -275,7 +275,7 @@ static unsigned long kfifo_copy_to_user(struct __kfifo *fifo, void __user *to,
 	 * incrementing the fifo->out index counter
 	 */
 	smp_wmb();
-	*copied = len - ret;
+	*copied = len - ret * esize;
 	/* return the number of elements which are not copied */
 	return ret;
 }
Signature · 1 line
1.8.0