aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kfifo.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/kfifo.h')
-rw-r--r--include/linux/kfifo.h42
1 files changed, 24 insertions, 18 deletions
diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h
index 7c6b32a1421c..6f6c5f300af6 100644
--- a/include/linux/kfifo.h
+++ b/include/linux/kfifo.h
@@ -67,7 +67,7 @@ struct kfifo {
67/** 67/**
68 * DECLARE_KFIFO - macro to declare a kfifo and the associated buffer 68 * DECLARE_KFIFO - macro to declare a kfifo and the associated buffer
69 * @name: name of the declared kfifo datatype 69 * @name: name of the declared kfifo datatype
70 * @size: size of the fifo buffer 70 * @size: size of the fifo buffer. Must be a power of two.
71 * 71 *
72 * Note1: the macro can be used inside struct or union declaration 72 * Note1: the macro can be used inside struct or union declaration
73 * Note2: the macro creates two objects: 73 * Note2: the macro creates two objects:
@@ -91,7 +91,7 @@ union { \
91/** 91/**
92 * DEFINE_KFIFO - macro to define and initialize a kfifo 92 * DEFINE_KFIFO - macro to define and initialize a kfifo
93 * @name: name of the declared kfifo datatype 93 * @name: name of the declared kfifo datatype
94 * @size: size of the fifo buffer 94 * @size: size of the fifo buffer. Must be a power of two.
95 * 95 *
96 * Note1: the macro can be used for global and local kfifo data type variables 96 * Note1: the macro can be used for global and local kfifo data type variables
97 * Note2: the macro creates two objects: 97 * Note2: the macro creates two objects:
@@ -104,15 +104,28 @@ union { \
104 104
105#undef __kfifo_initializer 105#undef __kfifo_initializer
106 106
107extern void kfifo_init(struct kfifo *fifo, unsigned char *buffer, 107extern void kfifo_init(struct kfifo *fifo, void *buffer,
108 unsigned int size); 108 unsigned int size);
109extern __must_check int kfifo_alloc(struct kfifo *fifo, unsigned int size, 109extern __must_check int kfifo_alloc(struct kfifo *fifo, unsigned int size,
110 gfp_t gfp_mask); 110 gfp_t gfp_mask);
111extern void kfifo_free(struct kfifo *fifo); 111extern void kfifo_free(struct kfifo *fifo);
112extern unsigned int kfifo_in(struct kfifo *fifo, 112extern unsigned int kfifo_in(struct kfifo *fifo,
113 const unsigned char *from, unsigned int len); 113 const void *from, unsigned int len);
114extern __must_check unsigned int kfifo_out(struct kfifo *fifo, 114extern __must_check unsigned int kfifo_out(struct kfifo *fifo,
115 unsigned char *to, unsigned int len); 115 void *to, unsigned int len);
116extern __must_check unsigned int kfifo_out_peek(struct kfifo *fifo,
117 void *to, unsigned int len, unsigned offset);
118
119/**
120 * kfifo_initialized - Check if kfifo is initialized.
121 * @fifo: fifo to check
122 * Return %true if FIFO is initialized, otherwise %false.
123 * Assumes the fifo was 0 before.
124 */
125static inline bool kfifo_initialized(struct kfifo *fifo)
126{
127 return fifo->buffer != 0;
128}
116 129
117/** 130/**
118 * kfifo_reset - removes the entire FIFO contents 131 * kfifo_reset - removes the entire FIFO contents
@@ -194,7 +207,7 @@ static inline __must_check unsigned int kfifo_avail(struct kfifo *fifo)
194 * bytes copied. 207 * bytes copied.
195 */ 208 */
196static inline unsigned int kfifo_in_locked(struct kfifo *fifo, 209static inline unsigned int kfifo_in_locked(struct kfifo *fifo,
197 const unsigned char *from, unsigned int n, spinlock_t *lock) 210 const void *from, unsigned int n, spinlock_t *lock)
198{ 211{
199 unsigned long flags; 212 unsigned long flags;
200 unsigned int ret; 213 unsigned int ret;
@@ -219,7 +232,7 @@ static inline unsigned int kfifo_in_locked(struct kfifo *fifo,
219 * @to buffer and returns the number of copied bytes. 232 * @to buffer and returns the number of copied bytes.
220 */ 233 */
221static inline __must_check unsigned int kfifo_out_locked(struct kfifo *fifo, 234static inline __must_check unsigned int kfifo_out_locked(struct kfifo *fifo,
222 unsigned char *to, unsigned int n, spinlock_t *lock) 235 void *to, unsigned int n, spinlock_t *lock)
223{ 236{
224 unsigned long flags; 237 unsigned long flags;
225 unsigned int ret; 238 unsigned int ret;
@@ -228,13 +241,6 @@ static inline __must_check unsigned int kfifo_out_locked(struct kfifo *fifo,
228 241
229 ret = kfifo_out(fifo, to, n); 242 ret = kfifo_out(fifo, to, n);
230 243
231 /*
232 * optimization: if the FIFO is empty, set the indices to 0
233 * so we don't wrap the next time
234 */
235 if (kfifo_is_empty(fifo))
236 kfifo_reset(fifo);
237
238 spin_unlock_irqrestore(lock, flags); 244 spin_unlock_irqrestore(lock, flags);
239 245
240 return ret; 246 return ret;
@@ -242,11 +248,11 @@ static inline __must_check unsigned int kfifo_out_locked(struct kfifo *fifo,
242 248
243extern void kfifo_skip(struct kfifo *fifo, unsigned int len); 249extern void kfifo_skip(struct kfifo *fifo, unsigned int len);
244 250
245extern __must_check unsigned int kfifo_from_user(struct kfifo *fifo, 251extern __must_check int kfifo_from_user(struct kfifo *fifo,
246 const void __user *from, unsigned int n); 252 const void __user *from, unsigned int n, unsigned *lenout);
247 253
248extern __must_check unsigned int kfifo_to_user(struct kfifo *fifo, 254extern __must_check int kfifo_to_user(struct kfifo *fifo,
249 void __user *to, unsigned int n); 255 void __user *to, unsigned int n, unsigned *lenout);
250 256
251/* 257/*
252 * __kfifo_add_out internal helper function for updating the out offset 258 * __kfifo_add_out internal helper function for updating the out offset