From patchwork Tue Jun 19 02:15:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 9417 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 AD84A23F19 for ; Tue, 19 Jun 2012 02:18:11 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id 7A558A18AAB for ; Tue, 19 Jun 2012 02:18:11 +0000 (UTC) Received: by yenq6 with SMTP id q6so4762394yen.11 for ; Mon, 18 Jun 2012 19:18:10 -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:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=AcI+O6lSp344WTFl+J+scxG2bYRidi3FJc80VkJdLHk=; b=QHi5mXPvyGNsur75SmPdLSm94zxuFrp7urAKeIPGve+B4ig1GZdvdJHCmtAk8kCk4X gWSBjv9KU95MOSaxi2HH+iMMtPn7+2/6IOLxJG3fFgKPJMp4Ajnc93s0pufc97jep+Ae xeH/DlBt7Ey/iM3Fwo2DEyiwcWoKj94TYw6eeuK7BQq9VhmDkxwR4y3fG/6IYK1gLG2W sg1L36Wwag51LrFgJyJzO+eVK+JB2GInrmgVs8X5f3FJvmQ1nfGX7oYYGBzPyncSW8Na 6nymKKBUPi2pM7QO+yBAuJEjY3Q5zohHa4/ueDFbJTir1oMWDtcY1mmUBU7b270ypq+n GEKQ== Received: by 10.42.210.193 with SMTP id gl1mr6536920icb.57.1340072290787; Mon, 18 Jun 2012 19:18:10 -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.24.148 with SMTP id v20csp101049ibb; Mon, 18 Jun 2012 19:18:10 -0700 (PDT) Received: by 10.68.217.233 with SMTP id pb9mr58353534pbc.121.1340072289945; Mon, 18 Jun 2012 19:18:09 -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 qa1si9911089pbb.216.2012.06.18.19.18.09 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 18 Jun 2012 19:18:09 -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 rr4so10377373pbb.37 for ; Mon, 18 Jun 2012 19:18:09 -0700 (PDT) Received: by 10.68.222.163 with SMTP id qn3mr58382024pbc.135.1340072289693; Mon, 18 Jun 2012 19:18:09 -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 jp3sm25996598pbc.7.2012.06.18.19.18.04 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 18 Jun 2012 19:18:09 -0700 (PDT) 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 3/7] pstore/ram_core: Proper checking for post_init errors (e.g. improper ECC size) Date: Mon, 18 Jun 2012 19:15:52 -0700 Message-Id: <1340072156-6225-3-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <20120619021050.GA19387@lizard> References: <20120619021050.GA19387@lizard> X-Gm-Message-State: ALoCoQm1sRbXNjRIpxkDbmPIm5v9/sNZ1H0JRXTB+jwVVl1adZXp7zcxl7XFBZIFj5atr817c2pL We will implement variable-sized ECC buffers soon, so post_init routine might fail much more likely, so we'd better check for its errors. To make error handling simple, modify persistent_ram_free() to it be safe at all times. Signed-off-by: Anton Vorontsov Acked-by: Kees Cook --- fs/pstore/ram_core.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c index 2653185..f62ebf2 100644 --- a/fs/pstore/ram_core.c +++ b/fs/pstore/ram_core.c @@ -427,11 +427,17 @@ static int __devinit persistent_ram_post_init(struct persistent_ram_zone *prz, void persistent_ram_free(struct persistent_ram_zone *prz) { - if (pfn_valid(prz->paddr >> PAGE_SHIFT)) { - vunmap(prz->vaddr); - } else { - iounmap(prz->vaddr); - release_mem_region(prz->paddr, prz->size); + if (!prz) + return; + + if (prz->vaddr) { + if (pfn_valid(prz->paddr >> PAGE_SHIFT)) { + vunmap(prz->vaddr); + } else { + iounmap(prz->vaddr); + release_mem_region(prz->paddr, prz->size); + } + prz->vaddr = NULL; } persistent_ram_free_old(prz); kfree(prz); @@ -454,10 +460,12 @@ struct persistent_ram_zone * __devinit persistent_ram_new(phys_addr_t start, if (ret) goto err; - persistent_ram_post_init(prz, ecc); + ret = persistent_ram_post_init(prz, ecc); + if (ret) + goto err; return prz; err: - kfree(prz); + persistent_ram_free(prz); return ERR_PTR(ret); }