From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,T_DKIMWL_WL_HIGH,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4679C43219 for ; Thu, 2 May 2019 15:32:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8BD4B2081C for ; Thu, 2 May 2019 15:32:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556811177; bh=UQbqGMDCgBNAjQjZMA67nwKs/q9PTTAcMDrta56byeg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=KM8c4LFJWCNd88qa0iwgLklVl/KZG382K3Vm2seJtSMW1I/8jzLKkzylkwMTJjy09 qx1WgbbWtdO9AQFNKa1Mm6A/qGjgUtoo8xcMu30h6OQiYCwZut3HDwCBmOOJwsV7fv txWpwhb8cxTJdzQAbKiu1xpfFsb7S4YtdCmLoq+k= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728421AbfEBPc4 (ORCPT ); Thu, 2 May 2019 11:32:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:52794 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729266AbfEBPcu (ORCPT ); Thu, 2 May 2019 11:32:50 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 B6CD32081C; Thu, 2 May 2019 15:32:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556811170; bh=UQbqGMDCgBNAjQjZMA67nwKs/q9PTTAcMDrta56byeg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tLzQfRik0mPDEmr+X3zcUv/o+0nLSd6Hugn1k6cjnYBeTsLCz1e/GbIFupYSABWjn t7GAdRAa/pyaFnCT9FCUGXE4xrVCyaG3p8l9+osEzlkoAqHDRrA/mLKk8ZdnCMPii2 U6ufojxRa8ZQasMdYKkkh7f/pR/pSZY69PnFzJtc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kangjie Lu , Jacek Anaszewski , "Sasha Levin (Microsoft)" Subject: [PATCH 5.0 100/101] leds: pca9532: fix a potential NULL pointer dereference Date: Thu, 2 May 2019 17:21:42 +0200 Message-Id: <20190502143346.636141727@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190502143339.434882399@linuxfoundation.org> References: <20190502143339.434882399@linuxfoundation.org> User-Agent: quilt/0.66 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 [ 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