From patchwork Wed Mar 7 21:58:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 7151 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 546E623E74 for ; Wed, 7 Mar 2012 22:00:47 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 044B6A1850C for ; Wed, 7 Mar 2012 22:00:46 +0000 (UTC) Received: by iage36 with SMTP id e36so12344521iag.11 for ; Wed, 07 Mar 2012 14:00:46 -0800 (PST) Received: by 10.50.158.133 with SMTP id wu5mr13394951igb.50.1331157646309; Wed, 07 Mar 2012 14:00:46 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.53.18 with SMTP id k18csp23031ibg; Wed, 7 Mar 2012 14:00:45 -0800 (PST) Received: by 10.52.29.75 with SMTP id i11mr6079943vdh.23.1331157645555; Wed, 07 Mar 2012 14:00:45 -0800 (PST) Received: from e1.ny.us.ibm.com (e1.ny.us.ibm.com. [32.97.182.141]) by mx.google.com with ESMTPS id jb4si20040659vdb.42.2012.03.07.14.00.44 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 07 Mar 2012 14:00:45 -0800 (PST) Received-SPF: pass (google.com: domain of jstultz@us.ibm.com designates 32.97.182.141 as permitted sender) client-ip=32.97.182.141; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jstultz@us.ibm.com designates 32.97.182.141 as permitted sender) smtp.mail=jstultz@us.ibm.com Received: from /spool/local by e1.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 7 Mar 2012 17:00:41 -0500 Received: from d01dlp02.pok.ibm.com (9.56.224.85) by e1.ny.us.ibm.com (192.168.1.101) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 7 Mar 2012 16:58:38 -0500 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id A2ABC6E804C; Wed, 7 Mar 2012 16:58:37 -0500 (EST) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q27LwbRL292524; Wed, 7 Mar 2012 16:58:37 -0500 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q27LwWXB032588; Wed, 7 Mar 2012 14:58:32 -0700 Received: from kernel.beaverton.ibm.com (kernel.beaverton.ibm.com [9.47.67.96]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q27LwVQ1032522; Wed, 7 Mar 2012 14:58:31 -0700 Received: by kernel.beaverton.ibm.com (Postfix, from userid 1056) id 3D55CC041A; Wed, 7 Mar 2012 13:58:30 -0800 (PST) From: John Stultz To: lkml Cc: Colin Cross , Greg KH , Android Kernel Team , John Stultz Subject: [PATCH 03/13] android: ram_console: move footer strings Date: Wed, 7 Mar 2012 13:58:13 -0800 Message-Id: <1331157503-3413-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.3.2.146.gca209 In-Reply-To: <1331157503-3413-1-git-send-email-john.stultz@linaro.org> References: <1331157503-3413-1-git-send-email-john.stultz@linaro.org> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12030721-6078-0000-0000-000008CF3AF6 X-Gm-Message-State: ALoCoQkmID5f2vU8LfC0ahxMUypAWm8swrat9uamCcJk8L+EGlQX/PTpyy6uz703wljyCFb5M5+J From: Colin Cross Don't store the bootinfo string and the ecc status string with the recovered old log data. This will simplify refactoring the persistent ram code out of the ram console code later. CC: Greg KH CC: Android Kernel Team Change-Id: I883bb6eec5bad5c1b1247da807e982e744fe40ba Signed-off-by: Colin Cross Signed-off-by: John Stultz --- drivers/staging/android/ram_console.c | 115 +++++++++++++++++++------------- 1 files changed, 68 insertions(+), 47 deletions(-) diff --git a/drivers/staging/android/ram_console.c b/drivers/staging/android/ram_console.c index f01a0c4..2310a79 100644 --- a/drivers/staging/android/ram_console.c +++ b/drivers/staging/android/ram_console.c @@ -42,6 +42,8 @@ static char __initdata #endif static char *ram_console_old_log; static size_t ram_console_old_log_size; +static const char *bootinfo; +static size_t bootinfo_size; static struct ram_console_buffer *ram_console_buffer; static size_t ram_console_buffer_size; @@ -156,20 +158,13 @@ void ram_console_enable_console(int enabled) } static void __init -ram_console_save_old(struct ram_console_buffer *buffer, const char *bootinfo, - char *dest) +ram_console_save_old(struct ram_console_buffer *buffer, char *dest) { size_t old_log_size = buffer->size; - size_t bootinfo_size = 0; - size_t total_size = old_log_size; - char *ptr; - const char *bootinfo_label = "Boot info:\n"; #ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION uint8_t *block; uint8_t *par; - char strbuf[80]; - int strbuf_len = 0; block = buffer->data; par = ram_console_par_buffer; @@ -195,24 +190,10 @@ ram_console_save_old(struct ram_console_buffer *buffer, const char *bootinfo, block += ECC_BLOCK_SIZE; par += ECC_SIZE; } - if (ram_console_corrected_bytes || ram_console_bad_blocks) - strbuf_len = snprintf(strbuf, sizeof(strbuf), - "\n%d Corrected bytes, %d unrecoverable blocks\n", - ram_console_corrected_bytes, ram_console_bad_blocks); - else - strbuf_len = snprintf(strbuf, sizeof(strbuf), - "\nNo errors detected\n"); - if (strbuf_len >= sizeof(strbuf)) - strbuf_len = sizeof(strbuf) - 1; - total_size += strbuf_len; #endif - if (bootinfo) - bootinfo_size = strlen(bootinfo) + strlen(bootinfo_label); - total_size += bootinfo_size; - if (dest == NULL) { - dest = kmalloc(total_size, GFP_KERNEL); + dest = kmalloc(old_log_size, GFP_KERNEL); if (dest == NULL) { printk(KERN_ERR "ram_console: failed to allocate buffer\n"); @@ -221,27 +202,15 @@ ram_console_save_old(struct ram_console_buffer *buffer, const char *bootinfo, } ram_console_old_log = dest; - ram_console_old_log_size = total_size; + ram_console_old_log_size = old_log_size; memcpy(ram_console_old_log, &buffer->data[buffer->start], buffer->size - buffer->start); memcpy(ram_console_old_log + buffer->size - buffer->start, &buffer->data[0], buffer->start); - ptr = ram_console_old_log + old_log_size; -#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION - memcpy(ptr, strbuf, strbuf_len); - ptr += strbuf_len; -#endif - if (bootinfo) { - memcpy(ptr, bootinfo_label, strlen(bootinfo_label)); - ptr += strlen(bootinfo_label); - memcpy(ptr, bootinfo, bootinfo_size); - ptr += bootinfo_size; - } } static int __init ram_console_init(struct ram_console_buffer *buffer, - size_t buffer_size, const char *bootinfo, - char *old_buf) + size_t buffer_size, char *old_buf) { #ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION int numerr; @@ -308,7 +277,7 @@ static int __init ram_console_init(struct ram_console_buffer *buffer, printk(KERN_INFO "ram_console: found existing buffer, " "size %d, start %d\n", buffer->size, buffer->start); - ram_console_save_old(buffer, bootinfo, old_buf); + ram_console_save_old(buffer, old_buf); } } else { printk(KERN_INFO "ram_console: no valid data in buffer " @@ -326,6 +295,24 @@ static int __init ram_console_init(struct ram_console_buffer *buffer, return 0; } +static ssize_t ram_console_ecc_string(char *str, size_t len) +{ +#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION + ssize_t ret; + + if (ram_console_corrected_bytes || ram_console_bad_blocks) + ret = snprintf(str, len, "" + "\n%d Corrected bytes, %d unrecoverable blocks\n", + ram_console_corrected_bytes, ram_console_bad_blocks); + else + ret = snprintf(str, len, "\nNo errors detected\n"); + + return ret; +#else + return 0; +#endif +} + #ifdef CONFIG_ANDROID_RAM_CONSOLE_EARLY_INIT static int __init ram_console_early_init(void) { @@ -342,7 +329,6 @@ static int ram_console_driver_probe(struct platform_device *pdev) size_t start; size_t buffer_size; void *buffer; - const char *bootinfo = NULL; struct ram_console_platform_data *pdata = pdev->dev.platform_data; if (res == NULL || pdev->num_resources != 1 || @@ -361,10 +347,13 @@ static int ram_console_driver_probe(struct platform_device *pdev) return -ENOMEM; } - if (pdata) - bootinfo = pdata->bootinfo; + if (pdata) { + bootinfo = kstrdup(pdata->bootinfo, GFP_KERNEL); + if (bootinfo) + bootinfo_size = strlen(bootinfo); + } - return ram_console_init(buffer, buffer_size, bootinfo, NULL/* allocate */); + return ram_console_init(buffer, buffer_size, NULL/* allocate */); } static struct platform_driver ram_console_driver = { @@ -387,14 +376,46 @@ static ssize_t ram_console_read_old(struct file *file, char __user *buf, { loff_t pos = *offset; ssize_t count; + char *str; + int ret; + + /* Main last_kmsg log */ + if (pos < ram_console_old_log_size) { + count = min(len, (size_t)(ram_console_old_log_size - pos)); + if (copy_to_user(buf, ram_console_old_log + pos, count)) + return -EFAULT; + goto out; + } - if (pos >= ram_console_old_log_size) - return 0; + /* ECC correction notice */ + pos -= ram_console_old_log_size; + count = ram_console_ecc_string(NULL, 0); + if (pos < count) { + str = kmalloc(count, GFP_KERNEL); + if (!str) + return -ENOMEM; + ram_console_ecc_string(str, count + 1); + count = min(len, (size_t)(count - pos)); + ret = copy_to_user(buf, str + pos, count); + kfree(str); + if (ret) + return -EFAULT; + goto out; + } - count = min(len, (size_t)(ram_console_old_log_size - pos)); - if (copy_to_user(buf, ram_console_old_log + pos, count)) - return -EFAULT; + /* Boot info passed through pdata */ + pos -= count; + if (pos < bootinfo_size) { + count = min(len, (size_t)(bootinfo_size - pos)); + if (copy_to_user(buf, bootinfo + pos, count)) + return -EFAULT; + goto out; + } + + /* EOF */ + return 0; +out: *offset += count; return count; }