support for user-space buffers in kfifo
On 6/12/07, Stelian Pop <[email protected]> wrote:
(cut)
Quoted 3 lines
accessing userspace memory with a spinlock taken (moreover an
irqsave()
one) is bad bad bad.
Hi Stelian.
I'm sending the new patch without kfifo_put_user and kfifo_get_user.
Regards,
Nelson.-
---
include/linux/kfifo.h +5 -0
@@ -41,8 +41,13 @@ extern struct kfifo *kfifo_alloc(unsigned int size, gfp_t gfp_mask,extern void kfifo_free (struct kfifo *fifo);extern unsigned int __kfifo_put (struct kfifo *fifo,unsigned char *buffer,unsigned int len); +extern int __kfifo_put_user (struct kfifo *fifo, +const unsigned char __user *buffer, +unsigned int len);extern unsigned int __kfifo_get (struct kfifo *fifo,unsigned char *buffer,unsigned int len); +extern int __kfifo_get_user (struct kfifo *fifo,unsigned char __user *buffer, +unsigned int len);/** * __kfifo_reset - removes the entire FIFO contents, no locking version
kernel/kfifo.c +109 -0
124 lines not on this page · raw message
Signature · 2 lines
http://arhuaco.org http://emQbit.com
Quoted 9 lines · Nelson Castillo
On 6/12/07, Stelian Pop <[email protected]> wrote:
(cut)Quoted 3 lines
accessing userspace memory with a spinlock taken (moreover an
irqsave()
one) is bad bad bad.Hi Stelian.
I'm sending the new patch without
kfifo_put_userandkfifo_get_user.
Ok, I have a few formatting/documentation comments:
Quoted 3 lines
+ * This function copies at most @len bytes from the @buffer into
+ * the FIFO depending on the free space, and returns the number of
+ * bytes copied.
... or -EFAULT if copy_from_user fails
kernel/kfifo.c unsigned int __kfifo_put(struct kfifo *fifo, · line 170
Quoted 6 lines
+ *
+ * Note that with only one concurrent reader and one concurrent
+ * writer, you don't need extra locking to use these functions.
+ */kernel/kfifo.c +2
-0+int __kfifo_put_user (struct kfifo *fifo,const unsigned char __user *buffer, +unsigned int len)
spacing ?
kernel/kfifo.c unsigned int __kfifo_put(struct kfifo *fifo, · line 187
Quoted 2 lines
kernel/kfifo.c +2
-0+if (copy_from_user (fifo->buffer + (fifo->in & (fifo->size -1 )), + buffer, l))
leave a space after the if please
Quoted 2 lines
+ * This function copies at most @len bytes from the FIFO into the
+ * @buffer and returns the number of copied bytes.
or -EFAULT
kernel/kfifo.c unsigned int __kfifo_get(struct kfifo *fifo, · line 270
Quoted 7 lines
+ *
+ * Note that with only one concurrent reader and one concurrent
+ * writer, you don't need extra locking to use these functions.
+ */kernel/kfifo.c +3
-0+ +int __kfifo_get_user (struct kfifo *fifo, +unsigned char __user *buffer,unsigned int len)
spacing.
Other than that I'm ok with this patch.
Thanks,
Stelian.
Signature · 1 line
Stelian Pop <[email protected]>