public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Richard Purdie <rpurdie@openedhand.com>
To: David Woodhouse <dwmw2@infradead.org>,
	linux-mtd <linux-mtd@lists.infradead.org>
Cc: Jarkko Lavinen <jarkko.lavinen@nokia.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] mtd: Add sync/unblank function to mtdoops
Date: Tue, 10 Jul 2007 20:33:54 +0100	[thread overview]
Message-ID: <1184096034.6435.82.camel@localhost.localdomain> (raw)

mtdoops wasn't ensuring data was flushed to flash in crash situations
after recent changes in mainline kernels as tracking the
oops_in_progress variable was no longer enough. We can use the "unblank"
console call as a sync call to tell us to write out the buffer though.

Therefore add a sync function to mtdoops and call this when console
unblank events occur.

Signed-off-by: Richard Purdie <rpurdie@openedhand.com>

Index: linux/drivers/mtd/mtdoops.c
===================================================================
--- linux.orig/drivers/mtd/mtdoops.c	2007-07-10 20:01:34.000000000 +0100
+++ linux/drivers/mtd/mtdoops.c	2007-07-10 20:23:09.000000000 +0100
@@ -271,40 +271,50 @@ static void mtdoops_notify_remove(struct
 	flush_scheduled_work();
 }
 
-
-static void
-mtdoops_console_write(struct console *co, const char *s, unsigned int count)
+static void mtdoops_console_sync(void)
 {
-	struct mtdoops_context *cxt = co->data;
+	struct mtdoops_context *cxt = &oops_cxt;
 	struct mtd_info *mtd = cxt->mtd;
-	int i, ret;
+	size_t retlen;
+	int ret;
 
 	if (!cxt->ready || !mtd)
 		return;
 
-	if (!oops_in_progress && cxt->writecount != 0) {
-		size_t retlen;
-		if (cxt->writecount < OOPS_PAGE_SIZE)
-			memset(cxt->oops_buf + cxt->writecount, 0xff,
+	if (cxt->writecount == 0)
+		return;
+
+	if (cxt->writecount < OOPS_PAGE_SIZE)
+		memset(cxt->oops_buf + cxt->writecount, 0xff,
 					OOPS_PAGE_SIZE - cxt->writecount);
 
-		ret = mtd->write(mtd, cxt->nextpage * OOPS_PAGE_SIZE,
+	ret = mtd->write(mtd, cxt->nextpage * OOPS_PAGE_SIZE,
 					OOPS_PAGE_SIZE, &retlen, cxt->oops_buf);
-		cxt->ready = 0;
-		cxt->writecount = 0;
+	cxt->ready = 0;
+	cxt->writecount = 0;
 
-		if ((retlen != OOPS_PAGE_SIZE) || (ret < 0))
-			printk(KERN_ERR "mtdoops: Write failure at %d (%d of %d"
-				" written), err %d.\n",
-				cxt->nextpage * OOPS_PAGE_SIZE, retlen,
-				OOPS_PAGE_SIZE, ret);
+	if ((retlen != OOPS_PAGE_SIZE) || (ret < 0))
+		printk(KERN_ERR "mtdoops: Write failure at %d (%d of %d written), err %d.\n",
+			cxt->nextpage * OOPS_PAGE_SIZE, retlen,	OOPS_PAGE_SIZE, ret);
 
-		ret = mtdoops_inc_counter(cxt);
-		if (ret == 1)
-			schedule_work(&cxt->work);
+	ret = mtdoops_inc_counter(cxt);
+	if (ret == 1)
+		schedule_work(&cxt->work);
+}
+
+static void
+mtdoops_console_write(struct console *co, const char *s, unsigned int count)
+{
+	struct mtdoops_context *cxt = co->data;
+	struct mtd_info *mtd = cxt->mtd;
+	int i;
+
+	if (!oops_in_progress) {
+		mtdoops_console_sync();
+		return;
 	}
 
-	if (!oops_in_progress)
+	if (!cxt->ready || !mtd)
 		return;
 
 	if (cxt->writecount == 0) {
@@ -344,6 +354,7 @@ static struct console mtdoops_console = 
 	.name		= "ttyMTD",
 	.write		= mtdoops_console_write,
 	.setup		= mtdoops_console_setup,
+	.unblank	= mtdoops_console_sync,
 	.flags		= CON_PRINTBUFFER,
 	.index		= -1,
 	.data		= &oops_cxt,

                 reply	other threads:[~2007-07-10 19:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1184096034.6435.82.camel@localhost.localdomain \
    --to=rpurdie@openedhand.com \
    --cc=dwmw2@infradead.org \
    --cc=jarkko.lavinen@nokia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@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