soc: imx8: Fix potential kernel dump in error path
PATCH 1/2 soc: imx8: Fix potential kernel dump in error path
From: Anson Huang <[email protected]>
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 always printing out the revision value.
--- drivers/soc/imx/soc-imx8.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/soc/imx/soc-imx8.c +4 -6
@@ -96,11 +96,6 @@ static const struct of_device_id imx8_soc_match[] = { { } }; -#define imx8_revision (soc_rev) \ - soc_rev ? \ - kasprintf(GFP_KERNEL, "%d.%d", (soc_rev >> 4) & 0xf, soc_rev & 0xf) : \ - "unknown" -static int __init imx8_soc_init (void ) {struct soc_device_attribute *soc_dev_attr;
@@ -135,7 +130,10 @@ static int __init imx8_soc_init(void) soc_rev = data->soc_revision (); } - soc_dev_attr->revision =imx8_revision (soc_rev); + soc_dev_attr->revision =kasprintf (GFP_KERNEL , +"%d.%d" , + (soc_rev >>4 ) &0xf , + soc_rev &0xf );if (!soc_dev_attr->revision) { ret = -ENOMEM ; goto free_soc;
Signature · 1 line
2.7.4
PATCH 2/2 soc: imx8: Use existing of_root directly
From: Anson Huang <[email protected]>
There is common of_root for reference, no need to find it from DT again, use of_root directly to make driver simple.
--- drivers/soc/imx/soc-imx8.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/soc/imx/soc-imx8.c +2 -7
@@ -100,7 +100,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;
@@ -112,12 +111,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;
@@ -145,8 +143,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 );
@@ -156,7 +152,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);
Signature · 1 line
2.7.4
RE: [PATCH 2/2] soc: imx8: Use existing of_root directly
Quoted 7 lines
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, June 12, 2019 11:36 AMThere is common
of_rootfor reference, no need to find it from DT again, useof_rootdirectly to make driver simple.Signed-off-by Anson Huang <[email protected]>
Regards
Dong Aisheng
Quoted 64 lines
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, June 12, 2019 11:36 AMQuoted 1 line
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/0xe4sp :
ffff00001003bd10
x29:ffff00001003bd10x28:ffff00001121e0a0
x27:ffff000011482000x26:ffff00001117068c
x25:ffff00001121e100x24:ffff000011482000
x23:ffff000010fe2b58x22:ffff0000111b9ab0
x21:ffff8000bd9dfba0x20:ffff0000111b9b70
x19:ffff7e000043f880x18: 0000000000001000
x17:ffff000010d05fa0x16:ffff0000122e0000
x15: 0140000000000000 x14: 0000000030360000
x13:ffff8000b94b5bb0x12: 0000000000000038
x11: ffffffffffffffff x10: ffffffffffffffff
x9 : 0000000000000003 x8 :ffff8000b9488147
x7 :ffff00001003bc00x6 : 0000000000000000
x5 : 0000000000000003 x4 : 0000000000000003
x3 : 0000000000000003 x2 :b8793acd604edf00
x1 :ffff7e000043f880x0 :ffff7e000043f888Call 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/0x18This patch fixes this potential kernel dump when a chip's revision is "unknown", it is done by always printing out the revision value.
Fixes a7e26f356ca1 ("soc: imx: Add generic i.MX8 SoC driver")Signed-off-by Anson Huang <[email protected]>--- drivers/soc/imx/soc-imx8.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/soc/imx/soc-imx8.c index renamed from drivers/soc/imx/soc-imx8.c +0
-002309a2..86b925a 100644
drivers/soc/imx/soc-imx8.c +0
-5@@ -96,11 +96,6 @@ static const struct of_device_id imx8_soc_match[] = { { } }; -#define imx8_revision (soc_rev) \ - soc_rev ? \ - kasprintf(GFP_KERNEL, "%d.%d", (soc_rev >> 4) & 0xf, soc_rev & 0xf) : \ - "unknown" -static int __init imx8_soc_init (void ) { struct soc_device_attribute *soc_dev_attr; @@ -135,7 +130,10 @@static int
__initimx8_soc_init(void)
drivers/soc/imx/soc-imx8.c static int __init imx8_soc_init(void) · line 136
Quoted 8 lines
drivers/soc/imx/soc-imx8.c +4
-1soc_rev = data->soc_revision (); } - soc_dev_attr->revision =imx8_revision (soc_rev); + soc_dev_attr->revision =kasprintf (GFP_KERNEL , +"%d.%d" , + (soc_rev >>4 ) &0xf , + soc_rev &0xf );
The revision "0.0" is confusing.
I might prefer to check "unknown" before free.
Regards
Dong Aisheng
Quoted 5 lines
drivers/soc/imx/soc-imx8.c +0
-1if (!soc_dev_attr->revision) { ret = -ENOMEM ; goto free_soc; --2.7.4