From patchwork Fri May 18 22:25:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 8823 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 C840923EB5 for ; Fri, 18 May 2012 22:26:54 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 7B7B9A183D8 for ; Fri, 18 May 2012 22:26:54 +0000 (UTC) Received: by ggnf1 with SMTP id f1so4151034ggn.11 for ; Fri, 18 May 2012 15:26:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:date:from :to:cc:subject:message-id:references:mime-version:content-type :content-disposition:in-reply-to:user-agent:x-gm-message-state; bh=NrnviDxRYf9xl4TOWgj3HrAsMmxWAKH/lV1LHHhTnqY=; b=FJ0e8dEotgbECFKP8/K7Y1ZFB5dZT2kcblc7quUADgvlWIskSETVrOUEcyeTZ26wbT J0EpFZk5+BbZ8Dn3blZope+rXKCH1ydP54Cqh3Iv6L4gp3YqByI7R1MfonGGAYtygOg+ 4smxOvWaT6y/lgpWXGxVIdH/TYXBu+dHu2I0lSAEcG8RRxvlVIQFO21AnNKecMrCY92p qQQ6TM7KcsFepilJa6yVSLPBxc5hv5J4DikadD8pXQVVruXRf5CxTMNwCD1XyHqvy97l V7UmuL2EVfa4i4ody4YNrxRqCd9qySpkkRU/TXz5cpnliUTbXYlbtmynqYCMfbiKv5y4 5tiA== Received: by 10.42.89.72 with SMTP id f8mr8434626icm.33.1337380013591; Fri, 18 May 2012 15:26:53 -0700 (PDT) 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.35.72 with SMTP id o8csp135288ibd; Fri, 18 May 2012 15:26:53 -0700 (PDT) Received: by 10.68.196.138 with SMTP id im10mr8302010pbc.47.1337380012592; Fri, 18 May 2012 15:26:52 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id qa10si17675425pbb.174.2012.05.18.15.26.52 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 18 May 2012 15:26:52 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) smtp.mail=anton.vorontsov@linaro.org Received: by mail-pb0-f50.google.com with SMTP id rr4so5393549pbb.37 for ; Fri, 18 May 2012 15:26:52 -0700 (PDT) Received: by 10.68.129.102 with SMTP id nv6mr2692940pbb.38.1337380012344; Fri, 18 May 2012 15:26:52 -0700 (PDT) Received: from localhost (c-71-204-165-222.hsd1.ca.comcast.net. [71.204.165.222]) by mx.google.com with ESMTPS id rt4sm14141255pbc.3.2012.05.18.15.26.49 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 18 May 2012 15:26:51 -0700 (PDT) Date: Fri, 18 May 2012 15:25:22 -0700 From: Anton Vorontsov To: Greg Kroah-Hartman , Kees Cook , Colin Cross , Tony Luck Cc: Arnd Bergmann , John Stultz , Shuah Khan , arve@android.com, Rebecca Schultz Zavin , Jesper Juhl , Randy Dunlap , Stephen Boyd , Thomas Meyer , Andrew Morton , Marco Stornelli , WANG Cong , linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org, linaro-kernel@lists.linaro.org, patches@linaro.org, kernel-team@android.com Subject: [PATCH 07/14] pstore/ram: Factor dmesg przs initialization out of probe() Message-ID: <20120518222522.GG23089@lizard> References: <20120518222314.GA9425@lizard> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20120518222314.GA9425@lizard> User-Agent: Mutt/1.5.21 (2010-09-15) X-Gm-Message-State: ALoCoQnCQqjd02r1pxNhPQfb65eT/pU+zDBCCTlWbl+qmaWvDUFv7pUI6osN7ABizFFcSs7F+2KH This will help make code clearer when we'll add support for other message types. This also makes probe() much shorter and understandable, plus makes mem/record size checking a bit easier. Implementation detail: we now use a paddr pointer, this will be used for allocating persistent ram zones for other message types. Signed-off-by: Anton Vorontsov --- fs/pstore/ram.c | 105 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 39 deletions(-) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 408fb07..db0e118 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -203,13 +203,67 @@ static struct ramoops_context oops_cxt = { }, }; +static void ramoops_free_przs(struct ramoops_context *cxt) +{ + int i; + + if (!cxt->przs) + return; + + for (i = 0; cxt->przs[i]; i++) + persistent_ram_free(cxt->przs[i]); + kfree(cxt->przs); +} + +static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt, + phys_addr_t *paddr, size_t dump_mem_sz) +{ + int err = -ENOMEM; + int i; + + if (!cxt->record_size) + return 0; + + cxt->max_dump_count = dump_mem_sz / cxt->record_size; + if (!cxt->max_dump_count) + return -ENOMEM; + + cxt->przs = kzalloc(sizeof(*cxt->przs) * cxt->max_dump_count, + GFP_KERNEL); + if (!cxt->przs) { + dev_err(dev, "failed to initialize a prz array for dumps\n"); + return -ENOMEM; + } + + for (i = 0; i < cxt->max_dump_count; i++) { + size_t sz = cxt->record_size; + + cxt->przs[i] = persistent_ram_new(*paddr, sz, cxt->ecc); + if (IS_ERR(cxt->przs[i])) { + err = PTR_ERR(cxt->przs[i]); + dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n", + sz, (unsigned long long)*paddr, err); + goto fail_prz; + } + *paddr += sz; + } + + cxt->max_count += cxt->max_dump_count; + + return 0; +fail_prz: + ramoops_free_przs(cxt); + return err; +} + static int __init ramoops_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct ramoops_platform_data *pdata = pdev->dev.platform_data; struct ramoops_context *cxt = &oops_cxt; + size_t dump_mem_sz; + phys_addr_t paddr; int err = -EINVAL; - int i; /* Only a single ramoops area allowed at a time, so fail extra * probes. @@ -226,22 +280,7 @@ static int __init ramoops_probe(struct platform_device *pdev) pdata->mem_size = rounddown_pow_of_two(pdata->mem_size); pdata->record_size = rounddown_pow_of_two(pdata->record_size); - /* Check for the minimum memory size */ - if (pdata->mem_size < MIN_MEM_SIZE && - pdata->record_size < MIN_MEM_SIZE) { - pr_err("memory size too small, minimum is %lu\n", - MIN_MEM_SIZE); - goto fail_out; - } - - if (pdata->mem_size < pdata->record_size) { - pr_err("The memory size must be larger than the " - "records size\n"); - goto fail_out; - } - - cxt->max_count = pdata->mem_size / pdata->record_size; - cxt->max_dump_count = cxt->max_count; + cxt->max_count = 0; cxt->count = 0; cxt->size = pdata->mem_size; cxt->phys_addr = pdata->mem_address; @@ -249,24 +288,14 @@ static int __init ramoops_probe(struct platform_device *pdev) cxt->dump_oops = pdata->dump_oops; cxt->ecc = pdata->ecc; - cxt->przs = kzalloc(sizeof(*cxt->przs) * cxt->max_dump_count, GFP_KERNEL); - if (!cxt->przs) { - err = -ENOMEM; - dev_err(dev, "failed to initialize a prz array\n"); - goto fail_out; - } - - for (i = 0; i < cxt->max_dump_count; i++) { - size_t sz = cxt->record_size; - phys_addr_t start = cxt->phys_addr + sz * i; + paddr = cxt->phys_addr; - cxt->przs[i] = persistent_ram_new(start, sz, cxt->ecc); - if (IS_ERR(cxt->przs[i])) { - err = PTR_ERR(cxt->przs[i]); - dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n", - sz, (unsigned long long)start, err); - goto fail_przs; - } + dump_mem_sz = cxt->size; + err = ramoops_init_przs(dev, cxt, &paddr, dump_mem_sz); + if (err) { + pr_err("memory size too small, minimum is %lu\n", + cxt->record_size); + goto fail_count; } cxt->pstore.data = cxt; @@ -279,7 +308,7 @@ static int __init ramoops_probe(struct platform_device *pdev) } err = pstore_register(&cxt->pstore); - if (err) { + if (err || !cxt->max_count) { pr_err("registering with pstore failed\n"); goto fail_buf; } @@ -306,10 +335,8 @@ fail_clear: cxt->pstore.bufsize = 0; cxt->max_count = 0; cxt->max_dump_count = 0; -fail_przs: - for (i = 0; cxt->przs[i]; i++) - persistent_ram_free(cxt->przs[i]); - kfree(cxt->przs); +fail_count: + ramoops_free_przs(cxt); fail_out: return err; }