Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp216755ybi; Wed, 29 May 2019 19:58:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqz74KFpWEUu+BmWfqjVO3GCdcB8cBZvg+Xh0BTze01cPAn9nIqzkys/lrj4HpIO+dHImnUZ X-Received: by 2002:aa7:9e51:: with SMTP id z17mr1346814pfq.212.1559185086088; Wed, 29 May 2019 19:58:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559185086; cv=none; d=google.com; s=arc-20160816; b=XUAuKS3EPrB2yD156eUQLADIvPyu4AqLQuOFi/a+NgJc1jKPb6XsiHwY7CWSpl+vK7 99oQnVWEiLwkHaZkkEl8arUqlBlNEt4S11Mw6Jnk0ymtm7MKbvNesO2GqLWCsiNx3uMm kMbLCjqXYnrlmFmlGjt6Ugbg1zGrccXbJvh1bJK+OhaP04XqZX91WzFUr3MomAZVmBdT LRFieznomL4rsV89Iwt8MI64ydXjhRr5Lr2NQ0NSiJ8B/2Mtmw0wHnrtcI5fVqZBEmm9 nUXJgVt2Zo58yCpBD8FbLOG6/04YqPqIAuQYyOOsf4MQbeXeIa6qdyCYy3lurhAqM8zN dTAQ== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Q0hg2IWCcaHXAkM88ceASeZAnofrWOY4R4oYb9tjtt8=; b=keg3PDK0p3vIBvsFuoCg9WoWj3w1PAS95trcd9IA5RiQlcWa2eiPNSQWd2Q0NLQPa2 u874JFDE4jXHwnYWkeWE9SGP6YMKmmUCN7Gjb+mPOKyLX+ldZk+7Pd0BR4NNBwlql8o1 9q7cv5IX+coVfW0QmsoQ6ASJtiq/c5VUpnexrg0x1uq+qkjrXSBD4b3M5ZpyeP0LzRB5 rFPGtzMUCMUYa4HRWvo2sVbr2I2FXeO6M5nS0F1v1FdSj/JUV9rQBGoit+a5etNctkpE 2cKc2TozOuxvuopQ32syBH+O9jkL1jUnOVP7vMT+XtVi5XjEbOZ8d98/y51PxLAPUshk Fwwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=bNBXxBWX; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d35si508847pla.134.2019.05.29.19.57.36; Wed, 29 May 2019 19:58:06 -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=pass header.i=@amazon.com header.s=amazon201209 header.b=bNBXxBWX; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727485AbfE3C4S (ORCPT + 99 others); Wed, 29 May 2019 22:56:18 -0400 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:2423 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727382AbfE3C4P (ORCPT ); Wed, 29 May 2019 22:56:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1559184975; x=1590720975; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Q0hg2IWCcaHXAkM88ceASeZAnofrWOY4R4oYb9tjtt8=; b=bNBXxBWXxvWn+aQBGZxVA2WN7UnD4XE9bu5YzBqHK693aRNFBgpmJh08 HGU/F5psfYM1EiRU3PMpxURbXlyCCv2dIGHdH+gGJ9Nty5RJQRpuUv3uL sfS2jyDuDZf1QVL42Iv3c+LcFEvAJQw4zDDwDUIzSo6LcWTo4KT0fU+QW 8=; X-IronPort-AV: E=Sophos;i="5.60,529,1549929600"; d="scan'208";a="768210709" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-8cc5d68b.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 30 May 2019 02:56:11 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-2b-8cc5d68b.us-west-2.amazon.com (Postfix) with ESMTPS id 43735A2153; Thu, 30 May 2019 02:56:11 +0000 (UTC) Received: from EX13D05UWB003.ant.amazon.com (10.43.161.26) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 30 May 2019 02:56:10 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D05UWB003.ant.amazon.com (10.43.161.26) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 30 May 2019 02:56:10 +0000 Received: from localhost (10.94.220.85) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 30 May 2019 02:56:10 +0000 From: Eduardo Valentin To: Guenter Roeck CC: Eduardo Valentin , Jean Delvare , , Subject: [PATCHv2 1/2] hwmon: core: add thermal sensors only if dev->of_node is present Date: Wed, 29 May 2019 19:56:04 -0700 Message-ID: <20190530025605.3698-2-eduval@amazon.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530025605.3698-1-eduval@amazon.com> References: <20190530025605.3698-1-eduval@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Drivers may register to hwmon and request for also registering with the thermal subsystem (HWMON_C_REGISTER_TZ). However, some of these driver, e.g. marvell phy, may be probed from Device Tree or being dynamically allocated, and in the later case, it will not have a dev->of_node entry. Registering with hwmon without the dev->of_node may result in different outcomes depending on the device tree, which may be a bit misleading. If the device tree blob has no 'thermal-zones' node, the *hwmon_device_register*() family functions are going to gracefully succeed, because of-thermal, *thermal_zone_of_sensor_register() return -ENODEV in this case, and the hwmon error path handles this error code as success to cover for the case where CONFIG_THERMAL_OF is not set. However, if the device tree blob has the 'thermal-zones' entry, the *hwmon_device_register*() will always fail on callers with no dev->of_node, propagating -EINVAL. If dev->of_node is not present, calling of-thermal does not make sense. For this reason, this patch checks first if the device has a of_node before going over the process of registering with the thermal subsystem of-thermal interface. And in this case, when a caller of *hwmon_device_register*() with HWMON_C_REGISTER_TZ and no dev->of_node will still register with hwmon, but not with the thermal subsystem. If all the hwmon part bits are in place, the registration will succeed. Cc: Jean Delvare Cc: Guenter Roeck Cc: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- V1->V2: no change drivers/hwmon/hwmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index e694c46ff039..429784edd5ff 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -636,7 +636,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata, if (err) goto free_hwmon; - if (dev && chip && chip->ops->read && + if (dev && dev->of_node && chip && chip->ops->read && chip->info[0]->type == hwmon_chip && (chip->info[0]->config[0] & HWMON_C_REGISTER_TZ)) { const struct hwmon_channel_info **info = chip->info; -- 2.21.0