mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/7] kfifo: change kfifo_init to work with a preallocated fifo
Date: Thu, 26 Jan 2012 14:26:48 +0100	[thread overview]
Message-ID: <1327584413-23055-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1327584413-23055-1-git-send-email-s.hauer@pengutronix.de>

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>
---
 include/kfifo.h |    2 +-
 lib/kfifo.c     |   23 +++++++++--------------
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/include/kfifo.h b/include/kfifo.h
index 3eb03cb..2987e0b 100644
--- a/include/kfifo.h
+++ b/include/kfifo.h
@@ -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);
 
diff --git a/lib/kfifo.c b/lib/kfifo.c
index 27d44e9..a2f3727 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;
 }
 
 /**
-- 
1.7.8.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2012-01-26 13:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-26 13:26 some debug patches Sascha Hauer
2012-01-26 13:26 ` [PATCH 1/7] console: remove unused function prototypes Sascha Hauer
2012-01-26 13:26 ` Sascha Hauer [this message]
2012-01-26 13:26 ` [PATCH 3/7] console: make it work without malloc Sascha Hauer
2012-01-26 13:26 ` [PATCH 4/7] ARM: panic on div 0 Sascha Hauer
2012-01-26 13:26 ` [PATCH 5/7] initcalls: do not hang if an initcall fails Sascha Hauer
2012-01-26 13:26 ` [PATCH 6/7] startup: use regular debug statements in initcall debugging Sascha Hauer
2012-01-26 13:26 ` [PATCH 7/7] Add dump_stack function Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1327584413-23055-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox