* [PATCH -next] soc: imx: gpc: add check for of_match_device in imx_gpc_old_dt_init
@ 2021-06-01 10:02 Tong Tiangen
2021-06-01 10:11 ` Jacky Bai
0 siblings, 1 reply; 4+ messages in thread
From: Tong Tiangen @ 2021-06-01 10:02 UTC (permalink / raw)
To: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
NXP Linux Team
Cc: linux-arm-kernel, linux-kernel, Tong Tiangen
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;
+ }
+
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH -next] soc: imx: gpc: add check for of_match_device in imx_gpc_old_dt_init
2021-06-01 10:02 [PATCH -next] soc: imx: gpc: add check for of_match_device in imx_gpc_old_dt_init Tong Tiangen
@ 2021-06-01 10:11 ` Jacky Bai
2021-06-01 14:04 ` Fabio Estevam
0 siblings, 1 reply; 4+ messages in thread
From: Jacky Bai @ 2021-06-01 10:11 UTC (permalink / raw)
To: Tong Tiangen, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, dl-linux-imx
Cc: linux-arm-kernel, linux-kernel
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next] soc: imx: gpc: add check for of_match_device in imx_gpc_old_dt_init
2021-06-01 10:11 ` Jacky Bai
@ 2021-06-01 14:04 ` Fabio Estevam
2021-06-02 2:06 ` tongtiangen
0 siblings, 1 reply; 4+ messages in thread
From: Fabio Estevam @ 2021-06-01 14:04 UTC (permalink / raw)
To: Jacky Bai
Cc: Tong Tiangen, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team,
dl-linux-imx, linux-arm-kernel, linux-kernel
On Tue, Jun 1, 2021 at 7:11 AM Jacky Bai <ping.bai@nxp.com> wrote:
> 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.
I agree. The only way this driver can probe is via device tree.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next] soc: imx: gpc: add check for of_match_device in imx_gpc_old_dt_init
2021-06-01 14:04 ` Fabio Estevam
@ 2021-06-02 2:06 ` tongtiangen
0 siblings, 0 replies; 4+ messages in thread
From: tongtiangen @ 2021-06-02 2:06 UTC (permalink / raw)
To: Fabio Estevam, Jacky Bai
Cc: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, dl-linux-imx,
linux-arm-kernel, linux-kernel
On 2021/6/1 22:04, Fabio Estevam wrote:
> On Tue, Jun 1, 2021 at 7:11 AM Jacky Bai <ping.bai@nxp.com> wrote:
>
>> 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.
> I agree. The only way this driver can probe is via device tree.
> .
ok, there is no problem in practical use. thanks all.
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-06-02 2:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-01 10:02 [PATCH -next] soc: imx: gpc: add check for of_match_device in imx_gpc_old_dt_init Tong Tiangen
2021-06-01 10:11 ` Jacky Bai
2021-06-01 14:04 ` Fabio Estevam
2021-06-02 2:06 ` tongtiangen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).