Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4910121imm; Tue, 9 Oct 2018 07:03:32 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Y1isQpcwxqndYSJeDNBFd4S/YuX5SzZZMFhUhJpbBBoGwxEwE6Equ80oOSpbVweCPmTTf X-Received: by 2002:a62:939d:: with SMTP id r29-v6mr30401867pfk.55.1539093812201; Tue, 09 Oct 2018 07:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539093812; cv=none; d=google.com; s=arc-20160816; b=04HKZLb9VkxMmu7ZgUDbExlVuEnp3B+pufY68mPo5SnYB0fxSXaxtFWePI1IyiNHoT 4ijPFlg3W53eEIF5Z+vfDZRVMktVjHMb0rD4idNBP+BHMFUD+j/7gOjHttq+iE7rfxiL ipcGKpHULSTilhhCGT778Cl8s1mKXxSFSkXct6ds4u6RMArLcnj/eHim/krGWj4zasbU rlyZF2Bi1uskTh+hLiJysaQxNeGelLWy0eOzG4jLu6ZI6nckYwCpoy7vC64zsay5dJgw VhvWuQm4+M3Tfpmzy8sSyJBrg3TZKEXcm16B0hqdHqDk5o9cUCmYfs9R520CeHMIQQJo k+fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=AqctBKfUOUKycQXJtMqSaLZShr8XeZNyNUzJAR/33xA=; b=MUGAL/pBB4SIDPbzv4FZ+Z5iG5QWCduwuweVRYzXU0+scaKZbAaLTDFNKH5RFeESib 0mqSDoLenUdjp/L5GEV8wCL3BrbZKzHsiAlmyEIgNNV5orv+p3NqsNQ0TilRTKsTo03u rP3Sg5syvjDClJZ6gP67++9IAiSzesucTZENq08VYPZl1/C2b0dEtrStgl1leK8Nrn/q Qhf56y2rmufTJYQ/Dy28Fn8Q1pu9VLsZOYTgu8r4oB4/M+ErMYlHa9nJeBnbwzQ4MmgE 3eFo+5UkpDZGm/Vomov470oFO2aIpcWIXAvkC9dKD8xuG3/McAu8i9D5UEyLuY15moNX JClg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f132-v6si19068249pgc.484.2018.10.09.07.03.17; Tue, 09 Oct 2018 07:03:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726722AbeJIVTd (ORCPT + 99 others); Tue, 9 Oct 2018 17:19:33 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:42853 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726617AbeJIVTd (ORCPT ); Tue, 9 Oct 2018 17:19:33 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 3350075B0C332; Tue, 9 Oct 2018 22:02:23 +0800 (CST) Received: from localhost (10.177.31.96) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.399.0; Tue, 9 Oct 2018 22:02:14 +0800 From: YueHaibing To: , , , CC: , , YueHaibing Subject: [PATCH v3 -next] powerpc/pseries/memory-hotplug: Fix return value type of find_aa_index Date: Tue, 9 Oct 2018 21:59:13 +0800 Message-ID: <20181009135913.14616-1-yuehaibing@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.177.31.96] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 'aa_index' is defined as an unsigned value, but find_aa_index may return -1 when dlpar_clone_property fails. So change find_aa_index return value type to bool, which indicate 'aa_index' whether found or not. Fixes: c05a5a40969e ("powerpc/pseries: Dynamic add entires to associativity lookup array") Signed-off-by: YueHaibing --- v3: change find_aa_index return type to bool v2: use 'rc' track the validation of aa_index --- arch/powerpc/platforms/pseries/hotplug-memory.c | 61 ++++++++++++------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index d26a771..4db510f 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -101,11 +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 bool 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; + u32 *assoc_arrays, new_prop_size; + struct property *new_prop; int aa_arrays, aa_array_entries, aa_array_sz; int i, index; @@ -121,46 +122,39 @@ 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; - break; + *aa_index = i; + return true; } - if (aa_index == -1) { - struct property *new_prop; - u32 new_prop_size; - - new_prop_size = ala_prop->length + aa_array_sz; - new_prop = dlpar_clone_property(ala_prop, new_prop_size); - if (!new_prop) - return -1; - - assoc_arrays = new_prop->value; + new_prop_size = ala_prop->length + aa_array_sz; + new_prop = dlpar_clone_property(ala_prop, new_prop_size); + if (!new_prop) + return false; - /* increment the number of entries in the lookup array */ - assoc_arrays[0] = cpu_to_be32(aa_arrays + 1); + assoc_arrays = new_prop->value; - /* copy the new associativity into the lookup array */ - index = aa_arrays * aa_array_entries + 2; - memcpy(&assoc_arrays[index], &lmb_assoc[1], aa_array_sz); + /* increment the number of entries in the lookup array */ + assoc_arrays[0] = cpu_to_be32(aa_arrays + 1); - of_update_property(dr_node, new_prop); + /* copy the new associativity into the lookup array */ + index = aa_arrays * aa_array_entries + 2; + memcpy(&assoc_arrays[index], &lmb_assoc[1], aa_array_sz); - /* - * The associativity lookup array index for this lmb is - * 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; - } + of_update_property(dr_node, new_prop); - return aa_index; + /* + * The associativity lookup array index for this lmb is + * 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; + return true; } static int update_lmb_associativity_index(struct drmem_lmb *lmb) @@ -169,6 +163,7 @@ static int update_lmb_associativity_index(struct drmem_lmb *lmb) struct property *ala_prop; const u32 *lmb_assoc; u32 aa_index; + bool is_found; parent = of_find_node_by_path("/"); if (!parent) @@ -200,11 +195,11 @@ static int update_lmb_associativity_index(struct drmem_lmb *lmb) return -ENODEV; } - aa_index = find_aa_index(dr_node, ala_prop, lmb_assoc); + is_found = find_aa_index(dr_node, ala_prop, lmb_assoc, &aa_index); dlpar_free_cc_nodes(lmb_node); - if (aa_index < 0) { + if (!is_found) { pr_err("Could not find LMB associativity\n"); return -1; } -- 2.7.0