From patchwork Tue Feb 2 18:37:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matwey V. Kornilov" X-Patchwork-Id: 12062625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7CCDC433E6 for ; Tue, 2 Feb 2021 18:43:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5550B64F4B for ; Tue, 2 Feb 2021 18:43:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238890AbhBBSnr (ORCPT ); Tue, 2 Feb 2021 13:43:47 -0500 Received: from lnfm1.sai.msu.ru ([93.180.26.255]:38478 "EHLO lnfm1.sai.msu.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233738AbhBBSm0 (ORCPT ); Tue, 2 Feb 2021 13:42:26 -0500 Received: from dragon.sai.msu.ru (dragon.sai.msu.ru [93.180.26.172]) by lnfm1.sai.msu.ru (8.14.1/8.12.8) with ESMTP id 112IboMk011289; Tue, 2 Feb 2021 21:37:55 +0300 Received: from oak.local (unknown [83.167.113.121]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by dragon.sai.msu.ru (Postfix) with ESMTPSA id 28E9A18B18; Tue, 2 Feb 2021 21:37:52 +0300 (MSK) From: "Matwey V. Kornilov" To: Jean Delvare , Guenter Roeck , Javier Martinez Canillas , linux-hwmon@vger.kernel.org (open list:HARDWARE MONITORING), linux-kernel@vger.kernel.org (open list) Cc: matwey.kornilov@gmail.com, "Matwey V. Kornilov" , linux-hwmon@vger.kernel.org (open list:HARDWARE MONITORING), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3] hwmon: lm75: Handle broken device nodes gracefully Date: Tue, 2 Feb 2021 21:37:37 +0300 Message-Id: <20210202183737.28747-1-matwey@sai.msu.ru> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210202142113.5456-1-matwey@sai.msu.ru> References: <20210202142113.5456-1-matwey@sai.msu.ru> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org There is a logical flaw in lm75_probe() function introduced in commit e97a45f1b460 ("hwmon: (lm75) Add OF device ID table") Note, that of_device_get_match_data() returns NULL when no match is found. This is the case when OF node exists but has unknown compatible line, while the module is still loaded via i2c detection. arch/powerpc/boot/dts/fsl/p2041rdb.dts: lm75b@48 { compatible = "nxp,lm75a"; reg = <0x48>; }; In this case, the sensor is mistakenly considered as ADT75 variant. Fixes: e97a45f1b460 ("hwmon: (lm75) Add OF device ID table") Signed-off-by: Matwey V. Kornilov --- Changes since v2: * fixed typo in the message * fixed brackets drivers/hwmon/lm75.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index e447febd121a..53882c334a0d 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -561,10 +561,17 @@ static int lm75_probe(struct i2c_client *client) int status, err; enum lm75_type kind; - if (client->dev.of_node) - kind = (enum lm75_type)of_device_get_match_data(&client->dev); - else + if (dev->of_node) { + const struct of_device_id *match = + of_match_device(dev->driver->of_match_table, dev); + + if (!match) + return -ENODEV; + + kind = (enum lm75_type)(match->data); + } else { kind = i2c_match_id(lm75_ids, client)->driver_data; + } if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))