From nobody Sun Feb 8 15:46:55 2026 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 BDA3EC74A5B for ; Tue, 21 Mar 2023 06:03:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229484AbjCUGDQ (ORCPT ); Tue, 21 Mar 2023 02:03:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbjCUGDM (ORCPT ); Tue, 21 Mar 2023 02:03:12 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 744E730E92; Mon, 20 Mar 2023 23:03:10 -0700 (PDT) Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.77 with qID 32L62ZWm8014765, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36505.realtek.com.tw[172.21.6.25]) by rtits2.realtek.com.tw (8.15.2/2.81/5.90) with ESMTPS id 32L62ZWm8014765 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK); Tue, 21 Mar 2023 14:02:35 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXH36505.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.32; Tue, 21 Mar 2023 14:02:46 +0800 Received: from localhost (172.21.177.105) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Tue, 21 Mar 2023 14:02:45 +0800 From: Phinex Hung CC: , Jean Delvare , Guenter Roeck , , Subject: [PATCH v2] hwmon: fix potential sensor registration fail if of_node is missing Date: Tue, 21 Mar 2023 14:02:23 +0800 Message-ID: <20230321060224.3819-1-phinex@realtek.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230315121606.GA71707@threadripper> References: <20230315121606.GA71707@threadripper> MIME-Version: 1.0 X-Originating-IP: [172.21.177.105] X-ClientProxiedBy: RTEXH36505.realtek.com.tw (172.21.6.25) To RTEXMBS04.realtek.com.tw (172.21.6.97) X-KSE-ServerInfo: RTEXMBS04.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-ServerInfo: RTEXH36505.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It is not sufficient to check of_node in current device. In some cases, this would cause the sensor registration to fail. This patch looks for device's ancestors to find a valid of_node if any. Signed-off-by: Phinex Hung --- v2: assign of_node from its ancestor to support sensor registration --- drivers/hwmon/hwmon.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index 33edb5c02f7d..d193ed3cb35e 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -757,6 +757,7 @@ __hwmon_device_register(struct device *dev, const char = *name, void *drvdata, struct hwmon_device *hwdev; const char *label; struct device *hdev; + struct device *tdev =3D dev; int i, err, id; =20 /* Complain about invalid characters in hwmon name attribute */ @@ -826,7 +827,9 @@ __hwmon_device_register(struct device *dev, const char = *name, void *drvdata, hwdev->name =3D name; hdev->class =3D &hwmon_class; hdev->parent =3D dev; - hdev->of_node =3D dev ? dev->of_node : NULL; + while (tdev && !tdev->of_node) + tdev =3D tdev->parent; + hdev->of_node =3D tdev ? tdev->of_node : NULL; hwdev->chip =3D chip; dev_set_drvdata(hdev, drvdata); dev_set_name(hdev, HWMON_ID_FORMAT, id); @@ -838,7 +841,7 @@ __hwmon_device_register(struct device *dev, const char = *name, void *drvdata, =20 INIT_LIST_HEAD(&hwdev->tzdata); =20 - if (dev && dev->of_node && chip && chip->ops->read && + if (hdev->of_node && chip && chip->ops->read && chip->info[0]->type =3D=3D hwmon_chip && (chip->info[0]->config[0] & HWMON_C_REGISTER_TZ)) { err =3D hwmon_thermal_register_sensors(hdev); --=20 2.17.1