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: 9627127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 22833604A9 for ; Thu, 16 Mar 2017 05:30:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1203A285F5 for ; Thu, 16 Mar 2017 05:30:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02F6B28637; Thu, 16 Mar 2017 05:30:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80A25285F5 for ; Thu, 16 Mar 2017 05:30:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751047AbdCPF37 (ORCPT ); Thu, 16 Mar 2017 01:29:59 -0400 Received: from mail-pf0-f172.google.com ([209.85.192.172]:36811 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750884AbdCPF36 (ORCPT ); Thu, 16 Mar 2017 01:29:58 -0400 Received: by mail-pf0-f172.google.com with SMTP id o126so18987911pfb.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=pfWsIVTjitBP0ImsaWecGmxjEipnzLsGRvI/+72MU4g+veCDWq4TWtV/oKSSFpkDTm WmlJOpyFwWgazVEXH9oPLazj0FE5h97XkppkiSJXbeF29O3iFqiQV/8rNOySwYMMnyiY iyPoV1NEAuhCqDXZDwC4xU9v0IxTBHQ9eXWNbMAFLHwYoDkLb5PXMatPyGCSnQAcFQgr moC8QZB8iGRG+qz5ZQVZ2IaUhh7oQjmCqrqrDQ7NSfwc3WiauTAfjzdGdQLIpOFQunLS wPeOHsf1PaqSDyYq902HiJA2q75i1vp5hGzylRDAAY+hL0Y7inSZwavt/95c1qXoTCBX VVCw== X-Gm-Message-State: AFeK/H1wyiN+zfclX4qpJtVSZTCC1wcK4BND2Mrm79Jle4Zsz6lSDAf1uRSom+p5+EzX6rzn 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: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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);