of/platform: Fix of_platform_device_destroy iteration of devices
of_platform_destroy does not work properly, since the tree population test was iterating on all devices having as its parent the given platform device. The check was intended to check whether any other platform or amba devices created by of_platform_populate were still populated, but instead checked for every kind of device. This is wrong, since platform devices typically create a subsystem regular device and set themselves as parents. Instead, go ahead and call the unregister functions for any devices created with of_platform_populate. The driver core will take care of unbinding drivers, and drivers are responsible for getting rid of any child devices that weren't created by of_platform_populate. Signed-off-by: Grant Likely <grant.likely@linaro.org> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
This commit is contained in:
Родитель
cd3de83f14
Коммит
75f353b613
|
@ -422,6 +422,7 @@ static int of_platform_bus_create(struct device_node *bus,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
of_node_set_flag(bus, OF_POPULATED_BUS);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,19 +509,13 @@ EXPORT_SYMBOL_GPL(of_platform_populate);
|
||||||
|
|
||||||
static int of_platform_device_destroy(struct device *dev, void *data)
|
static int of_platform_device_destroy(struct device *dev, void *data)
|
||||||
{
|
{
|
||||||
bool *children_left = data;
|
|
||||||
|
|
||||||
/* Do not touch devices not populated from the device tree */
|
/* Do not touch devices not populated from the device tree */
|
||||||
if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) {
|
if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED))
|
||||||
*children_left = true;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
/* Recurse, but don't touch this device if it has any children left */
|
/* Recurse for any nodes that were treated as busses */
|
||||||
if (of_platform_depopulate(dev) != 0) {
|
if (of_node_check_flag(dev->of_node, OF_POPULATED_BUS))
|
||||||
*children_left = true;
|
device_for_each_child(dev, NULL, of_platform_device_destroy);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dev->bus == &platform_bus_type)
|
if (dev->bus == &platform_bus_type)
|
||||||
platform_device_unregister(to_platform_device(dev));
|
platform_device_unregister(to_platform_device(dev));
|
||||||
|
@ -528,19 +523,15 @@ static int of_platform_device_destroy(struct device *dev, void *data)
|
||||||
else if (dev->bus == &amba_bustype)
|
else if (dev->bus == &amba_bustype)
|
||||||
amba_device_unregister(to_amba_device(dev));
|
amba_device_unregister(to_amba_device(dev));
|
||||||
#endif
|
#endif
|
||||||
else {
|
|
||||||
*children_left = true;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
of_node_clear_flag(dev->of_node, OF_POPULATED);
|
of_node_clear_flag(dev->of_node, OF_POPULATED);
|
||||||
|
of_node_clear_flag(dev->of_node, OF_POPULATED_BUS);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* of_platform_depopulate() - Remove devices populated from device tree
|
* of_platform_depopulate() - Remove devices populated from device tree
|
||||||
* @parent: device which childred will be removed
|
* @parent: device which children will be removed
|
||||||
*
|
*
|
||||||
* Complementary to of_platform_populate(), this function removes children
|
* Complementary to of_platform_populate(), this function removes children
|
||||||
* of the given device (and, recurrently, their children) that have been
|
* of the given device (and, recurrently, their children) that have been
|
||||||
|
@ -550,14 +541,9 @@ static int of_platform_device_destroy(struct device *dev, void *data)
|
||||||
* Returns 0 when all children devices have been removed or
|
* Returns 0 when all children devices have been removed or
|
||||||
* -EBUSY when some children remained.
|
* -EBUSY when some children remained.
|
||||||
*/
|
*/
|
||||||
int of_platform_depopulate(struct device *parent)
|
void of_platform_depopulate(struct device *parent)
|
||||||
{
|
{
|
||||||
bool children_left = false;
|
device_for_each_child(parent, NULL, of_platform_device_destroy);
|
||||||
|
|
||||||
device_for_each_child(parent, &children_left,
|
|
||||||
of_platform_device_destroy);
|
|
||||||
|
|
||||||
return children_left ? -EBUSY : 0;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(of_platform_depopulate);
|
EXPORT_SYMBOL_GPL(of_platform_depopulate);
|
||||||
|
|
||||||
|
|
|
@ -204,6 +204,7 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size)
|
||||||
#define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */
|
#define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */
|
||||||
#define OF_DETACHED 2 /* node has been detached from the device tree */
|
#define OF_DETACHED 2 /* node has been detached from the device tree */
|
||||||
#define OF_POPULATED 3 /* device already created for the node */
|
#define OF_POPULATED 3 /* device already created for the node */
|
||||||
|
#define OF_POPULATED_BUS 4 /* of_platform_populate recursed to children of this node */
|
||||||
|
|
||||||
#define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
|
#define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
|
||||||
#define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
|
#define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
|
||||||
|
|
|
@ -72,7 +72,7 @@ extern int of_platform_populate(struct device_node *root,
|
||||||
const struct of_device_id *matches,
|
const struct of_device_id *matches,
|
||||||
const struct of_dev_auxdata *lookup,
|
const struct of_dev_auxdata *lookup,
|
||||||
struct device *parent);
|
struct device *parent);
|
||||||
extern int of_platform_depopulate(struct device *parent);
|
extern void of_platform_depopulate(struct device *parent);
|
||||||
#else
|
#else
|
||||||
static inline int of_platform_populate(struct device_node *root,
|
static inline int of_platform_populate(struct device_node *root,
|
||||||
const struct of_device_id *matches,
|
const struct of_device_id *matches,
|
||||||
|
@ -81,10 +81,7 @@ static inline int of_platform_populate(struct device_node *root,
|
||||||
{
|
{
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
static inline int of_platform_depopulate(struct device *parent)
|
static inline void of_platform_depopulate(struct device *parent) { }
|
||||||
{
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _LINUX_OF_PLATFORM_H */
|
#endif /* _LINUX_OF_PLATFORM_H */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче