From patchwork Thu Oct 4 09:41:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yue Haibing X-Patchwork-Id: 978727 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Qp1M1g2xz9s8J for ; Thu, 4 Oct 2018 19:46:15 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42Qp1L6vzHzF318 for ; Thu, 4 Oct 2018 19:46:14 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=huawei.com (client-ip=45.249.212.32; helo=huawei.com; envelope-from=yuehaibing@huawei.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42Qnw13j5xzF3Jm for ; Thu, 4 Oct 2018 19:41:36 +1000 (AEST) Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 894534268DD10; Thu, 4 Oct 2018 17:41:31 +0800 (CST) Received: from localhost (10.177.31.96) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.399.0; Thu, 4 Oct 2018 17:41:22 +0800 From: YueHaibing To: , , , Subject: [PATCH v2 -next] powerpc/pseries/memory-hotplug: Fix return value type of find_aa_index Date: Thu, 4 Oct 2018 17:41:13 +0800 Message-ID: <20181004094113.5492-1-yuehaibing@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.177.31.96] X-CFilter-Loop: Reflected X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: YueHaibing , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 'aa_index' is defined as an unsigned value, but find_aa_index may return -1 when dlpar_clone_property fails. So we use an rc value to track the validation of finding the aa_index instead of the 'aa_index' value itself Fixes: c05a5a40969e ("powerpc/pseries: Dynamic add entires to associativity lookup array") Signed-off-by: YueHaibing --- v2: use 'rc' track the validation of aa_index --- arch/powerpc/platforms/pseries/hotplug-memory.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index 9a15d39..796e68b 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -101,13 +101,12 @@ static struct property *dlpar_clone_property(struct property *prop, return new_prop; } -static u32 find_aa_index(struct device_node *dr_node, - struct property *ala_prop, const u32 *lmb_assoc) +static int find_aa_index(struct device_node *dr_node, struct property *ala_prop, + const u32 *lmb_assoc, u32 *aa_index) { u32 *assoc_arrays; - u32 aa_index; int aa_arrays, aa_array_entries, aa_array_sz; - int i, index; + int i, index, rc = -1; /* * The ibm,associativity-lookup-arrays property is defined to be @@ -121,18 +120,18 @@ static u32 find_aa_index(struct device_node *dr_node, aa_array_entries = be32_to_cpu(assoc_arrays[1]); aa_array_sz = aa_array_entries * sizeof(u32); - aa_index = -1; for (i = 0; i < aa_arrays; i++) { index = (i * aa_array_entries) + 2; if (memcmp(&assoc_arrays[index], &lmb_assoc[1], aa_array_sz)) continue; - aa_index = i; + *aa_index = i; + rc = 0; break; } - if (aa_index == -1) { + if (rc == -1) { struct property *new_prop; u32 new_prop_size; @@ -157,10 +156,11 @@ static u32 find_aa_index(struct device_node *dr_node, * number of entries - 1 since we added its associativity * to the end of the lookup array. */ - aa_index = be32_to_cpu(assoc_arrays[0]) - 1; + *aa_index = be32_to_cpu(assoc_arrays[0]) - 1; + rc = 0; } - return aa_index; + return rc; } static int update_lmb_associativity_index(struct drmem_lmb *lmb) @@ -169,6 +169,7 @@ static int update_lmb_associativity_index(struct drmem_lmb *lmb) struct property *ala_prop; const u32 *lmb_assoc; u32 aa_index; + int rc; parent = of_find_node_by_path("/"); if (!parent) @@ -200,11 +201,11 @@ static int update_lmb_associativity_index(struct drmem_lmb *lmb) return -ENODEV; } - aa_index = find_aa_index(dr_node, ala_prop, lmb_assoc); + rc = find_aa_index(dr_node, ala_prop, lmb_assoc, &aa_index); dlpar_free_cc_nodes(lmb_node); - if (aa_index < 0) { + if (rc < 0) { pr_err("Could not find LMB associativity\n"); return -1; }