From patchwork Mon Jan 30 04:47:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shailendra.v@samsung.com X-Patchwork-Id: 9544421 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 750B3604A8 for ; Mon, 30 Jan 2017 04:48:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6862D26E49 for ; Mon, 30 Jan 2017 04:48:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C8822833B; Mon, 30 Jan 2017 04:48:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00 autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E9F492833A for ; Mon, 30 Jan 2017 04:48:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cY3tR-0007Pl-0u; Mon, 30 Jan 2017 04:48:41 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cY3sc-0006gx-KI; Mon, 30 Jan 2017 04:47:52 +0000 Received: from epcas3p3.samsung.com (unknown [182.195.41.21]) by mailout4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OKK01H59TB2NC50@mailout4.samsung.com>; Mon, 30 Jan 2017 13:47:26 +0900 (KST) Received: from epsmges3p7.samsung.com (unknown [182.195.42.21]) by epcas3p2.samsung.com (KnoxPortal) with ESMTP id 20170130044725epcas3p2f31c05e46af0c8e4269409768e2cae2f~ecz-_7IxX1843018430epcas3p2T; Mon, 30 Jan 2017 04:47:25 +0000 (GMT) Received: from epcas3p1.samsung.com ( [182.195.41.19]) by epsmges3p7.samsung.com (EPCPMTA) with SMTP id D6.33.04726.D55CE885; Mon, 30 Jan 2017 13:47:25 +0900 (KST) Received: from epsmgmsp03.samsung.com (unknown [182.195.34.24]) by epcas3p4.samsung.com (KnoxPortal) with ESMTP id 20170130044724epcas3p444b23d43fed213511e6994ecb4ed0ef3~ecz_xticq2006720067epcas3p4k; Mon, 30 Jan 2017 04:47:24 +0000 (GMT) X-AuditID: b6c32a15-f798a6d000001276-d2-588ec55d7e4a Received: from srin.p4 (Unknown_Domain [107.108.168.37]) by epsmgmsp03.samsung.com (EPCPMTA) with SMTP id B2.E4.04880.855CE885; Mon, 30 Jan 2017 13:47:24 +0900 (KST) From: Shailendra Verma To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Heiko Stuebner , Dmitry Torokhov , Ksenija Stanojevic , Marek Vasut , linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, p.shailesh@samsung.com, ashish.kalra@samsung.com, Shailendra Verma , Shailendra Verma Subject: [PATCH] iio: adc - Fix possible NULL derefrence. Date: Mon, 30 Jan 2017 10:17:14 +0530 Message-id: <1485751634-28963-1-git-send-email-shailendra.v@samsung.com> X-Mailer: git-send-email 1.7.9.5 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNIsWRmVeSWpSXmKPExsWy7bCmsG7s0b4Ig62HdSzuT/vGbnF40QtG i/+PXrNaPGhaxWSx6/8bZovHt+6zWyyZPJ/VYtPja6wW8468Y7G4vGsOm8WnB/+ZLd60NTJa 7JjSymLxe9cxdotb82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SmZduqxQa4qZroaSQl5ibaqsU oesbEqSkUJaYUwrkGRmgAQfnAPdgJX27BLeMwz1r2Qo6BSoevGlibmA8wtvFyMkhIWAi0Trn MBuELSZx4d56IJuLQ0hgOaPE8RONrCAJNgFDidd9f5lAEiICb1kkNj/dApYQFrCUmP62gxnE ZhFQlVh66j5YnFfAQ+LN6e9ADRxAUxUk5kyymcDIuYCRYRWjWGpBcW56bnGBgbFecWJucWle ul5yfu4mRmDYbzusJLGDccEKr0OMAhyMSjy8Cw73RQixJpYVV+YeYpTgYFYS4S3fCRTiTUms rEotyo8vKs1JLT7EaAq0fSKzlGhyPjAm80riDU1MLSwsTCyNjY0tTJTEeWOnPwsXEkhPLEnN Tk0tSC2C6WPi4JRqYFzx21Th25rFtauu2l93i5n/U9T75EuhBsPm83LrUhdKib1zv9WtrKvw 8s6WD46zdNID5rklcijrdb3gPzXJXDzpouXVyTmn9R++/FcvbHVZit+us3uuddNj1vBQ1wkX 5+koZ61632sS3sH+sOb6wVp2Y8vJM06azrJpKyr95n0v4Z30trwpoUosxRmJhlrMRcWJAJ70 rrORAgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170130044724epcas3p444b23d43fed213511e6994ecb4ed0ef3 X-Msg-Generator: CA X-Sender-IP: 182.195.34.24 X-Local-Sender: =?UTF-8?B?U2hhaWxlbmRyYSBWZXJtYRtTUkktTm9pZGEtQ29tbWVyY2lh?= =?UTF-8?B?bCBSJkQgIFN5c3RlbSBTL1cgR3JvdXAb7IK87ISx7KCE7J6QG0xlYWQgRW5n?= =?UTF-8?B?aW5lZXIvQ29ycG9yYXRlIEVuZ2luZWVy?= X-Global-Sender: =?UTF-8?B?U2hhaWxlbmRyYSBWZXJtYRtTUkktTm9pZGEtQ29tbWVyY2lh?= =?UTF-8?B?bCBSJkQgIFN5c3RlbSBTL1cgR3JvdXAbU2Ftc3VuZyBFbGVjdHJvbmljcxtM?= =?UTF-8?B?ZWFkIEVuZ2luZWVyL0NvcnBvcmF0ZSBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG1NXQUhRG0MxMElaMDFJWjAxODEyMA==?= CMS-TYPE: 103P X-HopCount: 7 X-CMS-RootMailID: 20170130044724epcas3p444b23d43fed213511e6994ecb4ed0ef3 X-RootMTR: 20170130044724epcas3p444b23d43fed213511e6994ecb4ed0ef3 References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170129_204751_087314_110B5BBD X-CRM114-Status: GOOD ( 11.15 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP of_match_device could return NULL, and so can cause a NULL pointer dereference later. Signed-off-by: Shailendra Verma --- drivers/iio/adc/mxs-lradc.c | 14 ++++++++++---- drivers/iio/adc/rockchip_saradc.c | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/mxs-lradc.c b/drivers/iio/adc/mxs-lradc.c index b84d37c..4308a59 100644 --- a/drivers/iio/adc/mxs-lradc.c +++ b/drivers/iio/adc/mxs-lradc.c @@ -1570,10 +1570,8 @@ static int mxs_lradc_probe_touchscreen(struct mxs_lradc *lradc, static int mxs_lradc_probe(struct platform_device *pdev) { - const struct of_device_id *of_id = - of_match_device(mxs_lradc_dt_ids, &pdev->dev); - const struct mxs_lradc_of_config *of_cfg = - &mxs_lradc_of_config[(enum mxs_lradc_id)of_id->data]; + const struct of_device_id *of_id; + const struct mxs_lradc_of_config *of_cfg; struct device *dev = &pdev->dev; struct device_node *node = dev->of_node; struct mxs_lradc *lradc; @@ -1583,6 +1581,14 @@ static int mxs_lradc_probe(struct platform_device *pdev) int i, s; u64 scale_uv; + of_id = of_match_device(mxs_lradc_dt_ids, &pdev->dev); + if (!of_id) { + dev_err(&pdev->dev, "Error: No device match found\n"); + return -ENODEV; + } + + of_cfg = &mxs_lradc_of_config[(enum mxs_lradc_id)of_id->data]; + /* Allocate the IIO device. */ iio = devm_iio_device_alloc(dev, sizeof(*lradc)); if (!iio) { diff --git a/drivers/iio/adc/rockchip_saradc.c b/drivers/iio/adc/rockchip_saradc.c index 85d7012..08dfb43 100644 --- a/drivers/iio/adc/rockchip_saradc.c +++ b/drivers/iio/adc/rockchip_saradc.c @@ -224,6 +224,10 @@ static int rockchip_saradc_probe(struct platform_device *pdev) info = iio_priv(indio_dev); match = of_match_device(rockchip_saradc_match, &pdev->dev); + if (!match) { + dev_err(&pdev->dev, "Error: No device match found\n"); + return -ENODEV; + } info->data = match->data; mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);