Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1697836ybg; Wed, 29 Jul 2020 23:35:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHnYBCj1DE6aj05S+XaTObWTWEBzcmhM1/pK1te2vnJeFiRaQ6g/1NzOIpOcX+K/xgwItC X-Received: by 2002:a50:ed8d:: with SMTP id h13mr1223861edr.68.1596090942204; Wed, 29 Jul 2020 23:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596090942; cv=none; d=google.com; s=arc-20160816; b=lhnAChXlpnEG2ThTV4XiKQfI4Uytwlk8bIxUHv1lh6dzga4Ti/TOPXVYOfx0LseXXz yvMpnrhMcKWLXfmeXlTIsW7nMKjrgMDLi5gZ5lBXsfSwiwXsARGTLzTLILRr+nmB4NPx 3WfP7TkEkGTgVx5y/3WR5ONNG30iUVDDw3u2QjI567S0Wn84SirHOg7LxUnb7b6JRpmO Um6XbRFmpPpE0esGT9VYfAVsjqoMn7PTm8fsEEhz81hOrH9r22W8GMXM4kUvmngaW9Qv dHsCcOR5ZChxcDl/OzYOONgCe1xIBHSdmi1/jR5Sh6feledO4OIcXSHbHm0MP1egB8yY 594Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Izry41/ecx9ATbNxmuDnZTe3d/XHOvLEgFerJTmZ78s=; b=EuECAw3sFK+hzsjQIxi5t4pz0BlRpvMOPcipqPBX7IK4yR4YhPXnWMsP0bchaNmt31 fwUngXN8A6UgXC5KTEP+7HH5STxxB6nAeNmr72FdeVjwEr3AoryS9edi83seeYmnHxLk 8Cmnm0jdFSdcpCyVg/3Ji16xqbYrJt3Mf248aTHYUJ8Nz1fgofrqRjhe8Gq6cr6ZT1ZI J9wvYUgRuDpsd+NbpYpV0OXsQmM4xy5A+zOeluSqCz199S1c5zPP1sGnZGUfeQnfVa9q 37avLdoSr4meT5fd/fIkEfzDTaGwN+TYEf3yHk4AHkQyIIMrJ2EIAKR3LRdeSebqzMSS qH3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pcyKjnxA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k6si2687292edn.299.2020.07.29.23.35.19; Wed, 29 Jul 2020 23:35:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pcyKjnxA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728758AbgG3Gck (ORCPT + 99 others); Thu, 30 Jul 2020 02:32:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:39294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728586AbgG3Gck (ORCPT ); Thu, 30 Jul 2020 02:32:40 -0400 Received: from mail-ua1-f51.google.com (mail-ua1-f51.google.com [209.85.222.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 74C162083B for ; Thu, 30 Jul 2020 06:32:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596090759; bh=gmLQHj64FkaGgheaXBUyCURKlTKz98iDmLTqsyXvdvc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=pcyKjnxAp1lbX4V/QXWlO9nvvxyG7yNXfzIaTpM5q0sMdTBU9YoCVR+1QVfk1YpxB c6nmJpqRkwZOhqrLEj1dD1UnjWbmLaD7KBJ6rMCy8Xu2gMjintotMoT+opqoB4XCz+ AM2TMwQTd+nncHMa6MlTVcpaA2nM73mjmT14MBAg= Received: by mail-ua1-f51.google.com with SMTP id x19so2245696uap.11 for ; Wed, 29 Jul 2020 23:32:39 -0700 (PDT) X-Gm-Message-State: AOAM5326IMAazmbGVpVPc9VPxOlMu41BooNYudwg1dBTSKFGKLo7Z9YK zRusRtc7TaVRA+Nk+1MXSbL3sBnaEDexZuV9HchExQ== X-Received: by 2002:a9f:2742:: with SMTP id a60mr1017353uaa.48.1596090758571; Wed, 29 Jul 2020 23:32:38 -0700 (PDT) MIME-Version: 1.0 References: <20200730061041.gyprgwfkzfb64t3m@vireshk-mac-ubuntu> In-Reply-To: <20200730061041.gyprgwfkzfb64t3m@vireshk-mac-ubuntu> From: Amit Kucheria Date: Thu, 30 Jul 2020 12:02:27 +0530 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] cpufreq: cached_resolved_idx can not be negative To: Viresh Kumar Cc: Rafael Wysocki , Andy Gross , Bjorn Andersson , Linux PM list , Vincent Guittot , ionela.voinescu@arm.com, linux-arm-msm , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 30, 2020 at 11:40 AM Viresh Kumar wrote: > > On 30-07-20, 11:29, Amit Kucheria wrote: > > On Thu, Jul 30, 2020 at 9:38 AM Viresh Kumar wrote: > > > > > > It is not possible for cached_resolved_idx to be invalid here as the > > > cpufreq core always sets index to a positive value. > > > > > > Change its type to unsigned int and fix qcom usage a bit. > > > > Shouldn't you fix up idx in cpufreq_driver_resolve_freq() to be > > unsigned int too? > > Yes, merged this into the patch. Looking at this more closely, I found another call site for cpufreq_frequency_table_target() in cpufreq.c that needs the index to be unsigned int. But then cpufreq_frequency_table_target() returns -EINVAL, so we should be able to handle int values. I think you will need to fix the unconditional assignment of policy->cached_resolved_idx = idx in cpufreq_driver_resolve_freq(). It doesn't check for -EINVAL, so the qcom driver is write in checking for a negative value. > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > index 0128de3603df..053d72e52a31 100644 > --- a/drivers/cpufreq/cpufreq.c > +++ b/drivers/cpufreq/cpufreq.c > @@ -538,7 +538,7 @@ unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, > policy->cached_target_freq = target_freq; > > if (cpufreq_driver->target_index) { > - int idx; > + unsigned int idx; > > idx = cpufreq_frequency_table_target(policy, target_freq, > CPUFREQ_RELATION_L); > > -- > viresh