of_node_put() is called after of_match_node() successfully called,
then in the following error handling, of_node_put() is called again
which is unnecessary, this patch adjusts the location of of_node_put()
to avoid such scenario.
Signed-off-by: Anson Huang <[email protected]>
---
drivers/soc/imx/soc-imx8.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/soc/imx/soc-imx8.c b/drivers/soc/imx/soc-imx8.c
index b1bd8e2..944add2 100644
--- a/drivers/soc/imx/soc-imx8.c
+++ b/drivers/soc/imx/soc-imx8.c
@@ -86,8 +86,6 @@ static int __init imx8_soc_init(void)
if (!id)
goto free_soc;
- of_node_put(root);
-
data = id->data;
if (data) {
soc_dev_attr->soc_id = data->name;
@@ -106,6 +104,8 @@ static int __init imx8_soc_init(void)
if (IS_ENABLED(CONFIG_ARM_IMX_CPUFREQ_DT))
platform_device_register_simple("imx-cpufreq-dt", -1, NULL, 0);
+ of_node_put(root);
+
return 0;
free_rev:
--
2.7.4
Current implementation of i.MX8 SoC driver returns -ENODEV
for all cases of error during initialization, this is incorrect.
This patch fixes them using correct return value according
to different errors.
Signed-off-by: Anson Huang <[email protected]>
---
drivers/soc/imx/soc-imx8.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/soc/imx/soc-imx8.c b/drivers/soc/imx/soc-imx8.c
index 944add2..9dd088f 100644
--- a/drivers/soc/imx/soc-imx8.c
+++ b/drivers/soc/imx/soc-imx8.c
@@ -73,7 +73,7 @@ static int __init imx8_soc_init(void)
soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
if (!soc_dev_attr)
- return -ENODEV;
+ return -ENOMEM;
soc_dev_attr->family = "Freescale i.MX";
@@ -83,8 +83,10 @@ static int __init imx8_soc_init(void)
goto free_soc;
id = of_match_node(imx8_soc_match, root);
- if (!id)
+ if (!id) {
+ ret = -ENODEV;
goto free_soc;
+ }
data = id->data;
if (data) {
@@ -94,12 +96,16 @@ static int __init imx8_soc_init(void)
}
soc_dev_attr->revision = imx8_revision(soc_rev);
- if (!soc_dev_attr->revision)
+ if (!soc_dev_attr->revision) {
+ ret = -ENOMEM;
goto free_soc;
+ }
soc_dev = soc_device_register(soc_dev_attr);
- if (IS_ERR(soc_dev))
+ if (IS_ERR(soc_dev)) {
+ ret = PTR_ERR(soc_dev);
goto free_rev;
+ }
if (IS_ENABLED(CONFIG_ARM_IMX_CPUFREQ_DT))
platform_device_register_simple("imx-cpufreq-dt", -1, NULL, 0);
@@ -113,6 +119,6 @@ static int __init imx8_soc_init(void)
free_soc:
kfree(soc_dev_attr);
of_node_put(root);
- return -ENODEV;
+ return ret;
}
device_initcall(imx8_soc_init);
--
2.7.4
On 5/21/2019 12:18 PM, Anson Huang wrote:
> of_node_put() is called after of_match_node() successfully called,
> then in the following error handling, of_node_put() is called again
> which is unnecessary, this patch adjusts the location of of_node_put()
> to avoid such scenario.
>
> Signed-off-by: Anson Huang <[email protected]>
For both:
Reviewed-by: Leonard Crestez <[email protected]>
I was thinking that maybe you could of_node_put as soon as you were done
with it but the model is read straight into soc_dev_attr so just freeing
everything at the end makes more sense.
On Tue, May 21, 2019 at 09:18:43AM +0000, Anson Huang wrote:
> of_node_put() is called after of_match_node() successfully called,
> then in the following error handling, of_node_put() is called again
> which is unnecessary, this patch adjusts the location of of_node_put()
> to avoid such scenario.
>
> Signed-off-by: Anson Huang <[email protected]>
Again, there are '=20' in the patch content and I cannot apply it.
Shawn
> ---
> drivers/soc/imx/soc-imx8.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/soc/imx/soc-imx8.c b/drivers/soc/imx/soc-imx8.c
> index b1bd8e2..944add2 100644
> --- a/drivers/soc/imx/soc-imx8.c
> +++ b/drivers/soc/imx/soc-imx8.c
> @@ -86,8 +86,6 @@ static int __init imx8_soc_init(void)
> if (!id)
> goto free_soc;
>
> - of_node_put(root);
> -
> data = id->data;
> if (data) {
> soc_dev_attr->soc_id = data->name;
> @@ -106,6 +104,8 @@ static int __init imx8_soc_init(void)
> if (IS_ENABLED(CONFIG_ARM_IMX_CPUFREQ_DT))
> platform_device_register_simple("imx-cpufreq-dt", -1, NULL, 0);
>
> + of_node_put(root);
> +
> return 0;
>
> free_rev:
> --
> 2.7.4
>
Hi, Shawn
> -----Original Message-----
> From: Shawn Guo [mailto:[email protected]]
> Sent: Thursday, May 23, 2019 8:41 PM
> To: Anson Huang <[email protected]>
> Cc: [email protected]; [email protected]; [email protected];
> Leonard Crestez <[email protected]>; Abel Vesa
> <[email protected]>; [email protected]; linux-arm-
> [email protected]; [email protected]; dl-linux-imx
> <[email protected]>
> Subject: Re: [PATCH 1/2] soc: imx: soc-imx8: Avoid unnecessary
> of_node_put() in error handling
>
> On Tue, May 21, 2019 at 09:18:43AM +0000, Anson Huang wrote:
> > of_node_put() is called after of_match_node() successfully called,
> > then in the following error handling, of_node_put() is called again
> > which is unnecessary, this patch adjusts the location of of_node_put()
> > to avoid such scenario.
> >
> > Signed-off-by: Anson Huang <[email protected]>
>
> Again, there are '=20' in the patch content and I cannot apply it.
I resent the patch set, please pick them up, thanks.
https://patchwork.kernel.org/patch/10959101/
https://patchwork.kernel.org/patch/10959099/
Anson.
>
> Shawn
>
> > ---
> > drivers/soc/imx/soc-imx8.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/soc/imx/soc-imx8.c b/drivers/soc/imx/soc-imx8.c
> > index b1bd8e2..944add2 100644
> > --- a/drivers/soc/imx/soc-imx8.c
> > +++ b/drivers/soc/imx/soc-imx8.c
> > @@ -86,8 +86,6 @@ static int __init imx8_soc_init(void)
> > if (!id)
> > goto free_soc;
> >
> > - of_node_put(root);
> > -
> > data = id->data;
> > if (data) {
> > soc_dev_attr->soc_id = data->name;
> > @@ -106,6 +104,8 @@ static int __init imx8_soc_init(void)
> > if (IS_ENABLED(CONFIG_ARM_IMX_CPUFREQ_DT))
> > platform_device_register_simple("imx-cpufreq-dt", -1, NULL,
> 0);
> >
> > + of_node_put(root);
> > +
> > return 0;
> >
> > free_rev:
> > --
> > 2.7.4
> >