Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2252184ybd; Mon, 24 Jun 2019 03:20:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwirXAPemk+Nd+txb/HMtc2IgXaSxW/ITrn+9hIjX6HX6ilGZ898aePZqnOSnmmPmXrGsNo X-Received: by 2002:a17:90a:1ae2:: with SMTP id p89mr1902064pjp.26.1561371623936; Mon, 24 Jun 2019 03:20:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561371623; cv=none; d=google.com; s=arc-20160816; b=qcCRJyu89UTQgQTl72pc4SPg5/zZfwYPQdOYkpKDVT5p2zupxJ6PN+8umKQqwKumpJ Egq4ssmVhaqh6ZWaF067JSoz6P7hhxh8cW3SZiwAg+y6SVlPRnx0Q/9PRiMKGoVbmOtz RXHJAf9oLlJfPI8La2DoRrzVAaJiIvEqv9LQv9BAFeOPdIsmglrsR6oLikcXdAIl9Z3C HRLd7NPf0/zIsRFn+p7pPsXJF8rCxOIB6ld7EgJda58lkzuD8s3rj3Vgn56VH5uFPKMK 1n7t6TKzp4ix0Vdy0rioM+VcBjUdZteMmdpetAER6cBzPPe2CXEXzq32TX6do+Osnw4Y R9gg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wyjf/7KsiL902wMVYXdpHjATy4hFhxrIac0I6DNItu0=; b=tL8v/lXEFFG3JdeDayqX1fD0RECM8igXhfP+ERHKbkjsJMjmnX5FuWvdYua/gR9mAx 923G7mayGUHQByhScCEzFA8fOFf552n2mjPGC45RDyDCz76f014wM+Z6uOiIpPfd9EFd AMkEGlnF8KBZieNTr6WSq/mT/FPwoNWoafMPaoDzA4Rh6ArOCaMClG5ImOTSBMEznGj8 VF+5mX1BCf3EY3La4GToLwGNqHyQZ93YJ1eiEmeaicL+taHRdrMHdt7+6L3ck8M7uMpy lny1IQp+gum2gphJJju8xjTWv4Uprlz/iC8bQAwzJBAV1tO7z6qpYqIM93Fe2fzXYFMA 162A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gjHDuDS5; 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 t2si9211185pgp.343.2019.06.24.03.20.08; Mon, 24 Jun 2019 03:20:23 -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=@kernel.org header.s=default header.b=gjHDuDS5; 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 S1729239AbfFXKST (ORCPT + 99 others); Mon, 24 Jun 2019 06:18:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:53958 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729770AbfFXKQ1 (ORCPT ); Mon, 24 Jun 2019 06:16:27 -0400 Received: from localhost (f4.8f.5177.ip4.static.sl-reverse.com [119.81.143.244]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CF272208E3; Mon, 24 Jun 2019 10:16:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561371387; bh=ZWzPHxVYO6d7ILI+35xWNGfP9V6kWW0cbdaUNlzXlDU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gjHDuDS5q969CBYr7xVYm6kH6H3AKJQC1ehb8wq3Gi2hejFNlppgwQWS1cuMeM9wM DnDbXsOhCne9gVjLVxfg8veoSOPvBXWFZOAXhRuDo5UCtSOxMGx3hjCRl/D+aNivUh U2qpDBJl5avr5SUIuXfIpk/t8jclDDHp77rf6KF8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org, Eduardo Valentin , Sasha Levin Subject: [PATCH 5.1 085/121] hwmon: (core) add thermal sensors only if dev->of_node is present Date: Mon, 24 Jun 2019 17:56:57 +0800 Message-Id: <20190624092325.180202592@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624092320.652599624@linuxfoundation.org> References: <20190624092320.652599624@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit c41dd48e21fae3e55b3670ccf2eb562fc1f6a67d ] 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. Fixes: d560168b5d0f ("hwmon: (core) New hwmon registration API") Cc: Jean Delvare Cc: Guenter Roeck Cc: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- 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 c22dc1e07911..c38883f748a1 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -633,7 +633,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.20.1