From patchwork Wed Sep 24 08:27:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 4962551 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 59DE39F32B for ; Wed, 24 Sep 2014 08:29:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 857AC2026C for ; Wed, 24 Sep 2014 08:29:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 575372010C for ; Wed, 24 Sep 2014 08:29:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753834AbaIXI1x (ORCPT ); Wed, 24 Sep 2014 04:27:53 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:28512 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753747AbaIXI1u (ORCPT ); Wed, 24 Sep 2014 04:27:50 -0400 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NCE00FTACUCQX90@mailout4.samsung.com>; Wed, 24 Sep 2014 17:27:49 +0900 (KST) X-AuditID: cbfee61b-f79d76d0000024d6-ac-5422808477c3 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id BA.AE.09430.48082245; Wed, 24 Sep 2014 17:27:48 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NCE00FDSCTFY620@mmp1.samsung.com>; Wed, 24 Sep 2014 17:27:48 +0900 (KST) From: Lukasz Majewski To: Zhang Rui , Eduardo Valentin Cc: Linux PM list , Lukasz Majewski , Bartlomiej Zolnierkiewicz , linux-kernel@vger.kernel.org, Lukasz Majewski Subject: [PATCH 2/3] thermal: core: fix: Initialize the max_state variable to 0 Date: Wed, 24 Sep 2014 10:27:11 +0200 Message-id: <1411547232-21493-3-git-send-email-l.majewski@samsung.com> X-Mailer: git-send-email 1.7.10.4 In-reply-to: <1411547232-21493-1-git-send-email-l.majewski@samsung.com> References: <1411547232-21493-1-git-send-email-l.majewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprALMWRmVeSWpSXmKPExsVy+t9jAd2WBqUQgwd/LC02zljPajH/yjVW izePuC3ePNzMaHF51xw2i8+9RxgtnjzsY3Ng99g56y67x+I9L5k81k17y+zRt2UVo8fnTXIB rFFcNimpOZllqUX6dglcGW9n3WUrWM5dsXnJG/YGxr2cXYycHBICJhKTNs5hg7DFJC7cWw9m CwksYpT4fiuzi5ELyO5iknjVvh8swSagJ/H57lOmLkYODhEBb4ktazhAapgFbjBKTOmfDBYX FvCXmHE5BKScRUBVYunfzcwgYV4BN4n9TVBrFSW6n00Am8gp4C5x8/czdoi1bhIHfx1kn8DI u4CRYRWjaGpBckFxUnqukV5xYm5xaV66XnJ+7iZGcDg9k97BuKrB4hCjAAejEg/vBHGlECHW xLLiytxDjBIczEoivCdKgUK8KYmVValF+fFFpTmpxYcYpTlYlMR5D7ZaBwoJpCeWpGanphak FsFkmTg4pRoYO9ViXqwRy+3eFOXn4z/xcJHPwdsWryYZb9jUt/7jobuX7LKy1oj26nFNdPFd p5qpX+nS8m36QaljNqse5LnlZ/F4OF06K3XnfO5lu0zHb6GbfvXc5ejPCSz6dJIpZ2KpeeS/ /g1yTL8u6ffeUXeaEqRfcjOqcgVj7c3Gd4uz1EVtgryLs/KVWIozEg21mIuKEwG6/sEwIwIA AA== Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Pointer to the uninitialized max_state variable is passed to get the maximal cooling state. For CPU cooling device (cpu_cooling.c) the cpufreq_get_max_state() is called, which even when error occurs will return the max_state variable unchanged. Since error for ->get_max_state() is not checked, the automatically allocated value of max_state is used for (upper > max_state) comparison. For any possible max_state value it is very unlikely that it will be less than upper. As a consequence, the cooling device is bind even without the backed cpufreq table initialized. This initialization will prevent from accidental binding trip points to cpu freq cooling frequencies when cpufreq driver itself is not yet fully initialized. Signed-off-by: Lukasz Majewski --- drivers/thermal/thermal_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 454884a..747618a 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -927,7 +927,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, struct thermal_instance *pos; struct thermal_zone_device *pos1; struct thermal_cooling_device *pos2; - unsigned long max_state; + unsigned long max_state = 0; int result; if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))