From patchwork Fri Aug 5 14:57:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 595769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB776C25B08 for ; Fri, 5 Aug 2022 14:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240966AbiHEO6D (ORCPT ); Fri, 5 Aug 2022 10:58:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240985AbiHEO5s (ORCPT ); Fri, 5 Aug 2022 10:57:48 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0112606A2 for ; Fri, 5 Aug 2022 07:57:46 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id z12so3519675wrs.9 for ; Fri, 05 Aug 2022 07:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=IVRxvoFqwRQnZhAcHxHZbeumlslt03wT2RECT4OCZkw=; b=KG8t4thEXO1EAMM4g9SuMmBUNntB3ar5OMy7/FF6n6ke1vU1zR06HBoXeP/K50oyc9 uh+WhmRzqb/0lt+afKXlT7f++5+1IyrZV+GXCBaz677/7NEbtbgRgeTOzR5lZZGq+/Jl hjOOTNNyTLUpWuA0AEf9X6gqYbWcOgdNljsTcL8n7/vNNfS6TYe7GbNhXFbPpGo9BxU9 l/8B2TIYONsaGa9hM4O4of0hdWgmtf87dc3yF44cPywFRl/EXKNgdv/SP1d9/8wqSRoo /v6JCHKAkEG+O+TfkVl72kEu+WomU4JWt1Lpwfp4U6ERj1LOKxvj7xCVovl2sn7nbsYA DrBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=IVRxvoFqwRQnZhAcHxHZbeumlslt03wT2RECT4OCZkw=; b=oXChNd+jfZp7pzkCYZI7pFl6fdHNvofY8eCfKfS870zrK7KWjISv/WitJsEYxz3OCE rpU979SYN0ydZQYcCPYYO/V2iY+V7yV4nlm1euu5nAg/nhm8z92yurileDYhsAkql2+A cbIybhsVOObrXxOzEaGxItiC0wf70n60KOPJcDamdnnKoOBI3QvnU+XgkSGxnKkYJOxC KfT/vfJw9+NGqssfYHf9z7BuLWILXE60KLQ38SS4Ojrcy/mWvU8/gJ2zBF2CsQ1o0Qjx 5PWKTYPGLqMP84F08HcMrLU9eFKExB/2QcDu2Jniv2XPF7X2SX+iKi0nfDPLtGpTaMtg 2GIA== X-Gm-Message-State: ACgBeo3/6SltkqU7DtPLTbEPJbkfABCYfalUXhQNiMk7kCvzb6uV5oIB XZitenvPIrC/Rp1xaa9T3VY7fA== X-Google-Smtp-Source: AA6agR6hFCyfpTZi71oTguTbP9QzIkTPi3a8OyWcF0iGylWEyCSab7M7hW8AKmmjYCMECjxsUIVtTQ== X-Received: by 2002:a05:6000:235:b0:220:3a22:fe38 with SMTP id l21-20020a056000023500b002203a22fe38mr4647889wrz.419.1659711465256; Fri, 05 Aug 2022 07:57:45 -0700 (PDT) Received: from mai.box.freepro.com ([2a05:6e02:1041:c10:aef0:8606:da6b:79ef]) by smtp.gmail.com with ESMTPSA id y1-20020adfd081000000b0022159d92004sm3102448wrh.82.2022.08.05.07.57.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 07:57:44 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: rui.zhang@intel.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Amit Kucheria Subject: [PATCH v1 02/26] thermal/sysfs: Do not make get_trip_hyst optional Date: Fri, 5 Aug 2022 16:57:05 +0200 Message-Id: <20220805145729.2491611-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220805145729.2491611-1-daniel.lezcano@linaro.org> References: <20220805145729.2491611-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The get_trip_hyst() ops is optional. It results all around the thermal framework code a check against the ops pointer and different action adding more complexity and making the code less readable and understandable. A zero hysteresis value is perfectly valid, so instead of adding more circumvolutions in the code, create unconditionnaly the hysteresis and use the thermal_zone_get_trip() function which returns a zero hysteresis if the get_trip_hyst() is not defined. Signed-off-by: Daniel Lezcano --- drivers/thermal/thermal_sysfs.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 2b53927f3263..bc3337826ae2 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -420,23 +420,20 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) return -ENOMEM; } - if (tz->ops->get_trip_hyst) { - tz->trip_hyst_attrs = kcalloc(tz->num_trips, - sizeof(*tz->trip_hyst_attrs), - GFP_KERNEL); - if (!tz->trip_hyst_attrs) { - kfree(tz->trip_type_attrs); - kfree(tz->trip_temp_attrs); - return -ENOMEM; - } + tz->trip_hyst_attrs = kcalloc(tz->num_trips, + sizeof(*tz->trip_hyst_attrs), + GFP_KERNEL); + if (!tz->trip_hyst_attrs) { + kfree(tz->trip_type_attrs); + kfree(tz->trip_temp_attrs); + return -ENOMEM; } attrs = kcalloc(tz->num_trips * 3 + 1, sizeof(*attrs), GFP_KERNEL); if (!attrs) { kfree(tz->trip_type_attrs); kfree(tz->trip_temp_attrs); - if (tz->ops->get_trip_hyst) - kfree(tz->trip_hyst_attrs); + kfree(tz->trip_hyst_attrs); return -ENOMEM; } @@ -469,9 +466,6 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) } attrs[indx + tz->num_trips] = &tz->trip_temp_attrs[indx].attr.attr; - /* create Optional trip hyst attribute */ - if (!tz->ops->get_trip_hyst) - continue; snprintf(tz->trip_hyst_attrs[indx].name, THERMAL_NAME_LENGTH, "trip_point_%d_hyst", indx); @@ -508,8 +502,7 @@ static void destroy_trip_attrs(struct thermal_zone_device *tz) kfree(tz->trip_type_attrs); kfree(tz->trip_temp_attrs); - if (tz->ops->get_trip_hyst) - kfree(tz->trip_hyst_attrs); + kfree(tz->trip_hyst_attrs); kfree(tz->trips_attribute_group.attrs); }