Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3547406yba; Sat, 11 May 2019 13:23:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxVY8OZsyV2qIUla7DUAgC0lHozszD5o2+t6JdLeZN1K0jfEye+i9Rthva2YydnsiLdvRhL X-Received: by 2002:a65:4b88:: with SMTP id t8mr22593330pgq.374.1557606214296; Sat, 11 May 2019 13:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557606214; cv=none; d=google.com; s=arc-20160816; b=bZF/NyM4WpKCnVWdVpYWhJ8wYHDhVgQc6SSjiG7qPXYoMAMrqKKjDxzHW8jPxeYQMa IS/shRGC0O3PyRBxrVkXS21iWOXLVvQY9PCOUwpP9yU/c2o5LvPTO4uGwz5W+Mp+Eo3x OdEznETTv3DE2W18DH2pQ2y++4cx/p9KzjYlMgRbL/121fAq5SalY/Mo4bNCbciWAQUI HwtNqaMT9TuAoeRg8ARJPC3Ma0nCQIsSo+lgT53iLmXyaCHW8VBF6Ld/ReqwK+adaySQ hAECx28HX7r1DQCD+D+W00wLtyPjkJspD2ERSKGIovlTPrDaduWAO+1lUt3RJ6k1wXzh e8SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=rLgXhVsDP/RzKSE+JdEI3qNT7K7MffBqtup5zZ8tHdc=; b=ipkJzoE6AZOmS0eeDkOIhJ1flMP2fwC/RL0MgQtgVvzdCl7/RCInWOHpWfBbQLLFyi fDzRtDoYOJLjgRys1RViZRfKKmYhGyaeJqNSmNI0g64X+j2MPrZuwekpQ3HjolWS+J5I Uf7qrXslZPotFTZMjWuN+2e9/GuP4Vb6XFpUwGvRRQc+RVpNFJbrDdJwik0UNeYJbYme 4jSVAohx6LVnz0vxKUdJRAT5Ub3DQ8rXpMwleZLSt8kXTGos1c5pU6YIk3tfx1X5gXj7 Ip2KzWZXcfUfITozXRiFF1AECTsLlTljcmctvMFy29tKqU/uv4Pf5WrTH3hCHL7mB3Eu 6owA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=aM7dbPPs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w126si13491165pfb.196.2019.05.11.13.23.16; Sat, 11 May 2019 13:23:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=aM7dbPPs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726233AbfEKUWZ (ORCPT + 99 others); Sat, 11 May 2019 16:22:25 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:36386 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725911AbfEKUWZ (ORCPT ); Sat, 11 May 2019 16:22:25 -0400 Received: by mail-pf1-f196.google.com with SMTP id v80so5029672pfa.3; Sat, 11 May 2019 13:22:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=rLgXhVsDP/RzKSE+JdEI3qNT7K7MffBqtup5zZ8tHdc=; b=aM7dbPPsnspFks6phirtx9698Y0IsGto7C9UDT80WCowD101CpiPlyueVSOOSS4CfY rdUXmIGf4U5p2oHyI40ORwkVJPk6jMXUTME3sGn3ON5ZQ+XFLYiVN+Eu/fi6/9uZvkj5 zRXR0e0BIzU6PM4HHEoI9hzRCtbvzL2zjiChylaRXSgxQw0UUV9NEL0sT1Ni0VDzhobJ BDqJEqRykfDS+779cLnXsMw+PlrBrlnoS7Ky8uYGGxYLiZNAtOfz2pMnhxNYIcuuAilI PQ+w3eqQj1Ju11J8TzECeV+wFqWMtZNpKrJ5OyEZHqZkmn3Zg70vXcdBYXtIItkdSiHv kJ3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=rLgXhVsDP/RzKSE+JdEI3qNT7K7MffBqtup5zZ8tHdc=; b=AvwmIQAvqFlXEyyGIOwzYVR85k57i2URi1/62y0H5FhadpBp4dVtdje1yS9Pyn2xao dVwrBGRd0pJFPFqSk1vYt6DXY2IzjuVia5L6ogM4ApMmM4z1jtbkOGkH9JceiJ15Im8Y c1pXyY6aViS2OXWEJeuRKARHW26PiHSZydjTTryw4ZAShiLrzRNXtTOILEISqgHL0h4w /V8jC2RfsPViO8rImFk/3M39kF/8Suaxzd2EbcgDAIGZMlgbBPgNBdUvS06PTUuuVgTM jwFVKEJPBOlU/hv+LgLf2Kao1ifCOD4y878bCW/eWC1STlIxuZJSLaHxP5QoD7OcbUhL 9Q7Q== X-Gm-Message-State: APjAAAXLEz5fCfX5Egk0f46knCVobNQyNwulEbyYwMW6BWWgfzbqcDjz +5ftafxDJ+zCDAo0TP5jEJQ= X-Received: by 2002:a65:6658:: with SMTP id z24mr22907719pgv.323.1557606144344; Sat, 11 May 2019 13:22:24 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id c23sm22145201pfp.0.2019.05.11.13.22.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 May 2019 13:22:22 -0700 (PDT) Subject: Re: [PATCH 1/6] thermal: Introduce devm_thermal_of_cooling_device_register To: Eduardo Valentin Cc: linux-hwmon@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, linux-pm@vger.kernel.org, Jean Delvare , Joel Stanley , Andrew Jeffery , Avi Fishman , Tomer Maimon , Tali Perry , Patrick Venture , Nancy Yuen , Benjamin Fair , Kamil Debski , Bartlomiej Zolnierkiewicz , Zhang Rui , Daniel Lezcano References: <1555617500-10862-1-git-send-email-linux@roeck-us.net> <1555617500-10862-2-git-send-email-linux@roeck-us.net> <20190511190415.GA22816@localhost.localdomain> From: Guenter Roeck Message-ID: <4be54a9c-ccc9-5489-6938-c66229d361b3@roeck-us.net> Date: Sat, 11 May 2019 13:22:19 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190511190415.GA22816@localhost.localdomain> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Eduardo, On 5/11/19 12:04 PM, Eduardo Valentin wrote: > Hello Guenter, > > On Thu, Apr 18, 2019 at 12:58:15PM -0700, Guenter Roeck wrote: >> thermal_of_cooling_device_register() and thermal_cooling_device_register() >> are typically called from driver probe functions, and >> thermal_cooling_device_unregister() is called from remove functions. This >> makes both a perfect candidate for device managed functions. >> >> Introduce devm_thermal_of_cooling_device_register(). This function can >> also be used to replace thermal_cooling_device_register() by passing a NULL >> pointer as device node. The new function requires both struct device * >> and struct device_node * as parameters since the struct device_node * >> parameter is not always identical to dev->of_node. >> >> Don't introduce a device managed remove function since it is not needed >> at this point. > > I don't have any objection on adding this API. Only a minor thing below: > > >> >> Signed-off-by: Guenter Roeck >> --- >> drivers/thermal/thermal_core.c | 49 ++++++++++++++++++++++++++++++++++++++++++ >> include/linux/thermal.h | 5 +++++ >> 2 files changed, 54 insertions(+) >> >> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c >> index 6590bb5cb688..e0b530603db6 100644 >> --- a/drivers/thermal/thermal_core.c >> +++ b/drivers/thermal/thermal_core.c >> @@ -1046,6 +1046,55 @@ thermal_of_cooling_device_register(struct device_node *np, >> } >> EXPORT_SYMBOL_GPL(thermal_of_cooling_device_register); >> >> +static void thermal_cooling_device_release(struct device *dev, void *res) >> +{ >> + thermal_cooling_device_unregister( >> + *(struct thermal_cooling_device **)res); >> +} >> + >> +/** >> + * devm_thermal_of_cooling_device_register() - register an OF thermal cooling >> + * device >> + * @dev: a valid struct device pointer of a sensor device. >> + * @np: a pointer to a device tree node. >> + * @type: the thermal cooling device type. >> + * @devdata: device private data. >> + * @ops: standard thermal cooling devices callbacks. >> + * >> + * This function will register a cooling device with device tree node reference. >> + * This interface function adds a new thermal cooling device (fan/processor/...) >> + * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself >> + * to all the thermal zone devices registered at the same time. >> + * >> + * Return: a pointer to the created struct thermal_cooling_device or an >> + * ERR_PTR. Caller must check return value with IS_ERR*() helpers. >> + */ >> +struct thermal_cooling_device * >> +devm_thermal_of_cooling_device_register(struct device *dev, >> + struct device_node *np, >> + char *type, void *devdata, >> + const struct thermal_cooling_device_ops *ops) >> +{ >> + struct thermal_cooling_device **ptr, *tcd; >> + >> + ptr = devres_alloc(thermal_cooling_device_release, sizeof(*ptr), >> + GFP_KERNEL); >> + if (!ptr) >> + return ERR_PTR(-ENOMEM); >> + >> + tcd = __thermal_cooling_device_register(np, type, devdata, ops); >> + if (IS_ERR(tcd)) { >> + devres_free(ptr); >> + return tcd; >> + } >> + >> + *ptr = tcd; >> + devres_add(dev, ptr); >> + >> + return tcd; >> +} >> +EXPORT_SYMBOL_GPL(devm_thermal_of_cooling_device_register); >> + >> static void __unbind(struct thermal_zone_device *tz, int mask, >> struct thermal_cooling_device *cdev) >> { >> diff --git a/include/linux/thermal.h b/include/linux/thermal.h >> index 5f4705f46c2f..43cf4fdd71d4 100644 >> --- a/include/linux/thermal.h >> +++ b/include/linux/thermal.h >> @@ -447,6 +447,11 @@ struct thermal_cooling_device *thermal_cooling_device_register(char *, void *, >> struct thermal_cooling_device * >> thermal_of_cooling_device_register(struct device_node *np, char *, void *, >> const struct thermal_cooling_device_ops *); >> +struct thermal_cooling_device * >> +devm_thermal_of_cooling_device_register(struct device *dev, >> + struct device_node *np, >> + char *type, void *devdata, >> + const struct thermal_cooling_device_ops *ops); > > We need to stub this in case thermal is not selected. > Yes. Sorry, that completely slipped my mind. >> void thermal_cooling_device_unregister(struct thermal_cooling_device *); >> struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name); >> int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp); > > Something like: > > > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index 43cf4fd..9b1b365 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -508,6 +508,14 @@ static inline struct thermal_cooling_device * > thermal_of_cooling_device_register(struct device_node *np, > char *type, void *devdata, const struct thermal_cooling_device_ops *ops) > { return ERR_PTR(-ENODEV); } > +struct thermal_cooling_device * > +devm_thermal_of_cooling_device_register(struct device *dev, > + struct device_node *np, > + char *type, void *devdata, > + const struct thermal_cooling_device_ops *ops) > +{ > + return ERR_PTR(-ENODEV); > +} > static inline void thermal_cooling_device_unregister( > struct thermal_cooling_device *cdev) > { } > ~ > > > If you want I can amend this to your patch and apply it. > Please do. > Also, do you prefer me to collect only this patch and you would collect hwmon changes, > or are you ok if I collect all the series? > Please go ahead and collect the entire series. Thanks, Guenter