Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1985442imu; Fri, 14 Dec 2018 04:06:06 -0800 (PST) X-Google-Smtp-Source: AFSGD/XU2ZJyS6DkWeJI9ZRGDeFPxesvN++UfUYCqT+eZY1tl8A6CRQ89cz4NsQDw2dhNbevECNs X-Received: by 2002:a63:3c58:: with SMTP id i24mr2516246pgn.284.1544789166807; Fri, 14 Dec 2018 04:06:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544789166; cv=none; d=google.com; s=arc-20160816; b=rWPSZ/RIA61woB1MPOafN9zeHjKW0Em9gkXm4NLFSPLW2V0iyiw/N12+Nz+gddIC41 g8B1bokltQPnkubSz7W6lR9c+TI/qX0sNdOZiR/1enAYBAllgs/VYFGN1/XPPJ/Pp70j 2VZ68nZcuyX3tH/FXRjq5cid9lhuBp+oWRtS6rRoXpFogF0f6WuGq7Rr9o32MN2v4riC dhH7hs6heACrCKT4KFTZkuRqyk66TGl7RsmQ6hDlpIH+gsgIJacU/CcT5Lf8VOSoRlmv F3QTqE63gVBaJWljEtmxqsK1JNsR52CTo4LDr2GECGbXn7klN3OeR65f+1GGCUKxOugE qgBw== 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=QZxNZoWtvhda/b9BNZ7eVMKno4yXH8CFcR3wdgFygCc=; b=W3lFUXhOIe0w80wfF4jjoF3ltdEBeYzeqwZ8D/56c1UFcwpJuyfwwQCpp4XmVJFTzP 0m8xphftms7F0xTOLWXH9KRtu2tj9lHLyD7KLaC33yhRKXLm7U24PJdu5wDLyj6zoad9 yFU4xJRoruDWFpGgylqdoMZUhU/yF7fn2+Scz8XihJ0CTqXqCSm7etCmrIc3tDs4ILUw z9UwSPCzXX+1ehKFMHd+O0C6eajNt330Sjclh8lxlIuPevF5g1bZmlBjPkA56G5Oikoo 9er6a6n8y83IW6EiRUo3Y6Hf8JJzJi7karOBBfKjGRV5tzrSbfv5R8kGCyHycDS5iN6L qOuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zDuKlbTJ; 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 n78si4158268pfi.235.2018.12.14.04.05.50; Fri, 14 Dec 2018 04:06:06 -0800 (PST) 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=zDuKlbTJ; 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 S1728731AbeLNMEA (ORCPT + 99 others); Fri, 14 Dec 2018 07:04:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:48256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730395AbeLNMDz (ORCPT ); Fri, 14 Dec 2018 07:03:55 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 5E2B62146E; Fri, 14 Dec 2018 12:03:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789034; bh=eXDWIINbSuNNks39i/g01ZjF8arh1S93A2usO8iin74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zDuKlbTJz72g6e/LjPNxT6j7nLNw7X4Kfj8yuo/byEpfridaYP8GpI7f9bWC69LSv bAPuLs8OjTXFhd/KFUCWKhLWqTDgWnjMaVHXbYiziZwjUKdTDV0EsappzB+X247wQz KMICdVIaiYpfQQN00Ls/BGIRSxbc8MccCKCgGtiI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicolin Chen , Guenter Roeck , Sasha Levin Subject: [PATCH 4.19 046/142] hwmon (ina2xx) Fix NULL id pointer in probe() Date: Fri, 14 Dec 2018 12:58:51 +0100 Message-Id: <20181214115748.902056462@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115747.053633987@linuxfoundation.org> References: <20181214115747.053633987@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 70df9ebbd82c794ddfbb49d45b337f18d5588dc2 ] When using DT configurations, the id pointer might turn out to be NULL. Then the driver encounters NULL pointer access: Unable to handle kernel read from unreadable memory at vaddr 00000018 [...] PC is at ina2xx_probe+0x114/0x200 LR is at ina2xx_probe+0x10c/0x200 [...] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b The reason is that i2c core returns the id pointer by matching id_table with client->name, while the client->name is actually using the name from the first string in the DT compatible list, not the best one. So i2c core would fail to match the id_table if the best matched compatible string isn't the first one, and then would return a NULL id pointer. This probably should be fixed in i2c core. But it doesn't hurt to make the driver robust. So this patch fixes it by using the "chip" that's added to unify both DT and non-DT configurations. Additionally, since id pointer could be null, so as id->name: ina2xx 10-0047: power monitor (null) (Rshunt = 1000 uOhm) ina2xx 10-0048: power monitor (null) (Rshunt = 10000 uOhm) So this patch also fixes NULL name pointer, using client->name to play safe and to align with hwmon->name. Fixes: bd0ddd4d0883 ("hwmon: (ina2xx) Add OF device ID table") Signed-off-by: Nicolin Chen Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/ina2xx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c index 71d3445ba869..c2252cf452f5 100644 --- a/drivers/hwmon/ina2xx.c +++ b/drivers/hwmon/ina2xx.c @@ -491,7 +491,7 @@ static int ina2xx_probe(struct i2c_client *client, } data->groups[group++] = &ina2xx_group; - if (id->driver_data == ina226) + if (chip == ina226) data->groups[group++] = &ina226_group; hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, @@ -500,7 +500,7 @@ static int ina2xx_probe(struct i2c_client *client, return PTR_ERR(hwmon_dev); dev_info(dev, "power monitor %s (Rshunt = %li uOhm)\n", - id->name, data->rshunt); + client->name, data->rshunt); return 0; } -- 2.19.1