9
0
Fork 0

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>
This commit is contained in:
Sascha Hauer 2012-01-26 10:25:26 +01:00
parent 48529db7d4
commit 178c4978b3
2 changed files with 10 additions and 15 deletions

View File

@ -28,7 +28,7 @@ struct kfifo {
unsigned int out; /* data is extracted from off. (out % size) */
};
struct kfifo *kfifo_init(unsigned char *buffer, unsigned int size);
void kfifo_init(struct kfifo *fifo, unsigned char *buffer, unsigned int size);
struct kfifo *kfifo_alloc(unsigned int size);
void kfifo_free(struct kfifo *fifo);

View File

@ -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;
}
return ret;
kfifo_init(fifo, buffer, size);
return fifo;
}
/**