From patchwork Fri Mar 20 04:41:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 46128 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8EF002153C for ; Fri, 20 Mar 2015 04:41:55 +0000 (UTC) Received: by lbdu10 with SMTP id u10sf11154878lbd.3 for ; Thu, 19 Mar 2015 21:41:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mime-version:in-reply-to:references :date:message-id:subject:from:to:cc:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=T3yceHhcAIr4xEd+4HGu0FGOV5oItNzM8b4GRZ+nufI=; b=WrZSvOWhxHXNodaiynGZFrC7ZYrvXE9q6buwG2Chg1IcwzRnMdlDI+I7tvQnSeOIQm pmMTkhYW7BS+iPeiP5oiZjLOpgYuNbIcby6LK+sU2f0lT1iS4Z4T3qyylhK3hCCqCvXV DqtmeKtwtLloC5Y3NNA25DzzBUQ2oH+J1TngH/IRz5Q8C8WEY0o91yZooGJmGWGAbEg5 GVK6YkNSsXOyH9v10HO6pSkeHcREzNDVKtBnWMikitPjxRZv/g3LGEMztV9E9egFFNlT apZ4iKATkd6lShC9zBt27L4J2/vuwpyDWgplUpH/DnzSSl0xbc8mc+KYOYmZ/cJBFTqk tfQw== X-Gm-Message-State: ALoCoQldETMKgXAqwSFSgZjBLAiZyIu5AdURjYAHkaAnedW5RHtpZG9okrVbxjuMajoEJcXAvZop X-Received: by 10.194.201.10 with SMTP id jw10mr12697406wjc.3.1426826513650; Thu, 19 Mar 2015 21:41:53 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.162 with SMTP id c2ls27330laa.69.gmail; Thu, 19 Mar 2015 21:41:53 -0700 (PDT) X-Received: by 10.152.5.194 with SMTP id u2mr71731341lau.88.1426826513451; Thu, 19 Mar 2015 21:41:53 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id ds4si2399828lac.34.2015.03.19.21.41.53 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 21:41:53 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by ladw1 with SMTP id w1so78447382lad.0 for ; Thu, 19 Mar 2015 21:41:53 -0700 (PDT) X-Received: by 10.112.8.101 with SMTP id q5mr66013619lba.19.1426826513222; Thu, 19 Mar 2015 21:41:53 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp797094lbj; Thu, 19 Mar 2015 21:41:52 -0700 (PDT) X-Received: by 10.70.91.110 with SMTP id cd14mr42210814pdb.48.1426826511341; Thu, 19 Mar 2015 21:41:51 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ee5si6950254pac.139.2015.03.19.21.41.50; Thu, 19 Mar 2015 21:41:51 -0700 (PDT) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751199AbbCTElt (ORCPT + 11 others); Fri, 20 Mar 2015 00:41:49 -0400 Received: from mail-ob0-f169.google.com ([209.85.214.169]:34628 "EHLO mail-ob0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750889AbbCTEls (ORCPT ); Fri, 20 Mar 2015 00:41:48 -0400 Received: by obbgg8 with SMTP id gg8so70328551obb.1 for ; Thu, 19 Mar 2015 21:41:48 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.60.134.17 with SMTP id pg17mr56163075oeb.12.1426826508325; Thu, 19 Mar 2015 21:41:48 -0700 (PDT) Received: by 10.182.250.51 with HTTP; Thu, 19 Mar 2015 21:41:48 -0700 (PDT) In-Reply-To: <550B7159.7090601@codeaurora.org> References: <3335dcc924b60249617dfad711c602927fb1f2b7.1424345053.git.viresh.kumar@linaro.org> <550B7159.7090601@codeaurora.org> Date: Fri, 20 Mar 2015 10:11:48 +0530 Message-ID: Subject: Re: [PATCH V2 06/20] cpufreq: Create for_each_{in}active_policy() From: Viresh Kumar To: Saravana Kannan Cc: Rafael Wysocki , Linaro Kernel Mailman List , "linux-pm@vger.kernel.org" , Stephen Boyd , Prarit Bhargava Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On 20 March 2015 at 06:31, Saravana Kannan wrote: > On 02/19/2015 03:32 AM, Viresh Kumar wrote: >> +static struct cpufreq_policy *next_policy(struct cpufreq_policy *policy, >> + bool active) >> +{ >> + while (1) { > > > I don't like while(1) unless it's really meant to be an infinite loop. I I don't hate it that much, and neither does other parts of kernel :) > think a do while would work here and also be more compact and readable. So you want this: else @@ -69,9 +69,9 @@ static struct cpufreq_policy *next_policy(struct cpufreq_policy *policy, * 1 0 policy * 1 1 next */ - if (active ^ policy_is_inactive(policy)) - return policy; - }; + } while (!(active ^ policy_is_inactive(policy))); + + return policy; } Not sure which one looked better :) >> + if (likely(policy)) >> + policy = list_next_entry(policy, policy_list); >> + else >> + policy = list_first_entry(&cpufreq_policy_list, >> + typeof(*policy), >> policy_list); > > > Can't you just move this part into expr1? That would make it much > clear/easier to understand No, because we want that for-loop to iterate over active/inactive policies only, and we need to run this routine to find it.. For ex: - We want to iterate over active policies only - The first policy of the list is inactive - The change you are suggesting will break things here.. >> + >> + /* No more policies */ >> + if (&policy->policy_list == &cpufreq_policy_list) >> + return policy; > > > I'm kinda confused by the fact that you return policy here unconditionally. > I think it's a bug. No? Eg: Is there's only one policy in the system and you > are looking for an inactive policy. Wouldn't this return the only policy -- > the one that's active. No. What we are returning here isn't a real policy actually but an container-of of the HEAD of the list, so it only has a valid ->policy_list value, others might give us a crash. See how list_next_entry() works :) --- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index d3f9ce3b94d3..ecbd8c2118c2 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -47,7 +47,7 @@ static inline bool policy_is_inactive(struct cpufreq_policy *policy) static struct cpufreq_policy *next_policy(struct cpufreq_policy *policy, bool active) { - while (1) { + do { if (likely(policy)) policy = list_next_entry(policy, policy_list);