Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pylibfdt/libfdt.i
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ class FdtSw(FdtRo):
device tree. This will be increased automatically as needed as new items
are added to the tree.
"""
INC_SIZE = 1024 # Expand size by this much when out of space
INC_SIZE = 1024 # Expand size by at least this much when out of space

def __init__(self, size_hint=None):
"""Create a new FdtSw object
Expand Down Expand Up @@ -901,14 +901,18 @@ class FdtSw(FdtRo):
-NOSPACE then the FDT will be expanded to have more space, and True will
be returned, indicating that the operation needs to be tried again.

Each expansion copies the whole tree into a new buffer, so the size is
at least doubled rather than grown by a fixed amount, to keep the total
amount of copying proportional to the size of the tree.

Args:
val: Return value from the operation that was attempted

Returns:
True if the operation must be retried, else False
"""
if check_err(val, QUIET_NOSPACE) < 0:
self.resize(len(self._fdt) + self.INC_SIZE)
self.resize(len(self._fdt) + max(len(self._fdt), self.INC_SIZE))
return True
return False

Expand Down
Loading