From patchwork Fri Jan 2 05:46:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 42671 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 730ED26CB5 for ; Fri, 2 Jan 2015 05:47:57 +0000 (UTC) Received: by mail-la0-f69.google.com with SMTP id gd6sf10359012lab.4 for ; Thu, 01 Jan 2015 21:47:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=UZeoksT0Hf71DXliw8st56WNJYh0Futshjx38X4KprE=; b=kuPryZx+e1B+OE1lw2BmdfRBKhul1ujAICCfnE8B42N7dHPbT7JEtVgPEM6+MjdzqJ 1Vit+X8KH5MwEb6V/0njco7KUruV2O7FtlkspQgO7XuY8yf5z3svARx4jfvKYW2KScXR qSBNzgYqnWppCuWh4Mi/0fuQohIpt9LreIqNJLf4afXhudEhRU+/Tquq3uy25p0EZJDe rsxicwch6mMYxa85cxI2WkpFRNnS/GAd3R1h4+grviiLmiWpP2MQTKjA13s9vh7qtt7e higZ7LHhaQSld8Ij06Q0l73a1L042w8EJm48M1I47nWmHaa7uA2t0fBpg+AJPC+sFPSc NumQ== X-Gm-Message-State: ALoCoQnVZScb862bWN92plB0rFhTCNa48DOJ2nLycP9d2IIJjg+kbbsmlFjFVbeWmYfdkBR4quem X-Received: by 10.180.105.97 with SMTP id gl1mr7867626wib.7.1420177676367; Thu, 01 Jan 2015 21:47:56 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.202 with SMTP id v10ls1949099lag.77.gmail; Thu, 01 Jan 2015 21:47:56 -0800 (PST) X-Received: by 10.152.7.180 with SMTP id k20mr76146222laa.4.1420177676003; Thu, 01 Jan 2015 21:47:56 -0800 (PST) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id un3si50348102lbb.21.2015.01.01.21.47.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 Jan 2015 21:47:55 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id gf13so14803659lab.7 for ; Thu, 01 Jan 2015 21:47:55 -0800 (PST) X-Received: by 10.112.163.33 with SMTP id yf1mr13659454lbb.56.1420177675912; Thu, 01 Jan 2015 21:47:55 -0800 (PST) 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.9.200 with SMTP id c8csp114533lbb; Thu, 1 Jan 2015 21:47:55 -0800 (PST) X-Received: by 10.70.133.35 with SMTP id oz3mr116070810pdb.69.1420177673915; Thu, 01 Jan 2015 21:47:53 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3si68097479pdc.177.2015.01.01.21.47.52; Thu, 01 Jan 2015 21:47:53 -0800 (PST) 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 S1750753AbbABFrw (ORCPT + 12 others); Fri, 2 Jan 2015 00:47:52 -0500 Received: from mail-pd0-f179.google.com ([209.85.192.179]:38214 "EHLO mail-pd0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750716AbbABFrv (ORCPT ); Fri, 2 Jan 2015 00:47:51 -0500 Received: by mail-pd0-f179.google.com with SMTP id fp1so23231955pdb.38 for ; Thu, 01 Jan 2015 21:47:51 -0800 (PST) X-Received: by 10.70.89.105 with SMTP id bn9mr119423310pdb.155.1420177671271; Thu, 01 Jan 2015 21:47:51 -0800 (PST) Received: from localhost ([122.167.116.151]) by mx.google.com with ESMTPSA id z14sm45335814pdl.82.2015.01.01.21.47.50 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 01 Jan 2015 21:47:50 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, prarit@redhat.com, skannan@codeaurora.org, Viresh Kumar Subject: [PATCH V2 13/14] cpufreq: stats: Fix locking Date: Fri, 2 Jan 2015 11:16:50 +0530 Message-Id: <0447fedc2d07cd35eed66d7de97ad4e0940b6110.1420177186.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.2.0 In-Reply-To: References: In-Reply-To: References: 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.48 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: , Locking wasn't handled properly at places and this patch is an attempt to fix it. Specially while creating/removing stat tables. Reviewed-by: Prarit Bhargava Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq_stats.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index de55ca86b6f1..95867985ea02 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -150,10 +150,12 @@ static void __cpufreq_stats_free_table(struct cpufreq_policy *policy) pr_debug("%s: Free stat table\n", __func__); + mutex_lock(&cpufreq_stats_lock); sysfs_remove_group(&policy->kobj, &stats_attr_group); kfree(stat->time_in_state); kfree(stat); policy->stats_data = NULL; + mutex_unlock(&cpufreq_stats_lock); } static void cpufreq_stats_free_table(unsigned int cpu) @@ -182,13 +184,17 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy) if (unlikely(!table)) return 0; + mutex_lock(&cpufreq_stats_lock); + /* stats already initialized */ - if (policy->stats_data) - return -EEXIST; + if (policy->stats_data) { + ret = -EEXIST; + goto unlock; + } stat = kzalloc(sizeof(*stat), GFP_KERNEL); if (!stat) - return -ENOMEM; + goto unlock; /* Find total allocation size */ cpufreq_for_each_valid_entry(pos, table) @@ -219,21 +225,21 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy) stat->freq_table[i++] = pos->frequency; stat->state_num = i; - mutex_lock(&cpufreq_stats_lock); stat->last_time = get_jiffies_64(); stat->last_index = freq_table_get_index(stat, policy->cur); - mutex_unlock(&cpufreq_stats_lock); policy->stats_data = stat; ret = sysfs_create_group(&policy->kobj, &stats_attr_group); if (!ret) - return 0; + goto unlock; /* We failed, release resources */ policy->stats_data = NULL; kfree(stat->time_in_state); free_stat: kfree(stat); +unlock: + mutex_unlock(&cpufreq_stats_lock); return ret; }