Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp651552pxb; Tue, 2 Feb 2021 14:24:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJza1/qexjVbcjljBLRc6JuMvBZVW1B8xXW3RGlFP0yoXgbt78j2FraRphcvURtByLtfkYPn X-Received: by 2002:a17:906:6087:: with SMTP id t7mr189326ejj.90.1612304640193; Tue, 02 Feb 2021 14:24:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612304640; cv=none; d=google.com; s=arc-20160816; b=zgIeVH8D5LoPAEaQ4i3d+kAuJ26lFpuEUjKAbEBmrYtVI2B0DxWJ0WQlS/Pacm/uyD w3UPuaRF4K2xVV4Ly2fdElMGTM8WETRIG0yJ7pt6VurcFIxhnIpNUUPJMyqDqPsDOjwj c4SO5FIHtrnF4T9j2hjkYlAxrxXBejRF2gKfygsfwvGkIjtY2Ih0LYh9XPzZzsv8qa+a 04f/N2goXaeH33c0BUhcvh7qONjyhvSsd2Lc5LQEv1zhvZyKB1erY9apIRDdKatwBUVo UYrgJra4Jh2UcDaSlLp47Yzx6x0UdaESAV1Ob6IScH6fWFXmHrmBDnZ84Q2ilIIyrP/7 jKoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=pORWpRoFg2wL8KyEPiqOKXeNG+sTRTapVOtRN9jW5dk=; b=QsYsyL9blNsCd8XH5mmDBwQM7PPRVLo53h9LCkILb4esnNseObkjteDHCaSNXNKKoE JGN4U7Cu1Id20/4IMSIjpFuLSjGQ1dAJ+XUUYu3+X/Q3dy+hB8GVa+X9R9/HHwWlJITE EDdCqyi0ADjCKFrTIfTfgDYRcEK3plXtBA7+R4gWw9fLTlOvQIC5Ziht+FObxYcodDLe 2mDHhyoAHYiuTs/GXzk1LGlt/VZF8YJ2VrW0MgJf3RpBo3/R1DdSRw5Qr/d653cI//4F q+LNn5WbcrmP+OuGbleoyIJYnx+j7zQ35uSYmKLmXsgLHm63uQbHWxTlsYT71Zw7wUYp kV3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=msu.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f19si125609ejb.315.2021.02.02.14.23.34; Tue, 02 Feb 2021 14:24:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=msu.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234359AbhBBO1q (ORCPT + 99 others); Tue, 2 Feb 2021 09:27:46 -0500 Received: from lnfm1.sai.msu.ru ([93.180.26.255]:34648 "EHLO lnfm1.sai.msu.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234480AbhBBO0e (ORCPT ); Tue, 2 Feb 2021 09:26:34 -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 112ELltP002147; Tue, 2 Feb 2021 17:21:52 +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 69EC3BE19; Tue, 2 Feb 2021 17:21:48 +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 v2] hwmon: lm75: Handle broken device nodes gracefully Date: Tue, 2 Feb 2021 17:21:12 +0300 Message-Id: <20210202142113.5456-1-matwey@sai.msu.ru> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210130101038.26331-1-matwey@sai.msu.ru> References: <20210130101038.26331-1-matwey@sai.msu.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 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 --- drivers/hwmon/lm75.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index e447febd121a..130ad5042107 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -561,9 +561,15 @@ 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, -- 2.26.2