From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751660AbeBAPCq (ORCPT ); Thu, 1 Feb 2018 10:02:46 -0500 Received: from foss.arm.com ([217.140.101.70]:51222 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751408AbeBAPCl (ORCPT ); Thu, 1 Feb 2018 10:02:41 -0500 Subject: Re: [PATCH] soc: mediatek: Handle return of of_match_device function To: Himanshu Jha , matthias.bgg@gmail.com Cc: ulf.hansson@linaro.org, weiyi.lu@mediatek.com, geert+renesas@glider.be, sean.wang@mediatek.com, linux-kernel@vger.kernel.org, kevin-cw.chen@mediatek.com, mars.cheng@mediatek.com, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org References: <1517482822-28758-1-git-send-email-himanshujha199640@gmail.com> From: Robin Murphy Message-ID: Date: Thu, 1 Feb 2018 15:02:38 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1517482822-28758-1-git-send-email-himanshujha199640@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/02/18 11:00, Himanshu Jha wrote: > In scpsys_probe function, return value of of_match_device function which > returns null is dereferenced without checking. Therefore, add a check for > potential null dereference. > > Detected by CoverityScan, CID#1424087 "Dereference null return value" > > Fixes: commit 53fddb1a66dd ("soc: mediatek: reduce code duplication of scpsys_probe across all SoCs") > Signed-off-by: Himanshu Jha > --- > drivers/soc/mediatek/mtk-scpsys.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c > index 435ce5e..6e7f196 100644 > --- a/drivers/soc/mediatek/mtk-scpsys.c > +++ b/drivers/soc/mediatek/mtk-scpsys.c > @@ -981,6 +981,9 @@ static int scpsys_probe(struct platform_device *pdev) > int i, ret; > > match = of_match_device(of_scpsys_match_tbl, &pdev->dev); > + if (!match) > + return -EINVAL; > + > soc = (const struct scp_soc_data *)match->data; You could of course replace the whole sequence with an of_device_get_match_data() call, which happens to be inherently safe against the no-match case even when that *is* impossible by design. Robin. > > scp = init_scp(pdev, soc->domains, soc->num_domains, &soc->regs, >