Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2845852yba; Mon, 22 Apr 2019 14:09:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqweZjCvPHbWvOdnP/pq+6FWS3sf3tWojdil0yn/StmnQb8bb9E2ggVhY/BxWsujxUqRiVlb X-Received: by 2002:a62:4595:: with SMTP id n21mr23101836pfi.79.1555967361698; Mon, 22 Apr 2019 14:09:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555967361; cv=none; d=google.com; s=arc-20160816; b=CaRIqCSXZ6A7RAy5nTgrq3eZKRHCQjf0mLYR3vovy9qNMv1s8wIK3UZYpvnCcnnLYY /rEwBCJshE4LJyMCD/C6YKmM0CUHn3rI0FFW4nHAxJsCZHUGWizJWyfRBv83kZd817s8 6OWM92eK+aoWNL9iSnuZLJ2zzFNfGtpkbuPgcJAEPAIUBVeJNCdUsuTs4KyDN0Dt/8pN L7aFIOHRbLAHJkAe4mkS4BAeoQ0qPQnxMTj+TK96srGYS4DwzOuc1wpAdP2X81d2Ithm NHFmoqeg3WMUc9lZ+L/TyC9aGa1gsitMz1tep74t5/xemeV/hm3G21LaxDrkRRPCsPhB Yn9g== 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=hbOO0q39n4/1mHCiFihMOgEcTk/opsf31mBhoYD5Ccb7gnJK1mK6Ggffovgg9AA/TI 4C3CuYkMiAsBlV5f5bMSKcbbJKLlKQvxMHsgtW3keNCuJ4ux40mcqYNv9tY1O+SxYdvg 8wAmJnxKeS3kmxMqiLTIpPyR6ROuyuYfmb9+EF0fci7Zx3NS8QKbattAOH8dO6sSj3KK CfHVZwuqOvGtsAmjtkBvc5tHT4hW3zOHlAJL29I/i5mcvYh2xH+PyoHg6qi6eeHyskmi 4SaebnOORDd44MIf0UoXYFtLLv/YWtoMwwWRcbsVlX6KkVoVlf/rGcE3hKlZ6gP33O7D jHJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="roWM/Je/"; 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 1si14835319plu.320.2019.04.22.14.09.06; Mon, 22 Apr 2019 14:09:21 -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="roWM/Je/"; 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 S1730272AbfDVTr1 (ORCPT + 99 others); Mon, 22 Apr 2019 15:47:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:50184 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730264AbfDVTrZ (ORCPT ); Mon, 22 Apr 2019 15:47:25 -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 D5A9821904; Mon, 22 Apr 2019 19:47:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962444; bh=2yWzdcIpJl1eWpNGQDtXa9BkpBvLMN8DxFGXO814MeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=roWM/Je/FSwIAO1UNWVoO/UmCmJaRq7d9YwIv4apN3tFzCEpLbwqrkfuEXsypmSXF tOspCEk9AcRC1rWEhEemwn1FFbb4UjxPBcPXE90wBhuN8zz1pPB23Cvv94LuCoTRn8 DitmR0gL2/HGzsPhRxFUEJLmxchkBs+J4PY4x4Zs= 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 4.19 67/68] leds: pca9532: fix a potential NULL pointer dereference Date: Mon, 22 Apr 2019 15:45:15 -0400 Message-Id: <20190422194516.11634-67-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194516.11634-1-sashal@kernel.org> References: <20190422194516.11634-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