libfdt: Add fdt_setprop_empty()
Device trees can contain empty (zero length) properties, which are often used as boolean flags. These can already be created using fdt_setprop() passing a length of zero and a pointer which is ignored. It is safe to pass NULL, but that may not be obvious from the interface. To make it clearer, add an fdt_setprop_empty() helper macro. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
@@ -1527,6 +1527,36 @@ static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
|
|||||||
#define fdt_setprop_string(fdt, nodeoffset, name, str) \
|
#define fdt_setprop_string(fdt, nodeoffset, name, str) \
|
||||||
fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
|
fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fdt_setprop_empty - set a property to an empty value
|
||||||
|
* @fdt: pointer to the device tree blob
|
||||||
|
* @nodeoffset: offset of the node whose property to change
|
||||||
|
* @name: name of the property to change
|
||||||
|
*
|
||||||
|
* fdt_setprop_empty() sets the value of the named property in the
|
||||||
|
* given node to an empty (zero length) value, or creates a new empty
|
||||||
|
* property if it does not already exist.
|
||||||
|
*
|
||||||
|
* This function may insert or delete data from the blob, and will
|
||||||
|
* therefore change the offsets of some existing nodes.
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* 0, on success
|
||||||
|
* -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
||||||
|
* contain the new property value
|
||||||
|
* -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
||||||
|
* -FDT_ERR_BADLAYOUT,
|
||||||
|
* -FDT_ERR_BADMAGIC,
|
||||||
|
* -FDT_ERR_BADVERSION,
|
||||||
|
* -FDT_ERR_BADSTATE,
|
||||||
|
* -FDT_ERR_BADSTRUCTURE,
|
||||||
|
* -FDT_ERR_BADLAYOUT,
|
||||||
|
* -FDT_ERR_TRUNCATED, standard meanings
|
||||||
|
*/
|
||||||
|
#define fdt_setprop_empty(fdt, nodeoffset, name) \
|
||||||
|
fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fdt_appendprop - append to or create a property
|
* fdt_appendprop - append to or create a property
|
||||||
* @fdt: pointer to the device tree blob
|
* @fdt: pointer to the device tree blob
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ int main(int argc, char *argv[])
|
|||||||
TEST_STRING_1);
|
TEST_STRING_1);
|
||||||
|
|
||||||
verbose_printf("Old string value was \"%s\"\n", strp);
|
verbose_printf("Old string value was \"%s\"\n", strp);
|
||||||
err = fdt_setprop(fdt, 0, "prop-str", NULL, 0);
|
err = fdt_setprop_empty(fdt, 0, "prop-str");
|
||||||
if (err)
|
if (err)
|
||||||
FAIL("Failed to empty \"prop-str\": %s",
|
FAIL("Failed to empty \"prop-str\": %s",
|
||||||
fdt_strerror(err));
|
fdt_strerror(err));
|
||||||
|
|||||||
Reference in New Issue
Block a user