Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp6019385imb; Fri, 8 Mar 2019 07:35:04 -0800 (PST) X-Google-Smtp-Source: APXvYqxPdSw2cDP5DVl9E1fbQORs/ZS5k6lMuJuehZtQJSI33w03nLBfU5WDWOkA1JH8OXAfXMnu X-Received: by 2002:a17:902:2884:: with SMTP id f4mr18683665plb.203.1552059304493; Fri, 08 Mar 2019 07:35:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552059304; cv=none; d=google.com; s=arc-20160816; b=SOaLq5XEwq8qFR39UwQo62Mn9HeEXZnxaBt0a9hEGUk5//nT4nAdaydcf9iaXpgg+r IJg+tjZZjMeHJIZeZtblvBi7dNj0msYPe5IJ7m7e7T1Gyn388qE02KV9EHTvro2HSiMJ fGTCaKuaiMwFKQ4KR37ekG00CdB9HXm+BIi2y15Uzwi2Z+FaoZiU10J3VD1/Q/xPMTQE b7DtFND/LEtfjyIxiI9mHjFHN095puOiUf3trCdfS6Cx2zOnPhxNk7VYrJnfzfEIWCHv OR4e6eCfek+WbIzkFrEoLAkXlFt3WSDtOsJrB1P+cdverby4MpAJ2gPWIFE8Emg/sKTY Qugg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=B6jsDmGL5Nd5kjNWBDehbHFhnownvPFfYHoVovnVdlc=; b=DNk93htjvHSWkI3xANlALvmAaJuQWQHPviOFidowPiqvqve7WB7Dpe1lqXsNSER0Eb 2aVUVVstOoPxCIjm+IKTlEmnkFuZKZwxtm8c91vOLvK+x7XkaE5X8FaMQH3CYzQcGbVA pSBbz31jIaZYi+OLRhbjS4zwYiO8XdhTnsnCAPK41LrGk8FCdf9S9z/BPhbi/YiDFE2+ QMkEZui9BDuHjaIVUWAZHMih2ddO27oDYSF8cCabyyzvR7ojjrV3lzpvPb6YcISXacLY d03nCthG+cmSmarN8MSLjnIVLLDP+aZP5ELGaR/izERLVHdJb0sxKddv81su3DUjwaoo Xt2A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2si6895037plr.167.2019.03.08.07.34.48; Fri, 08 Mar 2019 07:35:04 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726545AbfCHPdn (ORCPT + 99 others); Fri, 8 Mar 2019 10:33:43 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:60454 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726297AbfCHPdn (ORCPT ); Fri, 8 Mar 2019 10:33:43 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x28FTC7W092001 for ; Fri, 8 Mar 2019 10:33:42 -0500 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 2r3tfjacw6-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 08 Mar 2019 10:33:41 -0500 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 8 Mar 2019 15:33:41 -0000 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 8 Mar 2019 15:33:38 -0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x28FXb4025100504 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 8 Mar 2019 15:33:37 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 87FAFC6057; Fri, 8 Mar 2019 15:33:37 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 38402C6059; Fri, 8 Mar 2019 15:33:37 +0000 (GMT) Received: from sofia.ibm.com (unknown [9.102.1.126]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 8 Mar 2019 15:33:37 +0000 (GMT) Received: by sofia.ibm.com (Postfix, from userid 1000) id 560D92E2D49; Fri, 8 Mar 2019 21:03:34 +0530 (IST) From: "Gautham R. Shenoy" To: Michael Bringmann , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Vaidyanathan Srinivasan Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, "Pavithra R. Prakash" , "Gautham R. Shenoy" , Subject: [PATCH] pseries/energy: Use OF accessor functions to read ibm,drc-indexes Date: Fri, 8 Mar 2019 21:03:24 +0530 X-Mailer: git-send-email 1.8.3.1 X-TM-AS-GCONF: 00 x-cbid: 19030815-0036-0000-0000-00000A95EEC4 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010727; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000281; SDB=6.01171437; UDB=6.00612311; IPR=6.00952080; MB=3.00025893; MTD=3.00000008; XFM=3.00000015; UTC=2019-03-08 15:33:40 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19030815-0037-0000-0000-00004AF751AD Message-Id: <1552059204-18626-1-git-send-email-ego@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-08_13:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903080108 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Gautham R. Shenoy" In cpu_to_drc_index() in the case when FW_FEATURE_DRC_INFO is absent, we currently use of_read_property() to obtain the pointer to the array corresponding to the property "ibm,drc-indexes". The elements of this array are of type __be32, but are accessed without any conversion to the OS-endianness, which is buggy on a Little Endian OS. Fix this by using of_property_read_u32_index() accessor function to safely read the elements of the array. Fixes: commit e83636ac3334 ("pseries/drc-info: Search DRC properties for CPU indexes") Cc: #v4.16+ Reported-by: Pavithra R. Prakash Signed-off-by: Gautham R. Shenoy --- arch/powerpc/platforms/pseries/pseries_energy.c | 27 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/platforms/pseries/pseries_energy.c b/arch/powerpc/platforms/pseries/pseries_energy.c index 6ed2212..1c4d1ba 100644 --- a/arch/powerpc/platforms/pseries/pseries_energy.c +++ b/arch/powerpc/platforms/pseries/pseries_energy.c @@ -77,18 +77,27 @@ static u32 cpu_to_drc_index(int cpu) ret = drc.drc_index_start + (thread_index * drc.sequential_inc); } else { - const __be32 *indexes; - - indexes = of_get_property(dn, "ibm,drc-indexes", NULL); - if (indexes == NULL) - goto err_of_node_put; + u32 nr_drc_indexes, thread_drc_index; /* - * The first element indexes[0] is the number of drc_indexes - * returned in the list. Hence thread_index+1 will get the - * drc_index corresponding to core number thread_index. + * The first element of ibm,drc-indexes array is the + * number of drc_indexes returned in the list. Hence + * thread_index+1 will get the drc_index corresponding + * to core number thread_index. */ - ret = indexes[thread_index + 1]; + rc = of_property_read_u32_index(dn, "ibm,drc-indexes", + 0, &nr_drc_indexes); + if (rc) + goto err_of_node_put; + + WARN_ON(thread_index > nr_drc_indexes); + rc = of_property_read_u32_index(dn, "ibm,drc-indexes", + thread_index + 1, + &thread_drc_index); + if (rc) + goto err_of_node_put; + + ret = thread_drc_index; } rc = 0; -- 1.9.4