From patchwork Wed May 11 09:49:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michele DiGiorgio X-Patchwork-Id: 67494 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp131670qge; Wed, 11 May 2016 02:54:44 -0700 (PDT) X-Received: by 10.98.85.195 with SMTP id j186mr3488188pfb.50.1462960484148; Wed, 11 May 2016 02:54:44 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z62si8572552pfi.48.2016.05.11.02.54.43; Wed, 11 May 2016 02:54:44 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751348AbcEKJym (ORCPT + 14 others); Wed, 11 May 2016 05:54:42 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.140]:57254 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751129AbcEKJyl (ORCPT ); Wed, 11 May 2016 05:54:41 -0400 Received: from e108455-lin.cambridge.arm.com (e108455-lin.cambridge.arm.com [10.1.205.133]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with SMTP id u4B9nIwF030873; Wed, 11 May 2016 10:49:22 +0100 Received: by e108455-lin.cambridge.arm.com (sSMTP sendmail emulation); Wed, 11 May 2016 10:49:18 +0100 From: Michele Di Giorgio To: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Javi Merino , Michele Di Giorgio , Zhang Rui , Eduardo Valentin , Peter Feuerer Subject: [PATCH] thermal: check validity get_trip_hyst function pointer in bang-bang governor Date: Wed, 11 May 2016 10:49:07 +0100 Message-Id: <1462960147-9175-1-git-send-email-michele.digiorgio@arm.com> X-Mailer: git-send-email 1.9.1 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Bang-bang thermal governor uses trip point hysteresis to make decisions. Hysteresis is a required property in the device tree for trip points, but it is an optional thermal zone device operation. Hence, we need to check whether the function pointer is valid or not. If it is not available, we assume the hysteresis to be zero. Consequently, a highly varying temperature will make the governor continuosly switch a cooling device ON and OFF. CC: Zhang Rui CC: Eduardo Valentin CC: Peter Feuerer Signed-off-by: Michele Di Giorgio --- Using trip_hyst == 0 makes the governor work sensibly but may cause oscillations of the control signals of a cooling device. An alternative to this could be to fail the registration of the thermal governor. Another way would be to set the default value of the hysteresis to x% of the trip temperature, to make the governor less sensitive to highly varying inputs. drivers/thermal/gov_bang_bang.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/thermal/gov_bang_bang.c b/drivers/thermal/gov_bang_bang.c index 39d1519..bb118a1 100644 --- a/drivers/thermal/gov_bang_bang.c +++ b/drivers/thermal/gov_bang_bang.c @@ -29,7 +29,13 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) struct thermal_instance *instance; tz->ops->get_trip_temp(tz, trip, &trip_temp); - tz->ops->get_trip_hyst(tz, trip, &trip_hyst); + + if (!tz->ops->get_trip_hyst) { + pr_warn_once("Undefined get_trip_hyst for thermal zone %s - " + "running with default hysteresis zero\n", tz->type); + trip_hyst = 0; + } else + tz->ops->get_trip_hyst(tz, trip, &trip_hyst); dev_dbg(&tz->device, "Trip%d[temp=%d]:temp=%d:hyst=%d\n", trip, trip_temp, tz->temperature,