Skip to contentSkip to conversation

new kfifo API v0.3 - add kfifo_skip, kfifo_from_user and kfifo_to_user

PATCH In review Stefani Seibold 2 participants 2 messages Aug 14, 2009 Kfifo

lore
Share & tools
lore

Stefani Seibold

author maintainer
#0 lore raw

PATCH 5/6 new kfifo API v0.3 - add kfifo_skip, kfifo_from_user and kfifo_to_user

This is patch 5/6 of the new kfifo API:
kfifo_reset_out() to lockless save discard the fifo output Add kfifo_skip() to skip a number of output bytes Add kfifo_from_user() to copy user space data into the fifo Add kfifo_to_user() to copy fifo data to user space Do some code reorg

 include/linux/kfifo.h |   47 ++++++++++++++++
 kernel/kfifo.c        |  141 ++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 172 insertions(+), 16 deletions(-)
include/linux/kfifo.h +47 -0
diff -u -N -r linux-2.6.31-rc4-kfifo5/include/linux/kfifo.h linux-2.6.31-rc4-kfifo6/include/linux/kfifo.h
@@ -102,6 +102,16 @@
 }
 
 /**
+ * kfifo_reset_out - skip FIFO contents
+ * @fifo: the fifo to be emptied.
+ */
+static inline void kfifo_reset_out(struct kfifo *fifo)
+{
+	smp_mb();
+	fifo->out = fifo->in;
+}
+
+/**
  * kfifo_size - returns the size of the fifo in bytes
  * @fifo: the fifo to be used.
  */
@@ -208,4 +218,41 @@
 	return ret;
 }
 
+extern void kfifo_skip(struct kfifo *fifo, unsigned int len);
+
+extern __must_check unsigned int kfifo_from_user(struct kfifo *fifo,
+	const void __user *from, unsigned int n);
+
+extern __must_check unsigned int kfifo_to_user(struct kfifo *fifo,
+	void __user *to, unsigned int n);
+
+/**
+ * __kfifo_add_out internal helper function for updating the out offset
+ */
+static inline void __kfifo_add_out(struct kfifo *fifo,
+				unsigned int off)
+{
+	smp_mb();
+	fifo->out += off;
+}
+
+/**
+ * __kfifo_add_in internal helper function for updating the in offset
+ */
+static inline void __kfifo_add_in(struct kfifo *fifo,
+				unsigned int off)
+{
+	smp_wmb();
+	fifo->in += off;
+}
+
+/**
+ * __kfifo_off internal helper function for calculating the index of a
+ * given offeset
+ */
+static inline unsigned int __kfifo_off(struct kfifo *fifo, unsigned int off)
+{
+	return off & (fifo->size - 1);
+}
+
 #endif
kernel/kfifo.c +125 -16

192 lines not on this page · raw message

Acked-by on v1 5/6
#1 lore raw
Quoted 6 lines · Stefani Seibold

This is patch 5/6 of the new kfifo API:
kfifo_reset_out() to lockless save discard the fifo output Add kfifo_skip() to skip a number of output bytes Add kfifo_from_user() to copy user space data into the fifo Add kfifo_to_user() to copy fifo data to user space Do some code reorg

kfifo_skip is missing a comment regarding what it does, and as with the other patches, the description should line out why this is done, not what you do.

Quoted 1 line

Otherwise,