From patchwork Wed May 11 15:12:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12846352 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 4FD55C4321E for ; Wed, 11 May 2022 15:12:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245582AbiEKPMs (ORCPT ); Wed, 11 May 2022 11:12:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242600AbiEKPMh (ORCPT ); Wed, 11 May 2022 11:12:37 -0400 Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAFE260B83; Wed, 11 May 2022 08:12:36 -0700 (PDT) Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-ed9a75c453so3131409fac.11; Wed, 11 May 2022 08:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DUCwHnpEBZWvV+TfQ2kOF7vKh2668nns0uSQ/D4T0+w=; b=mpa3J5Vld3Dm5QiFIItHCDwdXGMZiJsoXZHFl7q/67GbnFhsG0ZNau9F9hjZigDGyb RSqxs+ef/bQI9XSDbDlHlM63Ls97iugjJMcDjj/y9yTAbId2j9m7K7ios4hgxCyjCGGn 4oqq2B+2CJ9dpKnOyPUW9k8saVXTy6k0RmShLZaMYHZqDh42na32W2H7rkGBK9lQX0UM rJ9cr5oPo6z3ILVQ0MQudj1VJnGaM4n6ZDYi56QA5K2pU00DdHE58ohOAkCRZKZRCp3B hG28i/Qmuejzx6fxa7sN4VCxp/R8a3joMPI9AWKgiSPyH33F8b+UrpSR97a9BIeGGMON uXMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=DUCwHnpEBZWvV+TfQ2kOF7vKh2668nns0uSQ/D4T0+w=; b=p724bCkneK6NHdoIcKbypF0rx/QO/d8fSAazjVoXF6p2hi0Bol0a5dd/ur1haFRt05 X/GIG0+ZTXst0P6gVt2ABquzkee+B4/bRJFO3t3iOyTO3aaUlbSTLO19rX1T4EXMstBh lh7xsdaoV3sXiaoubRbiHcx6JuFMn9B6YpEKEIp7XK66OrTqlNXigGNneXeGWgh6qaYL //RDy5ub9bTlt9zogE8DGjlY6uSpMgBUmVcHL36u1oZthm4dBjU3AC+J6krYztSiREs+ CKyEVcM3C0dOfF/3vZ63UMhK+OP4db57KNEIMl9c+y2MZJ99SE0ZfpLJ9zhbfEyY9Hjh 9KWQ== X-Gm-Message-State: AOAM532pHC8bb1pCnia/p2UfjRQGR6klg7UxXifJBQl42vjXMQbYFXki eWGuLMfyS421W5N50HButap3dtv1+Nc5Qg== X-Google-Smtp-Source: ABdhPJxEpONNgy/avRlEVwlFZ58TZazzcu2tObteJMDTfsTabiZm83KhSInAsCeabhGAf0p5TpZ32g== X-Received: by 2002:a05:6870:648d:b0:ec:b32d:3e1b with SMTP id cz13-20020a056870648d00b000ecb32d3e1bmr2954238oab.283.1652281956136; Wed, 11 May 2022 08:12:36 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 6-20020a4a0306000000b0035eb4e5a6d0sm984750ooi.38.2022.05.11.08.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 08:12:35 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: "Rafael J . Wysocki" Cc: Daniel Lezcano , Amit Kucheria , Zhang Rui , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Guenter Roeck Subject: [PATCH 1/3] hwmon: Introduce hwmon_device_register_for_thermal Date: Wed, 11 May 2022 08:12:28 -0700 Message-Id: <20220511151230.2983227-2-linux@roeck-us.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220511151230.2983227-1-linux@roeck-us.net> References: <20220511151230.2983227-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The thermal subsystem registers a hwmon driver without providing chip or sysfs group information. This is for legacy reasons and would be difficult to change. At the same time, we want to enforce that chip information is provided when registering a hwmon device using hwmon_device_register_with_info(). To enable this, introduce a special API for use only by the thermal subsystem. Signed-off-by: Guenter Roeck --- drivers/hwmon/hwmon.c | 25 +++++++++++++++++++++++++ include/linux/hwmon.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index 5915ccfdb7d9..13053a4edc9e 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -916,6 +916,31 @@ hwmon_device_register_with_info(struct device *dev, const char *name, } EXPORT_SYMBOL_GPL(hwmon_device_register_with_info); +/** + * hwmon_device_register_for_thermal - register hwmon device for thermal subsystem + * @dev: the parent device + * @name: hwmon name attribute + * @drvdata: driver data to attach to created device + * + * The use of this function is restricted. It is provided for legacy reasons + * and must only be called from the thermal subsystem. + * + * hwmon_device_unregister() must be called when the device is no + * longer needed. + * + * Returns the pointer to the new device. + */ +struct device * +hwmon_device_register_for_thermal(struct device *dev, const char *name, + void *drvdata) +{ + if (!name || !dev) + return ERR_PTR(-EINVAL); + + return __hwmon_device_register(dev, name, drvdata, NULL, NULL); +} +EXPORT_SYMBOL_NS_GPL(hwmon_device_register_for_thermal, HWMON_THERMAL); + /** * hwmon_device_register - register w/ hwmon * @dev: the device to register diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h index 4efaf06fd2b8..14325f93c6b2 100644 --- a/include/linux/hwmon.h +++ b/include/linux/hwmon.h @@ -450,6 +450,9 @@ hwmon_device_register_with_info(struct device *dev, const struct hwmon_chip_info *info, const struct attribute_group **extra_groups); struct device * +hwmon_device_register_for_thermal(struct device *dev, const char *name, + void *drvdata); +struct device * devm_hwmon_device_register_with_info(struct device *dev, const char *name, void *drvdata, const struct hwmon_chip_info *info, From patchwork Wed May 11 15:12:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12846351 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 39463C43217 for ; Wed, 11 May 2022 15:12:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245580AbiEKPMr (ORCPT ); Wed, 11 May 2022 11:12:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245548AbiEKPMj (ORCPT ); Wed, 11 May 2022 11:12:39 -0400 Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99E175F8D0; Wed, 11 May 2022 08:12:38 -0700 (PDT) Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-ed8a3962f8so3174698fac.4; Wed, 11 May 2022 08:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lWVV90oYpi4dWYDQ2mZpGM9vUZygMcQs9ZQl2WC1Reo=; b=YMSModPq/NltiVm3CaGLRZJ5MvAnSy6N4eoa4dSUqfmOSzFgoOKcm3D3NcjIxBM+jP WD6+i7dU4d5OIi48RAhaspZ2VRTheb6NdyVbmwYEk64kIb32KgqJQ2LMKaWPu904Sh/q vO8K7Z0pF0OyKhfBZBNETu03BttIXSUaaeKAgD0uZV3UZdjoK8Y5UrdxhW270e8hU4jj vIlte5TKL3UukZvAb5pfHIlzZ5hlU5nKurwMvldxNGaHMPx4taux94vLtsJUmO8Ore0o mZjsnNILOZF06oS7QRyk1NfO2wM6wO1UVfk3SsHGMs6LWNDklWAL75Nh6VUSP22jTYnx fESQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=lWVV90oYpi4dWYDQ2mZpGM9vUZygMcQs9ZQl2WC1Reo=; b=hIv9MUkxbrxkUKVGYxFRGJzBNVyXSl7PJNshegKLfH15mFPxZ6LC+KQ3FN05RopHKE i6FNR685Ego229EQuamaeQRhiK3F6zt7gxWo55iQO4v8hAP84bQFTDgPJd7fKadk5hKg 6pqqUgjcohMFwgfD4PjNe9hkY9YryYPgLp0tr8kcfIxo8xDsJAoK+pmfWoT6WHlDemiq pcSNCV216lvdnBE4xF692rBBU34/3uPuVXx0mmXiin3FiOPWD1yUxk6WG/yS4JfcT1WP jesneedC7Z47qVXB8+BBIEtyic/h08pOv0DuLVecUCSrrgwzDDItFrkehHk/BTVyI5Mo JOpw== X-Gm-Message-State: AOAM533JVcGtcVdlSK0WFmb+PTjkyM6QmMcoUbvaN5oNTPX+t29pARCk nkzriTG16NdQuU3qhUhkh9o= X-Google-Smtp-Source: ABdhPJyZtfT41OEAJN7SYN5skLyaan98nvwQQQ/N3h5pVIAPPFAsizBEODUCEvyMM005MmhHpQoHRg== X-Received: by 2002:a05:6870:2301:b0:e2:d57e:1c22 with SMTP id w1-20020a056870230100b000e2d57e1c22mr3067987oao.244.1652281957985; Wed, 11 May 2022 08:12:37 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id t13-20020a4adbcd000000b0035eb4e5a6b8sm1006421oou.14.2022.05.11.08.12.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 08:12:37 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: "Rafael J . Wysocki" Cc: Daniel Lezcano , Amit Kucheria , Zhang Rui , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Guenter Roeck Subject: [PATCH 2/3] thermal/drivers/thermal_hwmon: Use hwmon_device_register_for_thermal() Date: Wed, 11 May 2022 08:12:29 -0700 Message-Id: <20220511151230.2983227-3-linux@roeck-us.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220511151230.2983227-1-linux@roeck-us.net> References: <20220511151230.2983227-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The thermal subsystem registers a hwmon device without providing chip information or sysfs attribute groups. While undesirable, it would be difficult to change. On the other side, it abuses the hwmon_device_register_with_info API by not providing that information. Use new API specifically created for the thermal subsystem instead to let us enforce the 'chip' parameter for other callers of hwmon_device_register_with_info(). Signed-off-by: Guenter Roeck --- drivers/thermal/thermal_hwmon.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c index ad03262cca56..09e49ec8b6f4 100644 --- a/drivers/thermal/thermal_hwmon.c +++ b/drivers/thermal/thermal_hwmon.c @@ -149,8 +149,8 @@ int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) INIT_LIST_HEAD(&hwmon->tz_list); strlcpy(hwmon->type, tz->type, THERMAL_NAME_LENGTH); strreplace(hwmon->type, '-', '_'); - hwmon->device = hwmon_device_register_with_info(&tz->device, hwmon->type, - hwmon, NULL, NULL); + hwmon->device = hwmon_device_register_for_thermal(&tz->device, + hwmon->type, hwmon); if (IS_ERR(hwmon->device)) { result = PTR_ERR(hwmon->device); goto free_mem; @@ -277,3 +277,5 @@ int devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) return ret; } EXPORT_SYMBOL_GPL(devm_thermal_add_hwmon_sysfs); + +MODULE_IMPORT_NS(HWMON_THERMAL); From patchwork Wed May 11 15:12:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12846350 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 85D41C433EF for ; Wed, 11 May 2022 15:12:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245546AbiEKPMp (ORCPT ); Wed, 11 May 2022 11:12:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245534AbiEKPMl (ORCPT ); Wed, 11 May 2022 11:12:41 -0400 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CC819D06D; Wed, 11 May 2022 08:12:40 -0700 (PDT) Received: by mail-oi1-x233.google.com with SMTP id q8so3016109oif.13; Wed, 11 May 2022 08:12:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2JX+KNvsq9d1yikcsx1hZpdGq5xppixGCVbpyE6im6I=; b=kCGrRCJGNI+WeRLn77rZwlRWumPJr2+bP75SMWO0fNDZL16qg349h5SG2al9dBdry4 WRaLRx6hxSI0pWXjVJcCRMG6s2IEaRilbQN1UXR3ni0cCT3x7r+VMUMFyUVyupXcG7XM iKLUUZlmtLi0Fbn0Mr2IwCCFXhbDKLslZ/L7h78h2ybHEPp0ZHEK4Xc078GCRT40/Ktv p5eU3sIDwCSNB84IWL57LMwOSL9+FmVptp/YmRNNcrnqFQ9apiqCk1CmXxX/dcK65YiA z/tbjUHjz4CmTsLUjrk9N3K6IeAScYM6Kx6vfJuyvPKoV3prghhtfl+b+PQFNL417vkP h7KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=2JX+KNvsq9d1yikcsx1hZpdGq5xppixGCVbpyE6im6I=; b=NXx2NWtm8l34RE8+yy4jLZlcdUJKmEpbEZ0CqRep51ShZce+inxeKLCxDBpJFli4xE F09XYGaw9qWJ4/ZQjPm/+BGqTR0j30CWO22IZPPm83knp1K0qilLw4xIq6fNyOFW7weN ArWglLcQy2lw/8LEpVyJGFVIwpmGeKpzD6KCv4pdzzTzlE+D1UZA9khUPJ8gtRn/nZ/G E7Sh8G+Of2hzfWxH8rVFPedhFMZQJmxnboQMSyt+cz+Z3hh1aTjzP2N5udFbhEMeS8EE 8rFS0Qj84v7A/+wJF6gR391Dv9DBQqa5Hq/AX8HbS8eYg+uaqC47JTaTyH6Lx/x5BHjA gmUA== X-Gm-Message-State: AOAM531s1vxfODflYtP33h5cdIeCHSWg6yEELmqsXP7WBeF2gGQ7wZI5 i3PERDE9IRVTFZUlyfn0zGk= X-Google-Smtp-Source: ABdhPJz+eElEIyCPFZ77pMdbL315KuHzBSvEQ+BtjifhttYf8bNjDK2dbzTQRO81BzhIC6h3AfWGaA== X-Received: by 2002:a05:6808:1250:b0:2da:39df:1f92 with SMTP id o16-20020a056808125000b002da39df1f92mr2728045oiv.27.1652281959974; Wed, 11 May 2022 08:12:39 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id a17-20020a056870e0d100b000e932746d33sm710336oab.28.2022.05.11.08.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 08:12:39 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: "Rafael J . Wysocki" Cc: Daniel Lezcano , Amit Kucheria , Zhang Rui , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Guenter Roeck Subject: [PATCH 3/3] hwmon: Make chip parameter for with_info API mandatory Date: Wed, 11 May 2022 08:12:30 -0700 Message-Id: <20220511151230.2983227-4-linux@roeck-us.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220511151230.2983227-1-linux@roeck-us.net> References: <20220511151230.2983227-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Various attempts were made recently to "convert" the old hwmon_device_register() API to devm_hwmon_device_register_with_info() by just changing the function name without actually converting the driver. Prevent this from happening by making the 'chip' parameter of devm_hwmon_device_register_with_info() mandatory. Signed-off-by: Guenter Roeck --- Documentation/hwmon/hwmon-kernel-api.rst | 2 +- drivers/hwmon/hwmon.c | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Documentation/hwmon/hwmon-kernel-api.rst b/Documentation/hwmon/hwmon-kernel-api.rst index e2975d5caf34..f3276b3a381a 100644 --- a/Documentation/hwmon/hwmon-kernel-api.rst +++ b/Documentation/hwmon/hwmon-kernel-api.rst @@ -76,7 +76,7 @@ hwmon_device_register_with_info is the most comprehensive and preferred means to register a hardware monitoring device. It creates the standard sysfs attributes in the hardware monitoring core, letting the driver focus on reading from and writing to the chip instead of having to bother with sysfs attributes. -The parent device parameter cannot be NULL with non-NULL chip info. Its +The parent device parameter as well as the chip parameter must not be NULL. Its parameters are described in more detail below. devm_hwmon_device_register_with_info is similar to diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index 13053a4edc9e..22de7a9e7ba7 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -886,11 +886,12 @@ EXPORT_SYMBOL_GPL(hwmon_device_register_with_groups); /** * hwmon_device_register_with_info - register w/ hwmon - * @dev: the parent device - * @name: hwmon name attribute - * @drvdata: driver data to attach to created device - * @chip: pointer to hwmon chip information + * @dev: the parent device (mandatory) + * @name: hwmon name attribute (mandatory) + * @drvdata: driver data to attach to created device (optional) + * @chip: pointer to hwmon chip information (mandatory) * @extra_groups: pointer to list of additional non-standard attribute groups + * (optional) * * hwmon_device_unregister() must be called when the device is no * longer needed. @@ -903,13 +904,10 @@ hwmon_device_register_with_info(struct device *dev, const char *name, const struct hwmon_chip_info *chip, const struct attribute_group **extra_groups) { - if (!name) - return ERR_PTR(-EINVAL); - - if (chip && (!chip->ops || !chip->ops->is_visible || !chip->info)) + if (!dev || !name || !chip) return ERR_PTR(-EINVAL); - if (chip && !dev) + if (!chip->ops || !chip->ops->is_visible || !chip->info) return ERR_PTR(-EINVAL); return __hwmon_device_register(dev, name, drvdata, chip, extra_groups);