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=-8.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 783CCC352BE for ; Tue, 14 Apr 2020 22:30:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C262206D5 for ; Tue, 14 Apr 2020 22:30:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="FEbTmIVN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391999AbgDNWan (ORCPT ); Tue, 14 Apr 2020 18:30:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2391989AbgDNWaf (ORCPT ); Tue, 14 Apr 2020 18:30:35 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24080C061A0F for ; Tue, 14 Apr 2020 15:30:35 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id x4so14946410wmj.1 for ; Tue, 14 Apr 2020 15:30:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=okVUGJ3ikrrEbdgJgp1xfbeReFhs19fwarQOs8B1AZk=; b=FEbTmIVNW0JoSjYjr3F58Dza+Cb1Ac/sA7nNj8BJjD5avga0CHKNryFlZnyWoMT1E2 na8aftYRyJNOnjaU94xdsOPIs71//+sqT+bELBHBZIbzI3nbi3kByYX15ybKGjV8hqN8 PxohgfpVVFNtgIAZ8+2c5mP0p6CodDxUFWMY4O2jSjXsEBQJo7J8DK9ftSUKzLWke7nn oAeGy3RkG0ySkJTzFv/BokwJwPVpqQYV+DSF2MSBBYwES8cAPcLFhiyABwkrSKDt1/Xd zIbH9mjT61r1ANGVDNH0HBZbSuIrs3gfbCaJ63UJPyZrYL+Xj0hS9iZs1617fg7qMyP9 Bgww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=okVUGJ3ikrrEbdgJgp1xfbeReFhs19fwarQOs8B1AZk=; b=ciuPqynCjTZYSLzKg9qxGY2d3x1XrtLaMowISz38vLuyJu9YswjrvrtpZLAD+NTXO3 vOXRhwVGiLR9p/U27AmSnFjzq4OfkjdRAI6rdAPqLsdsYH6zjAn7PEaeo/j0kDaXXQtZ pCeaRaiLs+Zt6o7sCSJkBgQhR2dSCUSA75eiYOo9Gi9c5XmJxk8rzOSL4TqbxrDaXd0D eKQoHppoUw2HDZCL5Hf1UqSVWZAUiP61HJ0WR45doRsc4Qx0LFQs1DtGMyz6SpDJ6x4k xIdpbbme0liKZn5OvNtTzfzZ0krDIiKqkMkEFKTakTXk0MRdLu2ABtgoa9RTVWCrckTe DNjg== X-Gm-Message-State: AGi0PuZp/7npTOootJDpIxDE82JCVQhLUu34y0kcEMFyItfLAuNtYu0V uE1K8YkQn1xzbEgrcrqxeuzg4A== X-Google-Smtp-Source: APiQypIbVYGNGOComyaA0BUnVsxnNYsocIyXxHF8/fexB9IRx/uxZhOitPNh1Qfq4Q5sjQ8E/NKUGA== X-Received: by 2002:a1c:bd08:: with SMTP id n8mr1947813wmf.23.1586903433566; Tue, 14 Apr 2020 15:30:33 -0700 (PDT) Received: from [192.168.0.41] (lns-bzn-59-82-252-135-148.adsl.proxad.net. [82.252.135.148]) by smtp.googlemail.com with ESMTPSA id g186sm21701352wmg.36.2020.04.14.15.30.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Apr 2020 15:30:33 -0700 (PDT) Subject: Re: [RFC v2 4/9] thermal: core: Let thermal zone device's mode be stored in its struct To: Andrzej Pietrasiewicz , linux-pm@vger.kernel.org Cc: Zhang Rui , "Rafael J . Wysocki" , Len Brown , Jiri Pirko , Ido Schimmel , "David S . Miller" , Peter Kaestle , Darren Hart , Andy Shevchenko , Support Opensource , Amit Kucheria , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Allison Randal , Enrico Weigelt , Gayatri Kammela , Thomas Gleixner , linux-acpi@vger.kernel.org, netdev@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@collabora.com References: <2bc5a902-acde-526a-11a5-2357d899916c@linaro.org> <20200414180105.20042-1-andrzej.p@collabora.com> <20200414180105.20042-5-andrzej.p@collabora.com> From: Daniel Lezcano Message-ID: Date: Wed, 15 Apr 2020 00:30:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200414180105.20042-5-andrzej.p@collabora.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org On 14/04/2020 20:01, Andrzej Pietrasiewicz wrote: > All the drivers which provide ->get_mode()/->set_mode() methods store their > mode in a thermal_device_mode enum, so keep this information in struct > thermal_zone_device rather than scattered all over the place. > > Signed-off-by: Andrzej Pietrasiewicz > --- > drivers/thermal/thermal_core.c | 28 +++++++++++++++++++ > drivers/thermal/thermal_sysfs.c | 9 +++---- > include/linux/thermal.h | 48 +++++++++++++++++++++++++++++++++ > 3 files changed, 79 insertions(+), 6 deletions(-) > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index 9a321dc548c8..cb0ff47f0dbe 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -469,6 +469,34 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) > thermal_zone_device_init(tz); > } > > +int thermal_zone_device_get_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode *mode) > +{ > + if (tz->ops->get_mode) > + return tz->ops->get_mode(tz, mode); I think we can get rid of the get_mode here. locks missing. and mode = tz->mode must be always set. > + *mode = tz->mode; > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(thermal_zone_device_get_mode); > + > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ > + if (mode != THERMAL_DEVICE_DISABLED && > + mode != THERMAL_DEVICE_ENABLED) > + return -EINVAL; I'm not sure this is useful as 'mode' is an enum and this condition will be always correct. locks missing. > + if (tz->ops->set_mode) > + return tz->ops->set_mode(tz, mode); > + tz->mode = mode; It should be like: int ret = 0; mutex_lock(&tz->lock); if (tz->ops->set_mode) ret = tz->ops->set_mode(tz, mode); *mode = tz->mode; mutex_unlock(&tz->lock); return ret; > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(thermal_zone_device_set_mode); > + > void thermal_zone_device_update(struct thermal_zone_device *tz, > enum thermal_notify_event event) > { > diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c > index aa99edb4dff7..66d9691b8bd6 100644 > --- a/drivers/thermal/thermal_sysfs.c > +++ b/drivers/thermal/thermal_sysfs.c > @@ -52,10 +52,7 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) > enum thermal_device_mode mode; > int result; > > - if (!tz->ops->get_mode) > - return -EPERM; > - > - result = tz->ops->get_mode(tz, &mode); > + result = thermal_zone_device_get_mode(tz, &mode); > if (result) > return result; > > @@ -74,9 +71,9 @@ mode_store(struct device *dev, struct device_attribute *attr, > return -EPERM; > > if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) > - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); > + result = thermal_zone_device_enable(tz); > else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) > - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); > + result = thermal_zone_device_disable(tz); > else > result = -EINVAL; > > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index c91b1e344d56..9ff8542b7e7d 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -143,6 +143,7 @@ struct thermal_attr { > * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature > * @trip_type_attrs: attributes for trip points for sysfs: trip type > * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis > + * @mode: current mode of this thermal zone > * @devdata: private pointer for device private data > * @trips: number of trip points the thermal zone supports > * @trips_disabled; bitmap for disabled trips > @@ -185,6 +186,7 @@ struct thermal_zone_device { > struct thermal_attr *trip_temp_attrs; > struct thermal_attr *trip_type_attrs; > struct thermal_attr *trip_hyst_attrs; > + enum thermal_device_mode mode; > void *devdata; > int trips; > unsigned long trips_disabled; /* bitmap for disabled trips */ > @@ -437,6 +439,19 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, > unsigned int); > int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, > struct thermal_cooling_device *); > + > +int thermal_zone_device_get_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode *mode); > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode); > + > +static inline void > +thermal_zone_device_store_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ > + tz->mode = mode; > +} > + Please remove this store_mode function, it is not needed. Just: thermal_zone_device_get_mode() thermal_zone_device_set_mode() thermal_zone_device_disable() thermal_zone_device_enable() And all of them in drivers/thermal/thermal_core.h > void thermal_zone_device_update(struct thermal_zone_device *, > enum thermal_notify_event); > void thermal_zone_set_trips(struct thermal_zone_device *); > @@ -494,6 +509,17 @@ static inline int thermal_zone_unbind_cooling_device( > struct thermal_zone_device *tz, int trip, > struct thermal_cooling_device *cdev) > { return -ENODEV; } > +static inline int thermal_zone_device_get_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode *mode) > +{ return -ENODEV; } > +static inline int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ return -ENODEV; } > +static inline void > +thermal_zone_device_store_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ } > + > static inline void thermal_zone_device_update(struct thermal_zone_device *tz, > enum thermal_notify_event event) > { } > @@ -543,4 +569,26 @@ static inline void thermal_notify_framework(struct thermal_zone_device *tz, > { } > #endif /* CONFIG_THERMAL */ > > +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); > +} > + > +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); > +} > + > +static inline void > +thermal_zone_device_store_enabled(struct thermal_zone_device *tz) > +{ > + thermal_zone_device_store_mode(tz, THERMAL_DEVICE_ENABLED); > +} > + > +static inline void > +thermal_zone_device_store_disabled(struct thermal_zone_device *tz) > +{ > + thermal_zone_device_store_mode(tz, THERMAL_DEVICE_DISABLED); > +} > + > #endif /* __THERMAL_H__ */ > -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog