Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2246030ybd; Mon, 24 Jun 2019 03:13:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqwf4QfNDaFB+4ngGDx2lnRW2Rl/WfOr4kqi/JvU/bytpY1agDhTlaXFfaCh5RKxM65lmJyi X-Received: by 2002:a17:90b:8d8:: with SMTP id ds24mr23558582pjb.135.1561371234930; Mon, 24 Jun 2019 03:13:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561371234; cv=none; d=google.com; s=arc-20160816; b=lyosxyh7jZsdijRSvPx0vfJ9BC+rtjIiaNtqz+oWoVvL6iC6UmaYRuUX8GMhX5c3ye WIlFM0ay0WaiPeKdlGYiHnlnNQS8gpNTbinL+xYGP5YmO7aHsCdAekxkI2YcIW8zw1I/ GDX+w1ai/+pv0ceUpnRaLZTXGupwD2rNNPTOdCmBeYbSt4SxJPHTPsWlSGGoAygrsBbR W2ntnUkfH2+Om9Xk+kLQOPSRx5g4iI+1u6488kiSeQIfJRBW6zFoDGq/nSgsEqUdKpyE mWE4Z4a9q4S7+pxJvHOg/x7wHDslHy6BeAAIwLNwpkfXwJ2xYft/8fnmYyD+ZxDVo67l WdPg== 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=bhs7MT5pG7HAINoP0t+u9iTFXVpDuYMEGHZpqJBCpTw=; b=oTMAirCCgyNqAx69UEP24bDzk6Jp7mMOdlkkV8D/inaBvlEh2Qyg8R+by8+EKJee07 rdUP1DDBRjPti+cDJj1vCZExECFzsZxzIABBWleYQ9kdYHR2zzU/+M5u4d+t6wM8Dycu VCuBOltfbfUnBbFn5ZoA0arJzAqLNfM3UNJjeoR2hqJwGoMhDp062kKh0U7A4Gob0NKA jPjNrZZfscBJYfkFhIdVWfsSVjQKaGCEOzQ8pc4/ZSbLRxTvg/gfNPdR2Zb6Fv4QcMty yenVO1lkuHGsxKE9OS7HzvGlCWIezzFVe9bXRQouARkqYyb9U3ClUPrFg+02Wr8v3y7D dw7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ySkq3WfM; 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 f16si9836759plr.340.2019.06.24.03.13.39; Mon, 24 Jun 2019 03:13:54 -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=ySkq3WfM; 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 S1729903AbfFXKFV (ORCPT + 99 others); Mon, 24 Jun 2019 06:05:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:37084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729791AbfFXKFM (ORCPT ); Mon, 24 Jun 2019 06:05:12 -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 33540205ED; Mon, 24 Jun 2019 10:05:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561370711; bh=HTLPW14FV82/Pk42KIxwqTEOtpQcj/hntKth0Q7kJOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ySkq3WfM9MuU1Grv8u8HZHDV4AjlY39Lm20iFKDJHGjhlOtOM9eZChi/FBD67auWR aDV60dPHIKQt8/2fc/fOlb3KNIrn1SjZje/mnc9Z3EpFFZeWEkt77tEVZoBHpde9iJ XjXsaqDTdb1FqQwjad6dBRY/12v/F9mJLhyjacvI= 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 4.19 64/90] hwmon: (core) add thermal sensors only if dev->of_node is present Date: Mon, 24 Jun 2019 17:56:54 +0800 Message-Id: <20190624092318.284925383@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624092313.788773607@linuxfoundation.org> References: <20190624092313.788773607@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 fcdbac4a56e3..6b3559f58b67 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -619,7 +619,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