mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-09 19:16:02 +00:00
LibDeviceTree: Fix stale pointers in phandle and parent handling
We need to set them after we've created the full tree, as otherwise the HashMap containing the nodes may reallocate and invalidate the pointers.
This commit is contained in:
parent
b2377f1f9c
commit
ffa9875fa6
Notes:
sideshowbarker
2024-07-16 18:26:46 +09:00
Author: https://github.com/Hendiadyoin1
Commit: ffa9875fa6
Pull-request: https://github.com/SerenityOS/serenity/pull/24141
Reviewed-by: https://github.com/ADKaster ✅
2 changed files with 65 additions and 8 deletions
|
@ -13,6 +13,7 @@
|
|||
#include <AK/IterationDecision.h>
|
||||
#include <AK/MemoryStream.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/RecursionDecision.h>
|
||||
#include <AK/Span.h>
|
||||
|
||||
namespace DeviceTree {
|
||||
|
@ -168,6 +169,28 @@ public:
|
|||
// bonus points if it could automatically recurse in the tree under some conditions,
|
||||
// like "simple-bus" or "pci-bridge" nodes
|
||||
|
||||
auto for_each_node(CallableAs<ErrorOr<RecursionDecision>, StringView, DeviceTreeNodeView const&> auto callback) const
|
||||
{
|
||||
auto iterate = [&](auto self, StringView name, DeviceTreeNodeView const& node) -> ErrorOr<RecursionDecision> {
|
||||
auto result = TRY(callback(name, node));
|
||||
|
||||
if (result == RecursionDecision::Recurse) {
|
||||
for (auto const& [name, child] : node.children()) {
|
||||
auto child_result = TRY(self(self, name, child));
|
||||
|
||||
if (child_result == RecursionDecision::Break)
|
||||
return RecursionDecision::Break;
|
||||
}
|
||||
|
||||
return RecursionDecision::Continue;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
return iterate(iterate, "/"sv, *this);
|
||||
}
|
||||
|
||||
DeviceTreeNodeView const* phandle(u32 phandle) const
|
||||
{
|
||||
if (phandle >= m_phandles.size())
|
||||
|
@ -184,6 +207,28 @@ private:
|
|||
{
|
||||
}
|
||||
|
||||
auto for_each_node(CallableAs<ErrorOr<RecursionDecision>, StringView, DeviceTreeNodeView&> auto callback)
|
||||
{
|
||||
auto iterate = [&](auto self, StringView name, DeviceTreeNodeView& node) -> ErrorOr<RecursionDecision> {
|
||||
auto result = TRY(callback(name, node));
|
||||
|
||||
if (result == RecursionDecision::Recurse) {
|
||||
for (auto& [name, child] : node.children()) {
|
||||
auto child_result = TRY(self(self, name, child));
|
||||
|
||||
if (child_result == RecursionDecision::Break)
|
||||
return RecursionDecision::Break;
|
||||
}
|
||||
|
||||
return RecursionDecision::Continue;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
return iterate(iterate, "/"sv, *this);
|
||||
}
|
||||
|
||||
ErrorOr<void> set_phandle(u32 phandle, DeviceTreeNodeView* node)
|
||||
{
|
||||
if (m_phandles.size() > phandle && m_phandles[phandle] != nullptr)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue