summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-01-26 10:25:26 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2012-01-26 13:57:43 +0100
commit178c4978b3bf1d6876984b2d2659f646cdb39b8a (patch)
treea9e7488d75df6d142503fbb15e82602200943848 /lib
parent48529db7d46e600cbbf935af0f14f0a082950993 (diff)
downloadbarebox-178c4978b3bf1d6876984b2d2659f646cdb39b8a.tar.gz
barebox-178c4978b3bf1d6876984b2d2659f646cdb39b8a.tar.xz
kfifo: change kfifo_init to work with a preallocated fifo
kfifo currently only works with dynamically allocated fifos. Change the currently unused kfifo_init to take a preallocated fifo. This allows for statically initialized fifos. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/kfifo.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/lib/kfifo.c b/lib/kfifo.c
index 27d44e9bd8..a2f3727db3 100644
--- a/lib/kfifo.c
+++ b/lib/kfifo.c
@@ -34,19 +34,11 @@
* Do NOT pass the kfifo to kfifo_free() after use! Simply free the
* &struct kfifo with free().
*/
-struct kfifo *kfifo_init(unsigned char *buffer, unsigned int size)
+void kfifo_init(struct kfifo *fifo, unsigned char *buffer, unsigned int size)
{
- struct kfifo *fifo;
-
- fifo = malloc(sizeof(struct kfifo));
- if (!fifo)
- return NULL;
-
fifo->buffer = buffer;
fifo->size = size;
fifo->in = fifo->out = 0;
-
- return fifo;
}
/**
@@ -60,18 +52,21 @@ struct kfifo *kfifo_init(unsigned char *buffer, unsigned int size)
struct kfifo *kfifo_alloc(unsigned int size)
{
unsigned char *buffer;
- struct kfifo *ret;
+ struct kfifo *fifo;
buffer = malloc(size);
if (!buffer)
return NULL;
- ret = kfifo_init(buffer, size);
-
- if (!ret)
+ fifo = malloc(sizeof(struct kfifo));
+ if (!fifo) {
free(buffer);
+ return NULL;
+ }
+
+ kfifo_init(fifo, buffer, size);
- return ret;
+ return fifo;
}
/**