diff options
| -rw-r--r-- | include/linux/kfifo.h | 3 | ||||
| -rw-r--r-- | kernel/kfifo.c | 21 |
2 files changed, 24 insertions, 0 deletions
diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h index 86ad50a900c8..7ad6d32dd673 100644 --- a/include/linux/kfifo.h +++ b/include/linux/kfifo.h | |||
| @@ -113,6 +113,9 @@ extern unsigned int kfifo_in(struct kfifo *fifo, | |||
| 113 | const void *from, unsigned int len); | 113 | const void *from, unsigned int len); |
| 114 | extern __must_check unsigned int kfifo_out(struct kfifo *fifo, | 114 | extern __must_check unsigned int kfifo_out(struct kfifo *fifo, |
| 115 | void *to, unsigned int len); | 115 | void *to, unsigned int len); |
| 116 | extern __must_check unsigned int kfifo_out_peek(struct kfifo *fifo, | ||
| 117 | void *to, unsigned int len, unsigned offset); | ||
| 118 | |||
| 116 | 119 | ||
| 117 | /** | 120 | /** |
| 118 | * kfifo_reset - removes the entire FIFO contents | 121 | * kfifo_reset - removes the entire FIFO contents |
diff --git a/kernel/kfifo.c b/kernel/kfifo.c index b50bb622e8b0..7384f120be87 100644 --- a/kernel/kfifo.c +++ b/kernel/kfifo.c | |||
| @@ -302,6 +302,27 @@ unsigned int kfifo_out(struct kfifo *fifo, void *to, unsigned int len) | |||
| 302 | } | 302 | } |
| 303 | EXPORT_SYMBOL(kfifo_out); | 303 | EXPORT_SYMBOL(kfifo_out); |
| 304 | 304 | ||
| 305 | /** | ||
| 306 | * kfifo_out_peek - copy some data from the FIFO, but do not remove it | ||
| 307 | * @fifo: the fifo to be used. | ||
| 308 | * @to: where the data must be copied. | ||
| 309 | * @len: the size of the destination buffer. | ||
| 310 | * @offset: offset into the fifo | ||
| 311 | * | ||
| 312 | * This function copies at most @len bytes at @offset from the FIFO | ||
| 313 | * into the @to buffer and returns the number of copied bytes. | ||
| 314 | * The data is not removed from the FIFO. | ||
| 315 | */ | ||
| 316 | unsigned int kfifo_out_peek(struct kfifo *fifo, void *to, unsigned int len, | ||
| 317 | unsigned offset) | ||
| 318 | { | ||
| 319 | len = min(kfifo_len(fifo), len + offset); | ||
| 320 | |||
| 321 | __kfifo_out_data(fifo, to, len, offset); | ||
| 322 | return len; | ||
| 323 | } | ||
| 324 | EXPORT_SYMBOL(kfifo_out_peek); | ||
| 325 | |||
| 305 | unsigned int __kfifo_out_generic(struct kfifo *fifo, | 326 | unsigned int __kfifo_out_generic(struct kfifo *fifo, |
| 306 | void *to, unsigned int len, unsigned int recsize, | 327 | void *to, unsigned int len, unsigned int recsize, |
| 307 | unsigned int *total) | 328 | unsigned int *total) |
