Linux-mediatek Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Himanshu Jha <himanshujha199640@gmail.com>, 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
Subject: Re: [PATCH] soc: mediatek: Handle return of of_match_device function
Date: Thu, 1 Feb 2018 15:02:38 +0000	[thread overview]
Message-ID: <b8265d37-0ef0-9d24-8ace-8fae7f67477d@arm.com> (raw)
In-Reply-To: <1517482822-28758-1-git-send-email-himanshujha199640@gmail.com>

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 <himanshujha199640@gmail.com>
> ---
>   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,
> 

  parent reply	other threads:[~2018-02-01 15:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-01 11:00 [PATCH] soc: mediatek: Handle return of of_match_device function Himanshu Jha
2018-02-01 11:04 ` Geert Uytterhoeven
2018-02-01 11:59 ` Alexandre Belloni
2018-02-01 15:02 ` Robin Murphy [this message]
     [not found]   ` <b8265d37-0ef0-9d24-8ace-8fae7f67477d-5wv7dgnIgG8@public.gmane.org>
2018-02-01 15:09     ` Geert Uytterhoeven
2018-02-01 15:16       ` Robin Murphy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b8265d37-0ef0-9d24-8ace-8fae7f67477d@arm.com \
    --to=robin.murphy@arm.com \
    --cc=geert+renesas@glider.be \
    --cc=himanshujha199640@gmail.com \
    --cc=kevin-cw.chen@mediatek.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=mars.cheng@mediatek.com \
    --cc=matthias.bgg@gmail.com \
    --cc=sean.wang@mediatek.com \
    --cc=ulf.hansson@linaro.org \
    --cc=weiyi.lu@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox