From patchwork Mon Jun 22 08:02:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 50134 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3E17A21594 for ; Mon, 22 Jun 2015 08:03:21 +0000 (UTC) Received: by wiea6 with SMTP id a6sf8097502wie.1 for ; Mon, 22 Jun 2015 01:03:20 -0700 (PDT) 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=I/8MWP/NG0sCXAUrreXum/RiSFx2fIBsT1TesdXfrVw=; b=A7d9SBENHBE93MV7m3h9BRGDiDgGBkgUsmQibKC39GmpXBQZJECoW3sOcFSMMcM3Qw dAPj/9peSGIEz16O53vM4YG/Qf23MdH2VXQI2ak57FPERdGTEDk0m3eVLvsGr/CoFBTR UaASgM3Vx5Ph/lOa7tJk7f09cW/auT+xU3xc+kgM83dxQ1464fbHs1ycX0gmkfu3cfki crEjEh44pxDcgNMQoG5xjTiv3pIImGegywtcamWi+lhGk4bKBbHhgr86xKkoUIg8yqkb /Z/9xphvtpHNmGU+B9lTJejuL/qfoQAS+TRkKKiZMLS47bEcO1ujlu74IbNxLNmxq35U NLgg== X-Gm-Message-State: ALoCoQklqkQzRKFoGV+SxX0aQ0l7jR4MDREQo2mhlIOYx+eIps9RF9cHMV2wRqvKagnB2ht7AVkU X-Received: by 10.112.42.236 with SMTP id r12mr27041225lbl.2.1434960200336; Mon, 22 Jun 2015 01:03:20 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.7 with SMTP id m7ls883906laj.70.gmail; Mon, 22 Jun 2015 01:03:20 -0700 (PDT) X-Received: by 10.152.42.134 with SMTP id o6mr23401003lal.14.1434960200185; Mon, 22 Jun 2015 01:03:20 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id tp6si15902317lbb.97.2015.06.22.01.03.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jun 2015 01:03:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by lbbti3 with SMTP id ti3so103599196lbb.1 for ; Mon, 22 Jun 2015 01:03:20 -0700 (PDT) X-Received: by 10.112.155.197 with SMTP id vy5mr28535373lbb.29.1434960200092; Mon, 22 Jun 2015 01:03:20 -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.108.230 with SMTP id hn6csp2208694lbb; Mon, 22 Jun 2015 01:03:19 -0700 (PDT) X-Received: by 10.70.38.105 with SMTP id f9mr56792586pdk.14.1434960198396; Mon, 22 Jun 2015 01:03:18 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j10si28342941pbq.257.2015.06.22.01.03.17; Mon, 22 Jun 2015 01:03:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754380AbbFVIDQ (ORCPT + 11 others); Mon, 22 Jun 2015 04:03:16 -0400 Received: from mail-pd0-f181.google.com ([209.85.192.181]:35132 "EHLO mail-pd0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754192AbbFVIDP (ORCPT ); Mon, 22 Jun 2015 04:03:15 -0400 Received: by pdbci14 with SMTP id ci14so75090367pdb.2 for ; Mon, 22 Jun 2015 01:03:14 -0700 (PDT) X-Received: by 10.70.63.104 with SMTP id f8mr57027946pds.49.1434960194756; Mon, 22 Jun 2015 01:03:14 -0700 (PDT) Received: from localhost ([122.167.71.211]) by mx.google.com with ESMTPSA id qs8sm18855867pbc.38.2015.06.22.01.03.13 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 22 Jun 2015 01:03:14 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Preeti U Murthy Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Viresh Kumar Subject: [PATCH 02/10] cpufreq: conservative: Avoid races with transition notifier Date: Mon, 22 Jun 2015 13:32:49 +0530 Message-Id: <41ef05ed3b93677b4519e4c6c758753a7e63d432.1434959517.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.4.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.174 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: , It is possible that cpufreq transition notifier is called while the governor is performing its EXIT operation. If this happens, 'ccdbs' may get updated to NULL, while it is being accessed from the notifier callback. And that will result in NULL pointer dereference. ccdbs is used here just to get cpufreq policy, which can be obtained from cpufreq_cpu_get() as well. And so the reference to ccdbs can be avoided. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq_conservative.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c index 0e4154e584bf..1e3cabfb2b57 100644 --- a/drivers/cpufreq/cpufreq_conservative.c +++ b/drivers/cpufreq/cpufreq_conservative.c @@ -119,12 +119,13 @@ static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val, struct cpufreq_freqs *freq = data; struct cs_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, freq->cpu); - struct cpufreq_policy *policy; + struct cpufreq_policy *policy = cpufreq_cpu_get(freq->cpu); - if (!dbs_info->enable) + if (!policy) return 0; - policy = dbs_info->cdbs.ccdbs->policy; + if (!dbs_info->enable) + goto policy_put; /* * we only care if our internally tracked freq moves outside the 'valid' @@ -134,6 +135,9 @@ static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val, || dbs_info->requested_freq < policy->min) dbs_info->requested_freq = freq->new; +policy_put: + cpufreq_cpu_put(policy); + return 0; }