Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH V2 1/2] soc: imx8: Fix potential kernel dump in error path
@ 2019-06-14  8:07 Anson.Huang
  2019-06-14  8:07 ` [PATCH V2 2/2] soc: imx8: Use existing of_root directly Anson.Huang
  2019-06-18  9:13 ` [PATCH V2 1/2] soc: imx8: Fix potential kernel dump in error path Shawn Guo
  0 siblings, 2 replies; 5+ messages in thread
From: Anson.Huang @ 2019-06-14  8:07 UTC (permalink / raw)
  To: shawnguo, s.hauer, kernel, festevam, leonard.crestez,
	viresh.kumar, abel.vesa, linux-arm-kernel, linux-kernel
  Cc: Linux-imx

From: Anson Huang <Anson.Huang@nxp.com>

When SoC's revision value is 0, SoC driver will print out
"unknown" in sysfs's revision node, this "unknown" is a
static string which can NOT be freed, this will caused below
kernel dump in later error path which calls kfree:

kernel BUG at mm/slub.c:3942!
Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
Modules linked in:
CPU: 2 PID: 1 Comm: swapper/0 Not tainted 5.2.0-rc4-next-20190611-00023-g705146c-dirty #2197
Hardware name: NXP i.MX8MQ EVK (DT)
pstate: 60000005 (nZCv daif -PAN -UAO)
pc : kfree+0x170/0x1b0
lr : imx8_soc_init+0xc0/0xe4
sp : ffff00001003bd10
x29: ffff00001003bd10 x28: ffff00001121e0a0
x27: ffff000011482000 x26: ffff00001117068c
x25: ffff00001121e100 x24: ffff000011482000
x23: ffff000010fe2b58 x22: ffff0000111b9ab0
x21: ffff8000bd9dfba0 x20: ffff0000111b9b70
x19: ffff7e000043f880 x18: 0000000000001000
x17: ffff000010d05fa0 x16: ffff0000122e0000
x15: 0140000000000000 x14: 0000000030360000
x13: ffff8000b94b5bb0 x12: 0000000000000038
x11: ffffffffffffffff x10: ffffffffffffffff
x9 : 0000000000000003 x8 : ffff8000b9488147
x7 : ffff00001003bc00 x6 : 0000000000000000
x5 : 0000000000000003 x4 : 0000000000000003
x3 : 0000000000000003 x2 : b8793acd604edf00
x1 : ffff7e000043f880 x0 : ffff7e000043f888
Call trace:
 kfree+0x170/0x1b0
 imx8_soc_init+0xc0/0xe4
 do_one_initcall+0x58/0x1b8
 kernel_init_freeable+0x1cc/0x288
 kernel_init+0x10/0x100
 ret_from_fork+0x10/0x18

This patch fixes this potential kernel dump when a chip's
revision is "unknown", it is done by checking whether the
revision space can be freed.

Fixes: a7e26f356ca1 ("soc: imx: Add generic i.MX8 SoC driver")
Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
Changes since V1:
	- still need the "unknown" info for revision to avoid confusion, so fix this issue
	  by checking whether the revision space can be freed before freeing it.
---
 drivers/soc/imx/soc-imx8.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/imx/soc-imx8.c b/drivers/soc/imx/soc-imx8.c
index 02309a2..5c7f330 100644
--- a/drivers/soc/imx/soc-imx8.c
+++ b/drivers/soc/imx/soc-imx8.c
@@ -155,7 +155,8 @@ static int __init imx8_soc_init(void)
 	return 0;
 
 free_rev:
-	kfree(soc_dev_attr->revision);
+	if (strcmp(soc_dev_attr->revision, "unknown"))
+		kfree(soc_dev_attr->revision);
 free_soc:
 	kfree(soc_dev_attr);
 	of_node_put(root);
-- 
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH V2 2/2] soc: imx8: Use existing of_root directly
  2019-06-14  8:07 [PATCH V2 1/2] soc: imx8: Fix potential kernel dump in error path Anson.Huang
@ 2019-06-14  8:07 ` Anson.Huang
  2019-06-18  9:14   ` Shawn Guo
  2019-06-18  9:13 ` [PATCH V2 1/2] soc: imx8: Fix potential kernel dump in error path Shawn Guo
  1 sibling, 1 reply; 5+ messages in thread
From: Anson.Huang @ 2019-06-14  8:07 UTC (permalink / raw)
  To: shawnguo, s.hauer, kernel, festevam, leonard.crestez,
	viresh.kumar, abel.vesa, linux-arm-kernel, linux-kernel
  Cc: Linux-imx

From: Anson Huang <Anson.Huang@nxp.com>

There is common of_root for reference, no need to find it
from DT again, use of_root directly to make driver simple.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
---
No changes.
---
 drivers/soc/imx/soc-imx8.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/soc/imx/soc-imx8.c b/drivers/soc/imx/soc-imx8.c
index 5c7f330..b459bf2 100644
--- a/drivers/soc/imx/soc-imx8.c
+++ b/drivers/soc/imx/soc-imx8.c
@@ -105,7 +105,6 @@ static int __init imx8_soc_init(void)
 {
 	struct soc_device_attribute *soc_dev_attr;
 	struct soc_device *soc_dev;
-	struct device_node *root;
 	const struct of_device_id *id;
 	u32 soc_rev = 0;
 	const struct imx8_soc_data *data;
@@ -117,12 +116,11 @@ static int __init imx8_soc_init(void)
 
 	soc_dev_attr->family = "Freescale i.MX";
 
-	root = of_find_node_by_path("/");
-	ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
+	ret = of_property_read_string(of_root, "model", &soc_dev_attr->machine);
 	if (ret)
 		goto free_soc;
 
-	id = of_match_node(imx8_soc_match, root);
+	id = of_match_node(imx8_soc_match, of_root);
 	if (!id) {
 		ret = -ENODEV;
 		goto free_soc;
@@ -147,8 +145,6 @@ static int __init imx8_soc_init(void)
 		goto free_rev;
 	}
 
-	of_node_put(root);
-
 	if (IS_ENABLED(CONFIG_ARM_IMX_CPUFREQ_DT))
 		platform_device_register_simple("imx-cpufreq-dt", -1, NULL, 0);
 
@@ -159,7 +155,6 @@ static int __init imx8_soc_init(void)
 		kfree(soc_dev_attr->revision);
 free_soc:
 	kfree(soc_dev_attr);
-	of_node_put(root);
 	return ret;
 }
 device_initcall(imx8_soc_init);
-- 
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH V2 1/2] soc: imx8: Fix potential kernel dump in error path
  2019-06-14  8:07 [PATCH V2 1/2] soc: imx8: Fix potential kernel dump in error path Anson.Huang
  2019-06-14  8:07 ` [PATCH V2 2/2] soc: imx8: Use existing of_root directly Anson.Huang
@ 2019-06-18  9:13 ` Shawn Guo
  1 sibling, 0 replies; 5+ messages in thread
From: Shawn Guo @ 2019-06-18  9:13 UTC (permalink / raw)
  To: Anson.Huang
  Cc: abel.vesa, viresh.kumar, s.hauer, linux-kernel, Linux-imx,
	kernel, leonard.crestez, festevam, linux-arm-kernel

On Fri, Jun 14, 2019 at 04:07:47PM +0800, Anson.Huang@nxp.com wrote:
> From: Anson Huang <Anson.Huang@nxp.com>
> 
> When SoC's revision value is 0, SoC driver will print out
> "unknown" in sysfs's revision node, this "unknown" is a
> static string which can NOT be freed, this will caused below
> kernel dump in later error path which calls kfree:
> 
> kernel BUG at mm/slub.c:3942!
> Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
> Modules linked in:
> CPU: 2 PID: 1 Comm: swapper/0 Not tainted 5.2.0-rc4-next-20190611-00023-g705146c-dirty #2197
> Hardware name: NXP i.MX8MQ EVK (DT)
> pstate: 60000005 (nZCv daif -PAN -UAO)
> pc : kfree+0x170/0x1b0
> lr : imx8_soc_init+0xc0/0xe4
> sp : ffff00001003bd10
> x29: ffff00001003bd10 x28: ffff00001121e0a0
> x27: ffff000011482000 x26: ffff00001117068c
> x25: ffff00001121e100 x24: ffff000011482000
> x23: ffff000010fe2b58 x22: ffff0000111b9ab0
> x21: ffff8000bd9dfba0 x20: ffff0000111b9b70
> x19: ffff7e000043f880 x18: 0000000000001000
> x17: ffff000010d05fa0 x16: ffff0000122e0000
> x15: 0140000000000000 x14: 0000000030360000
> x13: ffff8000b94b5bb0 x12: 0000000000000038
> x11: ffffffffffffffff x10: ffffffffffffffff
> x9 : 0000000000000003 x8 : ffff8000b9488147
> x7 : ffff00001003bc00 x6 : 0000000000000000
> x5 : 0000000000000003 x4 : 0000000000000003
> x3 : 0000000000000003 x2 : b8793acd604edf00
> x1 : ffff7e000043f880 x0 : ffff7e000043f888
> Call trace:
>  kfree+0x170/0x1b0
>  imx8_soc_init+0xc0/0xe4
>  do_one_initcall+0x58/0x1b8
>  kernel_init_freeable+0x1cc/0x288
>  kernel_init+0x10/0x100
>  ret_from_fork+0x10/0x18
> 
> This patch fixes this potential kernel dump when a chip's
> revision is "unknown", it is done by checking whether the
> revision space can be freed.
> 
> Fixes: a7e26f356ca1 ("soc: imx: Add generic i.MX8 SoC driver")
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>

Applied, thanks.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH V2 2/2] soc: imx8: Use existing of_root directly
  2019-06-14  8:07 ` [PATCH V2 2/2] soc: imx8: Use existing of_root directly Anson.Huang
@ 2019-06-18  9:14   ` Shawn Guo
  2019-06-18  9:44     ` Anson Huang
  0 siblings, 1 reply; 5+ messages in thread
From: Shawn Guo @ 2019-06-18  9:14 UTC (permalink / raw)
  To: Anson.Huang
  Cc: abel.vesa, viresh.kumar, s.hauer, linux-kernel, Linux-imx,
	kernel, leonard.crestez, festevam, linux-arm-kernel

On Fri, Jun 14, 2019 at 04:07:48PM +0800, Anson.Huang@nxp.com wrote:
> From: Anson Huang <Anson.Huang@nxp.com>
> 
> There is common of_root for reference, no need to find it
> from DT again, use of_root directly to make driver simple.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>

It cannot be applied.  Please resend by basing on my imx/drivers branch.

Shawn

> ---
> No changes.
> ---
>  drivers/soc/imx/soc-imx8.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/soc/imx/soc-imx8.c b/drivers/soc/imx/soc-imx8.c
> index 5c7f330..b459bf2 100644
> --- a/drivers/soc/imx/soc-imx8.c
> +++ b/drivers/soc/imx/soc-imx8.c
> @@ -105,7 +105,6 @@ static int __init imx8_soc_init(void)
>  {
>  	struct soc_device_attribute *soc_dev_attr;
>  	struct soc_device *soc_dev;
> -	struct device_node *root;
>  	const struct of_device_id *id;
>  	u32 soc_rev = 0;
>  	const struct imx8_soc_data *data;
> @@ -117,12 +116,11 @@ static int __init imx8_soc_init(void)
>  
>  	soc_dev_attr->family = "Freescale i.MX";
>  
> -	root = of_find_node_by_path("/");
> -	ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
> +	ret = of_property_read_string(of_root, "model", &soc_dev_attr->machine);
>  	if (ret)
>  		goto free_soc;
>  
> -	id = of_match_node(imx8_soc_match, root);
> +	id = of_match_node(imx8_soc_match, of_root);
>  	if (!id) {
>  		ret = -ENODEV;
>  		goto free_soc;
> @@ -147,8 +145,6 @@ static int __init imx8_soc_init(void)
>  		goto free_rev;
>  	}
>  
> -	of_node_put(root);
> -
>  	if (IS_ENABLED(CONFIG_ARM_IMX_CPUFREQ_DT))
>  		platform_device_register_simple("imx-cpufreq-dt", -1, NULL, 0);
>  
> @@ -159,7 +155,6 @@ static int __init imx8_soc_init(void)
>  		kfree(soc_dev_attr->revision);
>  free_soc:
>  	kfree(soc_dev_attr);
> -	of_node_put(root);
>  	return ret;
>  }
>  device_initcall(imx8_soc_init);
> -- 
> 2.7.4
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH V2 2/2] soc: imx8: Use existing of_root directly
  2019-06-18  9:14   ` Shawn Guo
@ 2019-06-18  9:44     ` Anson Huang
  0 siblings, 0 replies; 5+ messages in thread
From: Anson Huang @ 2019-06-18  9:44 UTC (permalink / raw)
  To: Shawn Guo
  Cc: Abel Vesa, viresh.kumar, s.hauer, linux-kernel, dl-linux-imx,
	kernel, Leonard Crestez, festevam, linux-arm-kernel

Hi, Shawn

> -----Original Message-----
> From: Shawn Guo <shawnguo@kernel.org>
> Sent: Tuesday, June 18, 2019 5:15 PM
> To: Anson Huang <anson.huang@nxp.com>
> Cc: s.hauer@pengutronix.de; kernel@pengutronix.de; festevam@gmail.com;
> Leonard Crestez <leonard.crestez@nxp.com>; viresh.kumar@linaro.org;
> Abel Vesa <abel.vesa@nxp.com>; linux-arm-kernel@lists.infradead.org;
> linux-kernel@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH V2 2/2] soc: imx8: Use existing of_root directly
> 
> On Fri, Jun 14, 2019 at 04:07:48PM +0800, Anson.Huang@nxp.com wrote:
> > From: Anson Huang <Anson.Huang@nxp.com>
> >
> > There is common of_root for reference, no need to find it from DT
> > again, use of_root directly to make driver simple.
> >
> > Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> > Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
> 
> It cannot be applied.  Please resend by basing on my imx/drivers branch.

OK, just resent, there is a soc driver patch in linux-next, previously I did it based on it.
Now I change it to your git repo, you could meet conflict during merge.

Thanks,
Anson

> 
> Shawn
> 
> > ---
> > No changes.
> > ---
> >  drivers/soc/imx/soc-imx8.c | 9 ++-------
> >  1 file changed, 2 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/soc/imx/soc-imx8.c b/drivers/soc/imx/soc-imx8.c
> > index 5c7f330..b459bf2 100644
> > --- a/drivers/soc/imx/soc-imx8.c
> > +++ b/drivers/soc/imx/soc-imx8.c
> > @@ -105,7 +105,6 @@ static int __init imx8_soc_init(void)  {
> >  	struct soc_device_attribute *soc_dev_attr;
> >  	struct soc_device *soc_dev;
> > -	struct device_node *root;
> >  	const struct of_device_id *id;
> >  	u32 soc_rev = 0;
> >  	const struct imx8_soc_data *data;
> > @@ -117,12 +116,11 @@ static int __init imx8_soc_init(void)
> >
> >  	soc_dev_attr->family = "Freescale i.MX";
> >
> > -	root = of_find_node_by_path("/");
> > -	ret = of_property_read_string(root, "model", &soc_dev_attr-
> >machine);
> > +	ret = of_property_read_string(of_root, "model",
> > +&soc_dev_attr->machine);
> >  	if (ret)
> >  		goto free_soc;
> >
> > -	id = of_match_node(imx8_soc_match, root);
> > +	id = of_match_node(imx8_soc_match, of_root);
> >  	if (!id) {
> >  		ret = -ENODEV;
> >  		goto free_soc;
> > @@ -147,8 +145,6 @@ static int __init imx8_soc_init(void)
> >  		goto free_rev;
> >  	}
> >
> > -	of_node_put(root);
> > -
> >  	if (IS_ENABLED(CONFIG_ARM_IMX_CPUFREQ_DT))
> >  		platform_device_register_simple("imx-cpufreq-dt", -1, NULL,
> 0);
> >
> > @@ -159,7 +155,6 @@ static int __init imx8_soc_init(void)
> >  		kfree(soc_dev_attr->revision);
> >  free_soc:
> >  	kfree(soc_dev_attr);
> > -	of_node_put(root);
> >  	return ret;
> >  }
> >  device_initcall(imx8_soc_init);
> > --
> > 2.7.4
> >
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-14  8:07 [PATCH V2 1/2] soc: imx8: Fix potential kernel dump in error path Anson.Huang
2019-06-14  8:07 ` [PATCH V2 2/2] soc: imx8: Use existing of_root directly Anson.Huang
2019-06-18  9:14   ` Shawn Guo
2019-06-18  9:44     ` Anson Huang
2019-06-18  9:13 ` [PATCH V2 1/2] soc: imx8: Fix potential kernel dump in error path Shawn Guo

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org infradead-linux-arm-kernel@archiver.kernel.org
	public-inbox-index linux-arm-kernel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox