Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2603792pxb; Sat, 6 Feb 2021 01:57:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxSs13/it1A/xn0VcTJqXYvploI4TBY9j8e7rtRinpUEDxnBiSW1JCQftWBMiXQXuA5En4X X-Received: by 2002:aa7:d1da:: with SMTP id g26mr7589753edp.154.1612605476694; Sat, 06 Feb 2021 01:57:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612605476; cv=none; d=google.com; s=arc-20160816; b=WHsLfWmiOV2VcmvJVhuUPPQdvwAR+h/fP+YVLn3c5mF9OX1MkR8CPIuX9npMOsjnLY rnOHeKt9/U3PakxmzC/M1S6sZfLUk69oIn2mPEri1oG2cSy34ZuZNpOauf+++R9qubDs kAu77BZjsWv8avX4DLZiLoSFyK1cByonFe8gbsjzXtT1j8w+JP+9zJ1neepemGrPtwt7 TlA2jgnOVt70TMv/r50h5koWbA2KIkC2GuqpKyAFiemUW8Pe7m15aL/9opOPh/8gJm+K I+CEa+y92ytaw8wJpjAGOjPCbj8wuwYv07b79mn2V7SsrmCjnbLM132CcOEWqmOM9BGM J5qQ== 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=R0zg0oCxFw0yOXGAVUcEnxTdYAzHf8GWbonFcvNdFSY=; b=vrySV5QtBhlIry4KDgmKOMwYxKuCkh963jeI5kXds0WCxYsF1aAceHxyQG0RqadAq/ L2VyaWszbhhtU4ZrsBqqBaXAYVVayF2fgMSlFBB5f2QgklLdvP70dHLDZqCoLtgA3Rkj cQ8HC/hi5I5Hlph2MS0pKM4ISQn7moF4C0Kj4Hout+s1pXXj/Ye22vSONNrTTlLwlT8K XTpOKYDCU6r6d4yVi2E8QYJQD5nr+TajVwtuT/z85Gy0nRM5vEftCKFwAlcZHZezcfBJ aRMDBoyMKB0JjQy0n0nnET7lV0bt+XAoGWyYnvKhbQhpLomXCCiWftv2KwAz6sqUXEXN tzcw== 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 jz7si4058532ejb.476.2021.02.06.01.57.32; Sat, 06 Feb 2021 01:57:56 -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 S229566AbhBFJ4J (ORCPT + 99 others); Sat, 6 Feb 2021 04:56:09 -0500 Received: from lnfm1.sai.msu.ru ([93.180.26.255]:39770 "EHLO lnfm1.sai.msu.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbhBFJ4H (ORCPT ); Sat, 6 Feb 2021 04:56:07 -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 1169ph2D029783; Sat, 6 Feb 2021 12:51:48 +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 348F87B645; Sat, 6 Feb 2021 12:51:44 +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: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, "Matwey V. Kornilov" Subject: [PATCH v4 4/4] hwmon: lm75: Handle broken device nodes gracefully Date: Sat, 6 Feb 2021 12:51:21 +0300 Message-Id: <20210206095121.20625-5-matwey@sai.msu.ru> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210206095121.20625-1-matwey@sai.msu.ru> References: <2588ea5c-630e-6509-689d-4c8fea358e9b@roeck-us.net> <20210206095121.20625-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 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 --- 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 3e4374aa2f99..cd2cda4f557a 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -567,10 +567,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)) -- 2.26.2