From patchwork Thu Mar 7 21:26:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Christophe PLAGNIOL-VILLARD X-Patchwork-Id: 2233621 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 10A0B3FCF6 for ; Thu, 7 Mar 2013 21:35:10 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UDiP9-0003M6-Uj; Thu, 07 Mar 2013 21:31:12 +0000 Received: from 14.mo3.mail-out.ovh.net ([188.165.43.98] helo=mo3.mail-out.ovh.net) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UDiOw-0003Ic-0v for linux-arm-kernel@lists.infradead.org; Thu, 07 Mar 2013 21:30:59 +0000 Received: from mail412.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo3.mail-out.ovh.net (Postfix) with SMTP id 399C7FF8D84 for ; Thu, 7 Mar 2013 22:46:40 +0100 (CET) Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 7 Mar 2013 23:30:56 +0200 Received: from ns32433.ovh.net (HELO localhost) (plagnioj%jcrosoft.com@213.251.161.87) by ns0.ovh.net with SMTP; 7 Mar 2013 23:30:56 +0200 From: Jean-Christophe PLAGNIOL-VILLARD To: linux-arm-kernel@lists.infradead.org X-Ovh-Mailout: 178.32.228.3 (mo3.mail-out.ovh.net) Subject: [PATCH 1/9] kfifo: introduce kfifo_dump_str to dump the fifo Date: Thu, 7 Mar 2013 22:26:26 +0100 Message-Id: <1362691594-32286-1-git-send-email-plagnioj@jcrosoft.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <20130307212523.GK4401@game.jcrosoft.org> References: <20130307212523.GK4401@game.jcrosoft.org> X-Ovh-Tracer-Id: 508906759727787005 X-Ovh-Remote: 213.251.161.87 (ns32433.ovh.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-OVH-SPAMSTATE: OK X-OVH-SPAMSCORE: 0 X-OVH-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeeiuddrvdelucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecu X-Spam-Check: DONE|U 0.5/N X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeeiuddrvdelucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130307_163058_550035_1861CB2B X-CRM114-Status: GOOD ( 14.51 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [188.165.43.98 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Jean-Christophe PLAGNIOL-VILLARD X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This will allow to implement a dmesg mecanism in barebox Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD --- include/kfifo.h | 2 ++ lib/kfifo.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/kfifo.h b/include/kfifo.h index 25880f4..9dbbe0d 100644 --- a/include/kfifo.h +++ b/include/kfifo.h @@ -74,5 +74,7 @@ static inline unsigned int kfifo_len(struct kfifo *fifo) void kfifo_putc(struct kfifo *fifo, unsigned char c); unsigned int kfifo_getc(struct kfifo *fifo, unsigned char *c); +void kfifo_dump_str(struct kfifo *fifo, void (*dump)(unsigned char c)); + #endif diff --git a/lib/kfifo.c b/lib/kfifo.c index afd3894..7892aed 100644 --- a/lib/kfifo.c +++ b/lib/kfifo.c @@ -154,3 +154,24 @@ unsigned int kfifo_getc(struct kfifo *fifo, unsigned char *c) return 0; } +void kfifo_dump_str(struct kfifo *fifo, void (*dump)(unsigned char c)) +{ + int i; + unsigned char *c; + unsigned int l; + unsigned int len; + + len = fifo->in - fifo->out; + + /* first get the data from fifo->out until the end of the buffer */ + l = min(len, fifo->size - (fifo->out & (fifo->size - 1))); + c = fifo->buffer + (fifo->out & (fifo->size - 1)); + for (i = 0; i < l; i++) + dump(c[i]); + + /* then get the rest (if any) from the beginning of the buffer */ + c = fifo->buffer; + l = len - l; + for (i = 0; i < l; i++) + dump(c[i]); +}