From patchwork Mon Apr 17 06:01:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97492 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1212531qgf; Sun, 16 Apr 2017 23:03:00 -0700 (PDT) X-Received: by 10.98.148.2 with SMTP id m2mr10220814pfe.28.1492408980380; Sun, 16 Apr 2017 23:03:00 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y67si10036543pfj.22.2017.04.16.23.02.59; Sun, 16 Apr 2017 23:03:00 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S932645AbdDQGCr (ORCPT + 12 others); Mon, 17 Apr 2017 02:02:47 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:33408 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932810AbdDQGCo (ORCPT ); Mon, 17 Apr 2017 02:02:44 -0400 Received: by mail-pf0-f176.google.com with SMTP id s16so61535562pfs.0 for ; Sun, 16 Apr 2017 23:02:44 -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 :in-reply-to:references; bh=R/nCdBoYFzlttycp21aPwBW7xgWIZPpWNbAyzQbNzcA=; b=UJ4xXWKlUaXtpIFf08VsACV4Rzw6uRnfJ3ouaQBvsi3jEtSmpjLNBVKcQBzpqGbBRk Zs/mbHXLFf1WRvpK350DZcej8vU0nZUoceJmFj1YUCxbZmsYhKxyqQP6YUtDCg2IMz0P iNhHcifjIcQakhPKHpLr0b7r6KM5xQC/m7e3o= 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:in-reply-to:references; bh=R/nCdBoYFzlttycp21aPwBW7xgWIZPpWNbAyzQbNzcA=; b=W/Se777Rh7qUi0l8lpfpY2FuqZEMmzTYUoljnpkXLO2hYUkksJrjt8phL0gWr6ePFG rmmY8ivVyMXfH0xGcVTsMVSFFitrHaNB11gJer6BVBH7H6DXLR7NVZMIKuDI+vLrg69t WsaMmKE9Kz593Namn7zRGneNKycsheSnlcJJrRRPOC29RHfXsXkqz/8bH67G+G3eq6Gt KhpM0D7IMeoqWQ0Rla+bjwsXOWvpseKhRYq92ieFO3PbxBZfg59jEcTLDYRoXe8eSK2y 4FhyUhu4zVM6zvl3BODdeqFyHgWZpnD02foKVoaR8dNImso4sX+3JABcspUdRNhRQADx 6o5g== X-Gm-Message-State: AN3rC/5r3AZPak2wFD0pnkUs3dNFktimpoPKACJwI8ihre4AOx1aOCCv mig8IeNWQWllhU0K X-Received: by 10.84.168.4 with SMTP id e4mr13543864plb.138.1492408964282; Sun, 16 Apr 2017 23:02:44 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id 133sm15274661pfy.106.2017.04.16.23.02.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Apr 2017 23:02:43 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , "4 . 2+" Subject: [PATCH V2 01/17] thermal: cpu_cooling: Avoid accessing potentially freed structures Date: Mon, 17 Apr 2017 11:31:46 +0530 Message-Id: X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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+ # 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.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 69d0f430b2d1..be29489dd247 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -153,8 +153,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);