From patchwork Thu Mar 8 01:34:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 7155 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 B49E023EA9 for ; Thu, 8 Mar 2012 01:34:56 +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 380CCA18466 for ; Thu, 8 Mar 2012 01:34:56 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so12685171iag.11 for ; Wed, 07 Mar 2012 17:34:56 -0800 (PST) Received: by 10.50.45.228 with SMTP id q4mr3491147igm.58.1331170495993; Wed, 07 Mar 2012 17:34:55 -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 k18csp159ibg; Wed, 7 Mar 2012 17:34:53 -0800 (PST) Received: by 10.68.190.8 with SMTP id gm8mr6450960pbc.146.1331170493259; Wed, 07 Mar 2012 17:34:53 -0800 (PST) Received: from e31.co.us.ibm.com (e31.co.us.ibm.com. [32.97.110.149]) by mx.google.com with ESMTPS id l3si2686236pbs.94.2012.03.07.17.34.52 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 07 Mar 2012 17:34:53 -0800 (PST) Received-SPF: pass (google.com: domain of jstultz@us.ibm.com designates 32.97.110.149 as permitted sender) client-ip=32.97.110.149; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jstultz@us.ibm.com designates 32.97.110.149 as permitted sender) smtp.mail=jstultz@us.ibm.com Received: from /spool/local by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 7 Mar 2012 18:34:52 -0700 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 7 Mar 2012 18:34:49 -0700 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 8F8133E4004A; Wed, 7 Mar 2012 18:34:48 -0700 (MST) Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q281YmYS138468; Wed, 7 Mar 2012 18:34:48 -0700 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q281YlEG016507; Wed, 7 Mar 2012 18:34:48 -0700 Received: from kernel.beaverton.ibm.com (kernel.beaverton.ibm.com [9.47.67.96]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q281YlKZ016488; Wed, 7 Mar 2012 18:34:47 -0700 Received: by kernel.beaverton.ibm.com (Postfix, from userid 1056) id 60BAAC0419; Wed, 7 Mar 2012 17:34:46 -0800 (PST) From: John Stultz To: lkml Cc: Colin Cross , Greg KH , Android Kernel Team , John Stultz Subject: [PATCH 02/11] android: ram_console: move footer strings Date: Wed, 7 Mar 2012 17:34:29 -0800 Message-Id: <1331170478-30538-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.3.2.146.gca209 In-Reply-To: <1331170478-30538-1-git-send-email-john.stultz@linaro.org> References: <1331170478-30538-1-git-send-email-john.stultz@linaro.org> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12030801-7282-0000-0000-0000072F2228 X-Gm-Message-State: ALoCoQl02jgz0wTvzXtyIlQEQQJFwvwkM2buy6Ey8AxsjiX5fh/8m/i6HKte6b6sgtxLtWUcgfo6 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 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; }