From patchwork Fri Nov 4 11:43:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 9412557 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C974960723 for ; Fri, 4 Nov 2016 11:43:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBC802ADC2 for ; Fri, 4 Nov 2016 11:43:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B04932ADC6; Fri, 4 Nov 2016 11:43:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 723E72ADC2 for ; Fri, 4 Nov 2016 11:43:40 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c2csm-0007la-Nx; Fri, 04 Nov 2016 11:42:04 +0000 Received: from conuserg-12.nifty.com ([210.131.2.79]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c2csT-0007hU-Ds for linux-arm-kernel@lists.infradead.org; Fri, 04 Nov 2016 11:41:46 +0000 Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-12.nifty.com with ESMTP id uA4Bf7H9017322; Fri, 4 Nov 2016 20:41:08 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com uA4Bf7H9017322 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1478259668; bh=GewLLyoOIps2A2fRWEK2N0lt27JWPq1+3GskrVc38FI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KBFRh2q/4cxGpvc/E8R0F0weKN4Dt5culjIx02Z6AI7jvPZKl1Wtj4Hnbw43r77/8 c2p1lz2qkRFWKzkqoTagJHifWGjwWihZUwp8WbOlQfg5APRtIH9pWxWMdFCqeJQ1Uy yD4qG8CHGUCALERK1YGhEUKJ8bVaY+nnAG7rC9R/774FpbWIekUd9OkSw2zGuCgdFK faSRI2ddsnFAb9RGY4kRTLTJJZnBhqH8LniS2qu3+vVBneVnvPITmG8gdGyLN+2czI fnxNX9CPNLsYpdqb+ZcQ8qsaCsnZPS9r1n2IkAqaoz3k8GqeowV4eeOJzcqG6jG/F7 1cqnylvb+NyEA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/3] ARM: cache-uniphier: call kzalloc() after DT property parsing Date: Fri, 4 Nov 2016 20:43:34 +0900 Message-Id: <1478259816-24965-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1478259816-24965-1-git-send-email-yamada.masahiro@socionext.com> References: <1478259816-24965-1-git-send-email-yamada.masahiro@socionext.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161104_044145_862809_34714AD7 X-CRM114-Status: GOOD ( 11.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Masahiro Yamada , Russell King , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Allocate memory after DT property parsing that has more possibility of failure. This will decrease the number of bail-out points for kfree(). Signed-off-by: Masahiro Yamada --- arch/arm/mm/cache-uniphier.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/arch/arm/mm/cache-uniphier.c b/arch/arm/mm/cache-uniphier.c index dfe97b4..58f2ddb 100644 --- a/arch/arm/mm/cache-uniphier.c +++ b/arch/arm/mm/cache-uniphier.c @@ -328,7 +328,7 @@ static int __init __uniphier_cache_init(struct device_node *np, unsigned int *cache_level) { struct uniphier_cache_data *data; - u32 level, cache_size; + u32 level, line_size, nsets, cache_size; struct device_node *next_np; int ret = 0; @@ -354,36 +354,34 @@ static int __init __uniphier_cache_init(struct device_node *np, return -EINVAL; } - data = kzalloc(sizeof(*data), GFP_KERNEL); - if (!data) - return -ENOMEM; - - if (of_property_read_u32(np, "cache-line-size", &data->line_size) || - !is_power_of_2(data->line_size)) { + if (of_property_read_u32(np, "cache-line-size", &line_size) | + !is_power_of_2(line_size)) { pr_err("L%d: cache-line-size is unspecified or invalid\n", *cache_level); - ret = -EINVAL; - goto err; + return -EINVAL; } - if (of_property_read_u32(np, "cache-sets", &data->nsets) || - !is_power_of_2(data->nsets)) { + if (of_property_read_u32(np, "cache-sets", &nsets) || + !is_power_of_2(nsets)) { pr_err("L%d: cache-sets is unspecified or invalid\n", *cache_level); - ret = -EINVAL; - goto err; + return -EINVAL; } if (of_property_read_u32(np, "cache-size", &cache_size) || - cache_size == 0 || cache_size % (data->nsets * data->line_size)) { + cache_size == 0 || cache_size % (nsets * line_size)) { pr_err("L%d: cache-size is unspecified or invalid\n", *cache_level); - ret = -EINVAL; - goto err; + return -EINVAL; } - data->way_present_mask = - ((u32)1 << cache_size / data->nsets / data->line_size) - 1; + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->line_size = line_size; + data->nsets = nsets; + data->way_present_mask = ((u32)1 << cache_size / nsets / line_size) - 1; data->ctrl_base = of_iomap(np, 0); if (!data->ctrl_base) {