From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751398AbcFNLLV (ORCPT ); Tue, 14 Jun 2016 07:11:21 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:37866 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751140AbcFNLLT (ORCPT ); Tue, 14 Jun 2016 07:11:19 -0400 X-IBM-Helo: d23dlp03.au.ibm.com X-IBM-MailFrom: shreyas@linux.vnet.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org;linux-pm@vger.kernel.org Date: Tue, 14 Jun 2016 16:41:08 +0530 From: Shreyas B Prabhu User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.0 MIME-Version: 1.0 To: benh@au1.ibm.com, mpe@ellerman.id.au CC: ego@linux.vnet.ibm.com, mikey@neuling.org, Daniel Lezcano , linux-pm@vger.kernel.org, "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, Rob Herring , maddy@linux.vnet.ibm.com, Lorenzo Pieralisi , linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH v6 10/11] cpuidle/powernv: Add support for POWER ISA v3 idle states References: <1465404871-5406-1-git-send-email-shreyas@linux.vnet.ibm.com> <1465404871-5406-11-git-send-email-shreyas@linux.vnet.ibm.com> <1465854492.3022.30.camel@au1.ibm.com> In-Reply-To: <1465854492.3022.30.camel@au1.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16061411-0004-0000-0000-0000016DED4E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16061411-0005-0000-0000-000008126B69 Message-Id: <575FE64C.9080107@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-06-14_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606140125 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/14/2016 03:18 AM, Benjamin Herrenschmidt wrote: > On Wed, 2016-06-08 at 11:54 -0500, Shreyas B. Prabhu wrote: >> >> /* >> * States for dedicated partition case. >> */ >> @@ -167,6 +183,8 @@ static int powernv_add_idle_states(void) >> int nr_idle_states = 1; /* Snooze */ >> int dt_idle_states; >> u32 *latency_ns, *residency_ns, *flags; >> + u64 *psscr_val = NULL; >> + const char *names[CPUIDLE_STATE_MAX]; >> int i, rc; >> >> /* Currently we have snooze statically defined */ >> @@ -199,12 +217,41 @@ static int powernv_add_idle_states(void) >> goto out_free_latency; >> } >> >> + rc = of_property_read_string_array(power_mgt, >> + "ibm,cpu-idle-state-names", names, >> + dt_idle_states); > > Ok so from this I assume that dt_idle_states is the number of entries, > which has been checked properly to be < CPUIDLE_STATE_MAX correct ? > > Beause ... > While dt_idle_states should not be > CPUIDLE_STATE_MAX, if that were the case we will end up corrupting memory while updating powernv_states[]. I'll add a WARN_ON for such a case and handle adding idle states to powernv_states accordingly. Thanks for pointing this out. >> + if (rc < 0) { >> + pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-names in DT\n"); >> + goto out_free_latency; >> + } >> + >> + /* >> + * If the idle states use stop instruction, probe for psscr values >> + * which are necessary to specify required stop level. >> + */ >> + if (flags[0] & (OPAL_PM_STOP_INST_FAST | OPAL_PM_STOP_INST_DEEP)) { >> + psscr_val = kcalloc(dt_idle_states, sizeof(*psscr_val), >> + GFP_KERNEL); >> + rc = of_property_read_u64_array(power_mgt, >> + "ibm,cpu-idle-state-psscr", >> + psscr_val, dt_idle_states); > > Here, psscr val is only one u64 ... shouldn't you kmalloc sizeof(..) * > dt_idle_states ? I'm using kcalloc here since checkpatch script suggested kcalloc over kzalloc for allocating memory for arrays. I'll also include a patch to use kcalloc throughout the file for uniformity in next version. I was originally planning to post that cleanup separately. Thanks, Shreyas