Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2778422yba; Mon, 22 Apr 2019 12:48:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1knza0SuSybtMOFbqsKUaP009LOhq1QESUCznDBov9rzSq54SJqwHetuyPOqY+IDA9F4a X-Received: by 2002:a17:902:6b0b:: with SMTP id o11mr22083976plk.266.1555962494842; Mon, 22 Apr 2019 12:48:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555962494; cv=none; d=google.com; s=arc-20160816; b=Sq+7xLFUmz+uZc+yZfSs+jqWt7U3Fx9F6ai7cqWa23eZuCKB56NEBdhgzb+mcRFHGs qIYqi4hejkDiEdle2oAczOsS40ULHK4dCXuWurMM4B3/eZphQ5Edia3nj+7jp28tnWqU HefpInF4azcJk4aZW9yeF6GrzV/4eQF2A8vUIclyUCXbIUn72gbkZ0lXIN1MG98VG+QQ qlzIVEPLUt8pvxla0h6GyH1JgIVkiP36tTOLtQb41pd3j+V6GGgLofzgGr3hDSELcx2U Jcey0W7/zJyPbiN9BI+NbQ8kX1IFl1yrEa5Ssh5tTA28Z/bt8csF6wP9HPNedB8ghK/R jj8g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5ItBia9l5R5jRWzHlqxaqmG3s2X7pfTlEvslX8ydI74=; b=rvDZ8gAhbd+nx/sKMLX3WCArAU06/ycDBFtCpYm7svewNVlu+m5Zln6Ow2TJP0DVqb 2aljEK8DKAMOePGAnIjZGMCJj4KdNHOr+HwBzDcx0GfMAOBMoxHiE2JJrWvxhlAp5rdl 4FxeJEWrZpue3lnAe4MNHOZBUeU6CEXP68lvXyvSDmI2DGCrPxzhGYo8Jh5Tz5fBxZ8O XW/4glHTk65z+hZDDYxAePHWchtiBVyT9B8gLFARE08tOTkL7EngHSZgTh1f5Wzd7/8e V8LV+f4na/5j3sKyk2ddqYbbn8dyKQTlZlfX7othIxrHndNqyHNY1fpjBDLGCHtDNIIa w7jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Sbc40Txm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k1si12597124pgq.219.2019.04.22.12.47.58; Mon, 22 Apr 2019 12:48:14 -0700 (PDT) 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=Sbc40Txm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729713AbfDVTpS (ORCPT + 99 others); Mon, 22 Apr 2019 15:45:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:46844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729692AbfDVTpN (ORCPT ); Mon, 22 Apr 2019 15:45:13 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3E67E218D9; Mon, 22 Apr 2019 19:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962313; bh=2yWzdcIpJl1eWpNGQDtXa9BkpBvLMN8DxFGXO814MeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sbc40Txm1gffe5AkQmP6JkTszX4Rk6F1v2Jb/G5O1eIwi68twKtgMi7EKOZoCh1Mj fDfwyKsA+9Og44bHcP4cPS/pAw4RgJauF5fl0ahZ9AOPRtgu7/9aqKdEZHkoV5GfAn vDakRu6/g9eNNSIg3GFIjkIVEEehpqF5aJMotgXI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kangjie Lu , Jacek Anaszewski , Sasha Levin , linux-leds@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 97/98] leds: pca9532: fix a potential NULL pointer dereference Date: Mon, 22 Apr 2019 15:42:04 -0400 Message-Id: <20190422194205.10404-97-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194205.10404-1-sashal@kernel.org> References: <20190422194205.10404-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kangjie Lu [ Upstream commit 0aab8e4df4702b31314a27ec4b0631dfad0fae0a ] In case of_match_device cannot find a match, return -EINVAL to avoid NULL pointer dereference. Fixes: fa4191a609f2 ("leds: pca9532: Add device tree support") Signed-off-by: Kangjie Lu Signed-off-by: Jacek Anaszewski Signed-off-by: Sasha Levin (Microsoft) --- drivers/leds/leds-pca9532.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c index 7fea18b0c15d..7cb4d685a1f1 100644 --- a/drivers/leds/leds-pca9532.c +++ b/drivers/leds/leds-pca9532.c @@ -513,6 +513,7 @@ static int pca9532_probe(struct i2c_client *client, const struct i2c_device_id *id) { int devid; + const struct of_device_id *of_id; struct pca9532_data *data = i2c_get_clientdata(client); struct pca9532_platform_data *pca9532_pdata = dev_get_platdata(&client->dev); @@ -528,8 +529,11 @@ static int pca9532_probe(struct i2c_client *client, dev_err(&client->dev, "no platform data\n"); return -EINVAL; } - devid = (int)(uintptr_t)of_match_device( - of_pca9532_leds_match, &client->dev)->data; + of_id = of_match_device(of_pca9532_leds_match, + &client->dev); + if (unlikely(!of_id)) + return -EINVAL; + devid = (int)(uintptr_t) of_id->data; } else { devid = id->driver_data; } -- 2.19.1