Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3335135pxj; Tue, 1 Jun 2021 02:57:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6xxjs6m6s+0pJsSB4d21iBkkzoq56rL+8xNsVQbQTBANxBD1JFM90XZIW8zfvGG/4EfpL X-Received: by 2002:aa7:d648:: with SMTP id v8mr1230031edr.203.1622541458710; Tue, 01 Jun 2021 02:57:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622541458; cv=none; d=google.com; s=arc-20160816; b=Lxa7fKpbP7nmFYF9TVqX7fx69BbbhykDLZ9o9TFDgjekPGX46cqAe/AeAKQDP7YhZo oyQ1jvvW0JK+/vzxqneiFGPL0MW4yJwNf2VD/r9ivw7F7vVdp0q/WcxNiKnAHLEAtabg YZXNvFqNqE6XKIzllZqbaAxHeLX/xa5Ld7GOMgvu0eADqJt9VwJFIopkvKqxmdZtIfBn lVzR6IsUe7oZrCL8YWfFzUnLfMI3yom2hjgafgPlcxG2FR0C8By3JD+i1H1myTm1ACnH o3X+PT9hmtU7bNs/NHr6QEEH3vhL7/3HFuzD+T6zz1HUM0QSXEbXJe691EHQEu2kg4JH crNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=gSOXCrdqvNSGg6/doJFntCPqw3tW4cEl/473eJ6oOsQ=; b=XbQSTwVw/eY42U6R8vmJiCTkkvOKdttEfzQI8bellgosTZfnOTa0VPW+xrobO23sm0 DU/Yi9DKg/ZPgZl5EKQgSyZ0gJXoPJO6NFSAf/jjQX70i+Ug/R3Kp66+j3ALTSL6+4y0 Rjq7CZwmyYamcUCBZWhr3dtlUXuUvx2vd1WlNT/BWIu4xBjvRducruTNaT0tcvPru+81 AzNfrdylG9cWrfO5TC24fZjQZZm17hE6+A7qnxGwnApVmRAD59V+hbKB4JYWVQM45kMb e/EjHZhTy1kwza+eYs0m325PN7yikp0BEE77qymWDnu8bsDxQdgUCLD7iNoiQTYogrPp PZaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bo3si4354788edb.589.2021.06.01.02.57.16; Tue, 01 Jun 2021 02:57:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232947AbhFAJzT (ORCPT + 99 others); Tue, 1 Jun 2021 05:55:19 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:3318 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231971AbhFAJzT (ORCPT ); Tue, 1 Jun 2021 05:55:19 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4FvS6H4J4Gz1BG6Y; Tue, 1 Jun 2021 17:48:55 +0800 (CST) Received: from dggpemm000001.china.huawei.com (7.185.36.245) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 1 Jun 2021 17:53:37 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm000001.china.huawei.com (7.185.36.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 1 Jun 2021 17:53:36 +0800 From: Tong Tiangen To: Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team CC: , , Tong Tiangen Subject: [PATCH -next] soc: imx: gpc: add check for of_match_device in imx_gpc_old_dt_init Date: Tue, 1 Jun 2021 18:02:56 +0800 Message-ID: <20210601100256.70030-1-tongtiangen@huawei.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm000001.china.huawei.com (7.185.36.245) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; + } + 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