Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp6040003imb; Fri, 8 Mar 2019 08:02:24 -0800 (PST) X-Google-Smtp-Source: APXvYqxMLoWgjGxry2/9e/hVVGIcVWEIivbeWYFkNmi7P48zTZQdSc1gPgffY6nf20UUc9gf0WHG X-Received: by 2002:a62:110c:: with SMTP id z12mr19407529pfi.184.1552060944335; Fri, 08 Mar 2019 08:02:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552060944; cv=none; d=google.com; s=arc-20160816; b=GS5cxFwXiwGLKjh/myWp+l6scQ2ufRS3aM0e7bIotmIQA/vo3qZh7aEiKwunGKXaJQ IX4wF/TC5jUO56iIA4utm7ELOpmk2nejVhyrgo3fHHJmnt00Vgh6hxJoZ7WvhdEx/aNs CSXO5PIKPA3YAH2288LtPrJ5zPeWwHQOiKQgCcdmLMNbBw+huL41esM5Hv7Fjcxan0nB fpCFzG0MQycL7jCnL4MPOPf8OsL7vZ90nUP0hxEpeV84Va0nQTp5NW5HTcvsoPHZ3qRm 98dDz8squWdAVnlgpMtMOdasEacu6aKZdB+D03EjxTjLOC1G0Z2/oRMEVSmulKf6u/u7 wgeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date; bh=mh0o+sAJBmLF9i7BMI04pDFGUJyP9pr9Er0cBTCy5Eo=; b=XC7fL+NDb0bGy4DcpSp3Gr8J87EKQtrHBZpK7n2VfUrxMvMr7xfeaNXDZeg6G3xnRi EaEN5+ue4yju9hpe7ZPllCpsqzuDM1e0wfzwTAv9994pauOqcvEgizQ3XSrYC65uOsEt y9WauRDw3h1fWhNY9YFL0Y9k4ZyGBKpUUdEEt1s5iBOgRzXTTJTJNOg0aMHdnnkhrfK6 gzlVcO8rETo/xJWDfCb54JLxI5Z8r1R3jRAs3uNvhtW2eQqwIaVjCgHi3QglEludVVZ+ /u06Ns0Q0CZB5QGafEa5BnMV26epBkDkTIkDSSJlEcHqKTh6HyPvVXpcrNtbiC75DBk8 bP5w== 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 65si7768888pfg.28.2019.03.08.08.02.07; Fri, 08 Mar 2019 08:02:24 -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 S1726544AbfCHQBq (ORCPT + 99 others); Fri, 8 Mar 2019 11:01:46 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:49418 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726258AbfCHQBn (ORCPT ); Fri, 8 Mar 2019 11:01:43 -0500 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x28FxJdX115907 for ; Fri, 8 Mar 2019 11:01:42 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0b-001b2d01.pphosted.com with ESMTP id 2r3sbyenkh-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 08 Mar 2019 11:01:39 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 8 Mar 2019 16:01:15 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp01.uk.ibm.com (192.168.101.131) 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 16:01:11 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x28G1A6737355686 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 8 Mar 2019 16:01:10 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C9BCD4C040; Fri, 8 Mar 2019 16:01:10 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BA0CC4C05E; Fri, 8 Mar 2019 16:01:08 +0000 (GMT) Received: from drishya.in.ibm.com (unknown [9.85.68.185]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Fri, 8 Mar 2019 16:01:08 +0000 (GMT) Date: Fri, 8 Mar 2019 21:31:06 +0530 From: Vaidyanathan Srinivasan To: "Gautham R. Shenoy" Cc: Michael Bringmann , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, "Pavithra R. Prakash" , stable@vger.kernel.org Subject: Re: [PATCH] pseries/energy: Use OF accessor functions to read ibm,drc-indexes Reply-To: svaidy@linux.vnet.ibm.com References: <1552059204-18626-1-git-send-email-ego@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1552059204-18626-1-git-send-email-ego@linux.vnet.ibm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-TM-AS-GCONF: 00 x-cbid: 19030816-4275-0000-0000-00000318A81D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19030816-4276-0000-0000-0000382706D3 Message-Id: <20190308160106.GA5263@drishya.in.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-08_14:,, 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=1011 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-1903080110 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Gautham R Shenoy [2019-03-08 21:03:24]: > 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 Reviewed-by: Vaidyanathan Srinivasan > --- > 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; Oops! Good bugfix. We should use device tree accessors like this in all places for correct and safe code. Thanks! --Vaidy