From patchwork Mon Dec 7 19:05:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 339174 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp3064215jai; Mon, 7 Dec 2020 11:07:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxfJCzXHPqkwQmC1M4Gg35pIH2sCWI2hvFqDJbQGimV0QorkKOZwO1HTXW8F//RoHJ1pSPG X-Received: by 2002:a17:906:1752:: with SMTP id d18mr20552708eje.529.1607368050270; Mon, 07 Dec 2020 11:07:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607368050; cv=none; d=google.com; s=arc-20160816; b=fHgWkfEX0i/gMzkZNnmSYQ83DDGCCp6r+mQ668P36mit5kUoxWTNHEdb2qIEkGRl4m o3rhEEu1daugYeOG1IlaO7YjXqaeDavT5ksreURsDZxlGMDGJQyIqFupdKMXhXaia0D+ ui2EtApxzi2vhpG3OiqgKe9gGhJLjE31jsoaPEok3UUwhH/VC2T/4t3jkI95oEkqWMVE uhXT6xGegKSira4Uxooj/OG9EfHInrn4m0SAblwMG9DPE0h7o02x4CNTRqPBje+S2y/E e3CdfihLB0NzfQJQg64D+34cdEGFZc+V1xNKGyssHfPVJVafKyaWqbO4kC0udIoi36nM iR4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=UI14tg3SGBkYGbg6Pqk9K057841s9DbKHhwnpKgE5MI=; b=QZIbYrjz6mhPI2hRQGBU4/9ndhS2k8DLTmGfjdpeRix0g5bqvd1DfkSWeTRG+Pax8I tD+guVEB5/9vVyMeQeT7bjvTYq+cgz/CS7vcxiK0HAvSwvlvz58QvOCPl+BAkg9xg/8T mCDkRFVyiM4hhVM1zhG9hsA4IYBHDK2wI0CVtdRfa7KIfcfml7fy0SFeY7i61mS7fr2x snyoOl86OlDsGwGc92JNQEE2dXGI9PnW5W+rotyJJwCu99pCdzUCnpCwSWzJ+4C0JWs0 /ml5wTyaJ6kbH8/IsW/byunl/6Ccbkl+m+YUnH0T2rvOebRqMEA4nXFUElXqwtUskTOW yoYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pKx+MyG4; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q23si8877726edt.531.2020.12.07.11.07.30; Mon, 07 Dec 2020 11:07:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pKx+MyG4; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 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 S1726821AbgLGTGh (ORCPT + 8 others); Mon, 7 Dec 2020 14:06:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726788AbgLGTGg (ORCPT ); Mon, 7 Dec 2020 14:06:36 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DADDC06179C for ; Mon, 7 Dec 2020 11:05:56 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id a12so7043898wrv.8 for ; Mon, 07 Dec 2020 11:05:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=UI14tg3SGBkYGbg6Pqk9K057841s9DbKHhwnpKgE5MI=; b=pKx+MyG41dms/4j23nNZ3/iUylLDFBjR6zjZE8BchspCPgUCDWcLc90uB9rE36O+Ez aqf4pfnfMht4Yqb0boRP3IrxsjsESBQWS4bYeBWdE/R32M4YVuvue32iyiELLGguaFLj 4qTlZGeC2LMHE34f/F3/rH6KunfXyouDgDMtLLiiQMrrc+CAxUujKIaJDpwj1T1D0nbN 2ZfvWQmpLgTBbMiUbJAm/Vgexa9N4jWfjRqsGY5Zy+97OqkEaxkMtgJ7XLekrEL4d4eJ sCWizb1v4PT0IpMtWhLEBPulI9/VTu7UDTKykoyAzkbQuHyD7npY9LHg5FAs6tPJnDLA YLzA== 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; bh=UI14tg3SGBkYGbg6Pqk9K057841s9DbKHhwnpKgE5MI=; b=hIGTtTlIBATQryu9gyDZYsl+i+TIP6eWaT2B/ex+hBBmM+NgmOyehmcXyi7Uy/E+no eDJozEKKbhhz2dFH24V0Csc3d1YF58iyleRwB0VVVig9QA+qDVvGV6dxccvS/Z6pQOH0 E8ur32lvo3r/A5F2TiZA3V1KY1RiQ+FVVRRMmxeSBfmBodd8rE/k1Y2/4dQMOPfk045v NxGydrtLjZaKODEHd0sVzs6F6HPs+i8WzIyDLxtyEyrKDpAgDigwqUW4mPLtR1IBGVA9 jlxbXNK7St9tEOBLrYjLqH8ih/HKjOnZQzhOulJfD3LgjpW06z1OQpfUBqfpnT3SHcuL mHDA== X-Gm-Message-State: AOAM531j5spmyvX1pjzCpnsKuRlxhSSJHwtYlyw3j1LcKzR8+4ENh+i6 ERXOdbRVuhF3hKJLd2uf5l3zAg== X-Received: by 2002:a5d:634d:: with SMTP id b13mr21597532wrw.310.1607367954657; Mon, 07 Dec 2020 11:05:54 -0800 (PST) Received: from localhost.localdomain (lns-bzn-59-82-252-158-132.adsl.proxad.net. [82.252.158.132]) by smtp.gmail.com with ESMTPSA id e17sm6252886wrw.84.2020.12.07.11.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 11:05:53 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rui.zhang@intel.com Cc: Thara Gopinath , Amit Kucheria , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] thermal/core: Emit a warning if the thermal zone is updated without ops Date: Mon, 7 Dec 2020 20:05:30 +0100 Message-Id: <20201207190530.30334-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The actual code is silently ignoring a thermal zone update when a driver is requesting it without a get_temp ops set. That looks not correct, as the caller should not have called this function if the thermal zone is unable to read the temperature. That makes the code less robust as the check won't detect the driver is inconsistently using the thermal API and that does not help to improve the framework as these circumvolutions hide the problem at the source. In order to detect the situation when it happens, let's add a warning when the update is requested without the get_temp() ops set. Any warning emitted will have to be fixed at the source of the problem: the caller must not call thermal_zone_device_update if there is not get_temp callback set. As the check is done in thermal_zone_get_temperature() via the update_temperature() function, it is pointless to have the check and the WARN in the thermal_zone_device_update() function. Just remove the check and let the next call to raise the warning. Cc: Thara Gopinath Cc: Amit Kucheria Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Daniel Lezcano --- drivers/thermal/thermal_core.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 90e38cc199f4..1bd23ff2247b 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -448,17 +448,17 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) monitor_thermal_zone(tz); } -static void update_temperature(struct thermal_zone_device *tz) +static int update_temperature(struct thermal_zone_device *tz) { int temp, ret; ret = thermal_zone_get_temp(tz, &temp); if (ret) { if (ret != -EAGAIN) - dev_warn(&tz->device, - "failed to read out thermal zone (%d)\n", - ret); - return; + dev_warn_once(&tz->device, + "failed to read out thermal zone (%d)\n", + ret); + return ret; } mutex_lock(&tz->lock); @@ -469,6 +469,8 @@ static void update_temperature(struct thermal_zone_device *tz) trace_thermal_temperature(tz); thermal_genl_sampling_temp(tz->id, temp); + + return 0; } static void thermal_zone_device_init(struct thermal_zone_device *tz) @@ -553,11 +555,9 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, if (atomic_read(&in_suspend)) return; - if (!tz->ops->get_temp) + if (update_temperature(tz)) return; - update_temperature(tz); - thermal_zone_set_trips(tz); tz->notify_event = event;