9
0
Fork 0
barebox/common
Sascha Hauer 1a9e93cc81 drivers/base: fix corrupt device tree
dev_add_child is a very unsafe function. If called multiple times
it allows setting the same device to different parents thus corrupting
the siblings list. This happens regularly since:

| commit c2e568d19c
| Author: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
| Date:   Sat Nov 3 16:11:05 2012 +0100
|
|    bus: add bus device
|
|    automatically add it as parent of any bus device if none already specified
|
|    we have now a nice output per bus

If for example a FATfs is mounted this nice output per bus often ends with:

>     `---- fat0
>     `---- 0
>          `---- 0x86f0000087020031-0x86f000410df27124: /dev/<NULL>
>          `---- sram00
>               `---- 0x00000000-0xffffffffffffffff: /dev/<NULL>
>               `---- 0x00000000-0xffffffffffffffff: /dev/<NULL>
>               unable to handle NULL pointer dereference at address 0x0000000c
> pc : [<87f08a20>]    lr : [<87f08a04>]
> sp : 86eff8c0  ip : 87f3fbde  fp : ffffffff
> r10: ffffffff  r9 : 00000000  r8 : 00000003
> r7 : 86f075b8  r6 : 00000002  r5 : ffffffec  r4 : 86f07544
> r3 : 00000000  r2 : 43f900b4  r1 : 00000020  r0 : 00000005
> Flags: Nzcv  IRQs off  FIQs off  Mode SVC_32
> [<87f08a20>] (do_devinfo_subtree+0x90/0x130) from [<87f08a90>] (do_devinfo_subtree+0x100/0x130)
>
> [<87f3e070>] (unwind_backtrace+0x0/0x90) from [<87f28514>] (panic+0x28/0x3c)
> [<87f28514>] (panic+0x28/0x3c) from [<87f3e4b8>] (do_exception+0x10/0x14)
> [<87f3e4b8>] (do_exception+0x10/0x14) from [<87f3e544>] (do_data_abort+0x2c/0x38)
> [<87f3e544>] (do_data_abort+0x2c/0x38) from [<87f3e268>] (data_abort+0x48/0x60)

This patch fixes this by adding a device to its parents children list in
register_device so that dev_add_child is no longer needed. This function
is removed from the tree. Now callers of register_device have to clearly
set the parent *before* registering a device.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reported-by: Jan Lübbe <jlu@pengutronix.de>
2012-12-12 15:04:27 +01:00
..
.gitignore update .gitignore files for linker scripts 2009-01-21 23:28:14 +01:00
Kconfig Merge branch 'kconfig' 2012-12-08 12:22:21 +01:00
Makefile Add in-system barebox update infrastructure 2012-10-17 20:23:41 +02:00
bbu.c barebox update: fix finding default handler 2012-12-03 09:57:41 +01:00
binfmt.c Introduce binfmt support 2012-04-18 20:14:12 +08:00
block.c Treewide: remove address of the Free Software Foundation 2012-09-17 10:57:41 +02:00
bootargs.c Treewide: remove address of the Free Software Foundation 2012-09-17 10:57:41 +02:00
clock.c clock: introduce non interruptible timeout 2012-10-29 22:31:18 +01:00
command.c command: return 1 on unknown command 2012-11-01 16:31:07 +01:00
complete.c environment variables: use linux list 2012-10-30 10:24:12 +01:00
console.c drivers/base: fix corrupt device tree 2012-12-12 15:04:27 +01:00
console_simple.c console: use debug_ll before the console is available 2012-10-30 10:23:50 +01:00
date.c Treewide: remove address of the Free Software Foundation 2012-09-17 10:57:41 +02:00
digest.c Treewide: remove address of the Free Software Foundation 2012-09-17 10:57:41 +02:00
dlmalloc.c rename include/mem_malloc.h to include/memory.h 2011-09-23 16:32:48 +02:00
dummy_malloc.c dummy_malloc: add calloc support 2012-01-11 09:36:30 +01:00
env.c environment variables: use linux list 2012-10-30 10:24:12 +01:00
environment.c loadenv: allow more fine grained environment loading 2012-11-29 20:23:04 +01:00
filetype.c add ext fs detection support 2012-12-03 11:23:25 +01:00
globalvar.c globalvar: add support to set a value to of all globalvars beginning with 'match' 2012-09-14 00:46:00 +08:00
hush.c Treewide: remove address of the Free Software Foundation 2012-09-17 10:57:41 +02:00
image.c Merge branch 'for-next/remove-fsf-address' 2012-10-03 21:12:48 +02:00
kallsyms.c kallsyms/printk: enable symbol printing support (%pS) 2011-03-10 14:50:16 +01:00
meminfo.c common: split out meminfo output and make it optional 2012-09-06 12:43:36 +02:00
memory.c memory: return error in barebox_add_memory_bank 2012-10-08 00:33:21 +02:00
memsize.c Treewide: remove address of the Free Software Foundation 2012-09-17 10:57:41 +02:00
menu.c Treewide: remove address of the Free Software Foundation 2012-09-17 10:57:41 +02:00
misc.c Treewide: remove address of the Free Software Foundation 2012-09-17 10:57:41 +02:00
module.c Treewide: remove address of the Free Software Foundation 2012-09-17 10:57:41 +02:00
module.lds.S Treewide: remove address of the Free Software Foundation 2012-09-17 10:57:41 +02:00
oftree.c of: add devicetree probing support 2012-09-14 11:47:42 +02:00
parser.c parser: use debug macros 2010-11-01 11:44:48 +01:00
partitions.c Merge branch 'for-next/misc' 2012-11-16 14:01:34 +01:00
password.c password: fixed underflow on <backspace> 2012-12-05 10:38:27 +01:00
poller.c Add generic poll infrastructure 2010-12-20 09:28:21 +01:00
reset_source.c Enable a way to provide the reason for "being here" 2012-07-18 16:21:43 +02:00
resource.c resource: statically initialize iomem resource 2012-10-07 12:58:10 +02:00
s_record.c Treewide: remove address of the Free Software Foundation 2012-09-17 10:57:41 +02:00
startup.c loadenv: allow more fine grained environment loading 2012-11-29 20:23:04 +01:00
tlsf.c tlsf: Use NULL instead of 0 for returning NULL pointers 2012-06-30 22:34:54 +02:00
tlsf_malloc.c Treewide: remove address of the Free Software Foundation 2012-09-17 10:57:41 +02:00
tlsfbits.h tlsf: remove unused stuff from tlsfbits.h 2011-12-23 11:29:10 +01:00
uimage.c Merge branch 'for-next/tftp' 2012-12-07 16:43:24 +01:00
version.c of: Print model name in banner 2012-10-09 20:57:23 +02:00