From patchwork Thu Mar 16 05:29:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 95371 Delivered-To: patch@linaro.org Received: by 10.140.89.134 with SMTP id v6csp660488qgd; Wed, 15 Mar 2017 22:30:00 -0700 (PDT) X-Received: by 10.98.94.2 with SMTP id s2mr7965600pfb.133.1489642200305; Wed, 15 Mar 2017 22:30:00 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s2si2921832pfe.85.2017.03.15.22.29.59; Wed, 15 Mar 2017 22:30:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750987AbdCPF37 (ORCPT + 5 others); Thu, 16 Mar 2017 01:29:59 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:36010 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750919AbdCPF36 (ORCPT ); Thu, 16 Mar 2017 01:29:58 -0400 Received: by mail-pg0-f42.google.com with SMTP id g2so19537705pge.3 for ; Wed, 15 Mar 2017 22:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6KqgEAJAIWQt0Qij1SmLDoR31Tdt819Ky4639ZYzD8E=; b=PjcTpkX3ouuL20pgVpai2w8v9Y6MhUlLIWIjQiDYq1t1eJaBWP3lrJyZVu6VefM6P+ w23Obq9ZxbROTtN/ySmEPcYM0WgVQxH1xqQcpeMKmJbD2PwHqw5WaW7IZXmTgiKY4fef ZGEfAE0GZ677ymCA5zGNg6Zzfu1A+9C7GQoKo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6KqgEAJAIWQt0Qij1SmLDoR31Tdt819Ky4639ZYzD8E=; b=lOuh9tVnJ7lme0eLlZ73uOrMDPbmnPFzItrD7LstpGd4/xDA8U0t97SNXmM7qJW4Ni 1TpK87LMYWe08BSo/Pp0Jw/20+Jbt/OaOrPuLxY/5xq/3h6PhUR/F/GSYCLk//LiQNLp ZMz3zYloXW/ra1t4kzaT2u1WQtvvYjwOd8LwkqJcNMmZcee4SfgVbpggoHMWULAc9rkq 6Ol2OOTHrnq/Khc17PQxvRTRczMzR34sm8Nc7yX6H/u4iNXCGLljyqt7qBo6Te8qe2PI 6COftOgNdkm2bqhB4WDi25tltcGVzQm4oSBxwBhXQEWn0Tafzps7QamlmWpuysu7A4X3 OqzQ== X-Gm-Message-State: AFeK/H0iK0v2lZ4EnmEVssJZZAq0Jck6Jd5uq3TENmW/72/IZzlAgJiyk5kwXoW55LKgq1pV X-Received: by 10.84.233.193 with SMTP id m1mr9853384pln.118.1489642197361; Wed, 15 Mar 2017 22:29:57 -0700 (PDT) Received: from localhost ([122.171.239.200]) by smtp.gmail.com with ESMTPSA id b190sm7386639pfa.110.2017.03.15.22.29.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Mar 2017 22:29:56 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Javi Merino , Zhang Rui , Eduardo Valentin , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , "4 . 2+" Subject: [PATCH 01/17] thermal: cpu_cooling: Avoid accessing potentially freed structures Date: Thu, 16 Mar 2017 10:59:36 +0530 Message-Id: X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org After the lock is dropped, it is possible that the cpufreq_dev gets freed before we call get_level() and that can cause kernel to crash. Drop the lock after we are done using the structure. Cc: 4.2+ Fixes: 02373d7c69b4 ("thermal: cpu_cooling: fix lockdep problems in cpu_cooling") Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.7.1.410.g6faf27b diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index c2525b585487..6fd258d62e47 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -155,8 +155,10 @@ unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq) mutex_lock(&cooling_list_lock); list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) { if (cpumask_test_cpu(cpu, &cpufreq_dev->allowed_cpus)) { + unsigned long level = get_level(cpufreq_dev, freq); + mutex_unlock(&cooling_list_lock); - return get_level(cpufreq_dev, freq); + return level; } } mutex_unlock(&cooling_list_lock);