mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jacky Bai <ping.bai@nxp.com>
To: Tong Tiangen <tongtiangen@huawei.com>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	dl-linux-imx <linux-imx@nxp.com>
Cc: "linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH -next] soc: imx: gpc: add check for of_match_device in imx_gpc_old_dt_init
Date: Tue, 1 Jun 2021 10:11:28 +0000	[thread overview]
Message-ID: <DBBPR04MB7930A304416458880D69E1C7873E9@DBBPR04MB7930.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <20210601100256.70030-1-tongtiangen@huawei.com>

> Subject: [PATCH -next] soc: imx: gpc: add check for of_match_device in
> imx_gpc_old_dt_init
> 
> Add check for of_match_device in imx_gpc_old_dt_init to avoid potential
> NULL dereference of of_id.
> 
> Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
> ---
>  drivers/soc/imx/gpc.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/soc/imx/gpc.c b/drivers/soc/imx/gpc.c index
> 90a8b2c0676f..017a5e2bd4e6 100644
> --- a/drivers/soc/imx/gpc.c
> +++ b/drivers/soc/imx/gpc.c
> @@ -403,14 +403,25 @@ static int imx_gpc_old_dt_init(struct device *dev,
> struct regmap *regmap,
> 
>  static int imx_gpc_probe(struct platform_device *pdev)  {
> -	const struct of_device_id *of_id =
> -			of_match_device(imx_gpc_dt_ids, &pdev->dev);
> -	const struct imx_gpc_dt_data *of_id_data = of_id->data;
> +	const struct of_device_id *of_id;
> +	const struct imx_gpc_dt_data *of_id_data;
>  	struct device_node *pgc_node;
>  	struct regmap *regmap;
>  	void __iomem *base;
>  	int ret;
> 
> +	of_id = of_match_device(imx_gpc_dt_ids, &pdev->dev);
> +	if (!of_id) {
> +		dev_err(&pdev->dev, "OF id missing\n");
> +		return -EINVAL;
> +	}
> +
> +	of_id_data = of_id->data;
> +	if (!of_id_data) {
> +		dev_err(&pdev->dev, "OF id data missing\n");
> +		return -EINVAL;
> +	}
> +

I think there is no chance to pass 'invalid of_id' and 'of_id_data' to the probe function.
Such check seems not really necessary.

BR
Jacky Bai

>  	pgc_node = of_get_child_by_name(pdev->dev.of_node, "pgc");
> 
>  	/* bail out if DT too old and doesn't provide the necessary info */
> --
> 2.18.0.huawei.25


  reply	other threads:[~2021-06-01 10:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-01 10:02 Tong Tiangen
2021-06-01 10:11 ` Jacky Bai [this message]
2021-06-01 14:04   ` Fabio Estevam
2021-06-02  2:06     ` tongtiangen

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=DBBPR04MB7930A304416458880D69E1C7873E9@DBBPR04MB7930.eurprd04.prod.outlook.com \
    --to=ping.bai@nxp.com \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=tongtiangen@huawei.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

all inboxes | Powered by JetHome®