From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FC71C1B087 for ; Mon, 7 Dec 2020 19:07:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFB51238E5 for ; Mon, 7 Dec 2020 19:07:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726839AbgLGTGm (ORCPT ); Mon, 7 Dec 2020 14:06:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726636AbgLGTGm (ORCPT ); Mon, 7 Dec 2020 14:06:42 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 373B4C0617B0 for ; Mon, 7 Dec 2020 11:05:56 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id r7so2594592wrc.5 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=J7MEiQzKBduo07FgbZ8QNB4BvnQxy5Kzo7CT8wsDlH/M/vLElb3C0zuykjbL08P8ma E/xnEpvVmcMvXVnTKYx8jnGfdHRdjf183RS7b+HNhxZ95pEFMgGW3pJL2Wkg+pIAKQcT OtSak31oYIcPBAH4XXETSSdJ6NJ+nlBXbjGR2VmKi2LdFdbnLSijZ4mKL+rhWSWm0RWW UZvZIw/ejUKsCvmlMncH7VLHm51udaO46DZMMh0OUeOVQWYWsVwoPTJzLJkjKrpr2xXg 34hkV7gpRXowBN2/oTGCwt4AsiwIwAx+DRMggrC9g4pjo+JRpiSCgmoKdAOe+fhZUIsY d9YA== X-Gm-Message-State: AOAM531hhH0+FnJmvM/zKjC4belFyDzfqd9emGv9x46d0/XhHYiWA9oO rGTczYHfmYTPaur0ONhKTryKsg== X-Google-Smtp-Source: ABdhPJxHlboYN9ZsdYwuXvc9ho5FJzzeaFH+p3W6D13RLecafmX6lJtPJUz5zSyorCxNVdOaBSedOw== 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-kernel@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(-) 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; -- 2.17.1