Skip to content

Commit

Permalink
libfdt: Add support for disabling rollback handling
Browse files Browse the repository at this point in the history
Allow enabling FDT_ASSUME_NO_ROLLBACK to disable rolling back after a
failed operation.

Signed-off-by: Simon Glass <[email protected]>
Reviewed-by: David Gibson <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: David Gibson <[email protected]>
  • Loading branch information
sjg20 authored and dgibson committed Feb 24, 2020
1 parent 77563ae commit fc03c4a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions libfdt/fdt_rw.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ static int fdt_splice_string_(void *fdt, int newlen)
return 0;
}

/**
* fdt_find_add_string_() - Find or allocate a string
*
* @fdt: pointer to the device tree to check/adjust
* @s: string to find/add
* @allocated: Set to 0 if the string was found, 1 if not found and so
* allocated. Ignored if can_assume(NO_ROLLBACK)
* @return offset of string in the string table (whether found or added)
*/
static int fdt_find_add_string_(void *fdt, const char *s, int *allocated)
{
char *strtab = (char *)fdt + fdt_off_dt_strings(fdt);
Expand All @@ -122,7 +131,8 @@ static int fdt_find_add_string_(void *fdt, const char *s, int *allocated)
int len = strlen(s) + 1;
int err;

*allocated = 0;
if (!can_assume(NO_ROLLBACK))
*allocated = 0;

p = fdt_find_string_(strtab, fdt_size_dt_strings(fdt), s);
if (p)
Expand All @@ -134,7 +144,8 @@ static int fdt_find_add_string_(void *fdt, const char *s, int *allocated)
if (err)
return err;

*allocated = 1;
if (!can_assume(NO_ROLLBACK))
*allocated = 1;

memcpy(new, s, len);
return (new - strtab);
Expand Down Expand Up @@ -208,7 +219,8 @@ static int fdt_add_property_(void *fdt, int nodeoffset, const char *name,

err = fdt_splice_struct_(fdt, *prop, 0, proplen);
if (err) {
if (allocated)
/* Delete the string if we failed to add it */
if (!can_assume(NO_ROLLBACK) && allocated)
fdt_del_last_string_(fdt, name);
return err;
}
Expand Down

0 comments on commit fc03c4a

Please sign in to comment.