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 c2e568d
| 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>
WIP_next-LS master next stable/v2013.05 stable/v2013.06 stable/v2013.07 stable/v2013.08 stable/v2013.10 stable/v2014.05 stable/v2014.06 stable/v2014.07 stable/v2014.08 stable/v2014.09 stable/v2014.10 stable/v2014.11 stable/v2014.12 stable/v2015.01 stable/v2015.02 stable/v2017.05 stable/v2017.06 stable/v2017.07 stable/v2017.11 stable/v2018.07 stable/v2018.09 stable/v2018.12 work/fit-support v2020.07.0 v2020.06.0 v2020.05.0 v2020.04.0 v2020.03.0 v2020.02.0 v2020.01.0 v2019.12.0 v2019.11.0 v2019.10.0 v2019.09.0 v2019.08.1 v2019.08.0 v2019.07.0 v2019.06.1 v2019.06.0 v2019.05.0 v2019.04.0 v2019.03.0 v2019.02.0 v2019.01.0 v2018.12.0 v2018.11.0 v2018.10.0 v2018.09.1 v2018.09.0 v2018.08.1 v2018.08.0 v2018.07.2 v2018.07.1 v2018.07.0 v2018.06.0 v2018.05.0 v2018.04.0 v2018.03.0 v2018.02.0 v2018.01.0 v2017.12.0 v2017.11.0 v2017.10.0 v2017.09.0 v2017.08.0 v2017.07.1 v2017.07.0 v2017.06.2 v2017.06.1 v2017.06.0 v2017.05.4 v2017.05.3 v2017.05.2 v2017.05.1 v2017.05.0 v2017.04.0 v2017.03.0 v2017.02.0 v2017.01.0 v2016.11.0 v2016.10.0 v2016.09.0 v2016.08.0 v2016.07.0 v2016.06.0 v2016.05.0 v2016.04.0 v2016.03.0 v2016.02.0 v2016.01.0 v2015.12.0 v2015.11.0 v2015.10.0 v2015.09.0 v2015.08.0 v2015.07.0 v2015.06.0 v2015.05.0 v2015.04.0 v2015.03.0 v2015.02.0 v2015.01.0 v2014.12.0 v2014.11.0 v2014.10.0 v2014.09.0 v2014.08.0 v2014.07.0 v2014.06.0 v2014.05.0 v2014.04.0 v2014.03.0 v2014.02.0 v2014.01.0 v2013.12.0 v2013.11.0 v2013.10.1 v2013.10.0 v2013.09.0 v2013.08.1 v2013.08.0 v2013.07.0 v2013.06.1 v2013.06.0 v2013.05.1 v2013.05.0 v2013.04.0 v2013.03.0 v2013.02.0 v2013.01.0
1 parent c7c9c88 commit 1a9e93cc81dbae55743c0dafae4bd6ac8241e8a3
@Sascha Hauer Sascha Hauer authored on 12 Dec 2012
Showing 12 changed files
View
common/console.c
View
drivers/base/driver.c
View
drivers/i2c/i2c.c
View
drivers/mci/mci-core.c
View
drivers/mtd/core.c
View
drivers/net/phy/mdio_bus.c
View
drivers/net/phy/phy.c
View
drivers/spi/spi.c
View
drivers/w1/w1.c
View
fs/fs.c
View
include/driver.h
View
net/eth.c