From patchwork Thu Dec 18 12:00:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 42440 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 456E826C8B for ; Thu, 18 Dec 2014 12:01:55 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id hs14sf653721lab.5 for ; Thu, 18 Dec 2014 04:01:54 -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=rt8E4dvCebpuCuRbxzRjzYCdVSHZE3wcNEgiOzVO8RM=; b=FrdWt0Jt7Kv3/Bo4fWBn3oj9XQGoDtKUemBIpU+v06RJITNWPH0SMlOrAqmHOBqwcC qYSVKqjhAQ4kgon5iXcn5Io2hu1K2vJ8n8o858c+04rgJCfmxRm8FAgkrLb5adlfHHpC MRrF0dHxxfMCszLsc5DITO3KBb1l7Qpz1TDrruLCXxZjU8loborm2lz3OE5GF5VCDk2g PyrnoqUTeVDGym6/REP5/Oc6qr7qEGsXVQLbDhsIAH/+0ZGyiZM+otSM1SbEZ1ggpWaR +kWfHVtVfYgadn+HeHeDvNIGwVNDuF6ziA8QtPk0Dkh6f/sIRMnr0MFLHbdQ741wA/sK gC6A== X-Gm-Message-State: ALoCoQlyg91kuWV6POc8lRZ3WEJCYiFS/P/TdCpRHPsrsrZNgzrXVpnwi/ZtYfD2ua42JOawGUyt X-Received: by 10.112.171.167 with SMTP id av7mr284801lbc.2.1418904114272; Thu, 18 Dec 2014 04:01:54 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.170 with SMTP id p10ls1227423lal.35.gmail; Thu, 18 Dec 2014 04:01:53 -0800 (PST) X-Received: by 10.152.6.8 with SMTP id w8mr1854380law.41.1418904113834; Thu, 18 Dec 2014 04:01:53 -0800 (PST) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id li1si6608761lab.112.2014.12.18.04.01.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 18 Dec 2014 04:01:53 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by mail-lb0-f175.google.com with SMTP id u10so836285lbd.34 for ; Thu, 18 Dec 2014 04:01:53 -0800 (PST) X-Received: by 10.152.2.41 with SMTP id 9mr1776972lar.47.1418904113746; Thu, 18 Dec 2014 04:01:53 -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.142.69 with SMTP id ru5csp1680609lbb; Thu, 18 Dec 2014 04:01:52 -0800 (PST) X-Received: by 10.68.137.101 with SMTP id qh5mr2752523pbb.13.1418904111862; Thu, 18 Dec 2014 04:01:51 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ov3si9608661pbc.228.2014.12.18.04.01.51; Thu, 18 Dec 2014 04:01:51 -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 S1752450AbaLRMBu (ORCPT + 12 others); Thu, 18 Dec 2014 07:01:50 -0500 Received: from mail-pd0-f177.google.com ([209.85.192.177]:48747 "EHLO mail-pd0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752473AbaLRMBu (ORCPT ); Thu, 18 Dec 2014 07:01:50 -0500 Received: by mail-pd0-f177.google.com with SMTP id ft15so1280058pdb.8 for ; Thu, 18 Dec 2014 04:01:49 -0800 (PST) X-Received: by 10.66.159.164 with SMTP id xd4mr2916504pab.54.1418904109169; Thu, 18 Dec 2014 04:01:49 -0800 (PST) Received: from localhost ([122.166.148.73]) by mx.google.com with ESMTPSA id jd1sm6628941pbd.49.2014.12.18.04.01.47 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 18 Dec 2014 04:01:48 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Viresh Kumar Subject: [PATCH 12/13] cpufreq: stats: Fix locking Date: Thu, 18 Dec 2014 17:30:29 +0530 Message-Id: <6277a557b0102524ca317bf0aa94d7b479375d6e.1418902789.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.217.175 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. 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 7701532b32c8..e18735816908 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -149,10 +149,12 @@ static void __cpufreq_stats_free_table(struct cpufreq_policy *policy) pr_debug("%s: Free stat table\n", __func__); + spin_lock(&cpufreq_stats_lock); sysfs_remove_group(&policy->kobj, &stats_attr_group); kfree(stat->time_in_state); kfree(stat); policy->stats_data = NULL; + spin_unlock(&cpufreq_stats_lock); } static void cpufreq_stats_free_table(unsigned int cpu) @@ -181,13 +183,17 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy) if (unlikely(!table)) return 0; + spin_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) @@ -218,21 +224,21 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy) stat->freq_table[i++] = pos->frequency; stat->state_num = i; - spin_lock(&cpufreq_stats_lock); stat->last_time = get_jiffies_64(); stat->last_index = freq_table_get_index(stat, policy->cur); - spin_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: + spin_unlock(&cpufreq_stats_lock); return ret; }