Skip to content

Commit

Permalink
dm: core: Rename ofnode_get_chosen_prop()
Browse files Browse the repository at this point in the history
This function is actually intended to read a string rather than a
property. All of its current callers use it that way. Also there is no way
to return the length of the property from this function.

Rename it to better indicate its purpose, using ofnode_read as the prefix
since this matches most other functions.

Also add some tests which are missing for these functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
  • Loading branch information
sjg20 authored and Michal Simek committed Aug 5, 2020
1 parent d797174 commit 19f6d41
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
2 changes: 2 additions & 0 deletions arch/sandbox/dts/test.dts
Expand Up @@ -774,6 +774,8 @@
chosen {
#address-cells = <1>;
#size-cells = <1>;
setting = "sunrise ohoka";
other-node = "/some-bus/c-test@5";
chosen-test {
compatible = "denx,u-boot-fdt-test";
reg = <9 1>;
Expand Down
2 changes: 1 addition & 1 deletion board/theobroma-systems/puma_rk3399/puma-rk3399.c
Expand Up @@ -49,7 +49,7 @@ static void setup_iodomain(void)
static int setup_boottargets(void)
{
const char *boot_device =
ofnode_get_chosen_prop("u-boot,spl-boot-device");
ofnode_read_chosen_string("u-boot,spl-boot-device");
char *env_default, *env;

if (!boot_device) {
Expand Down
2 changes: 1 addition & 1 deletion board/xilinx/common/board.c
Expand Up @@ -23,7 +23,7 @@ int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
return -ENODEV;

debug("%s: Path to EEPROM %s\n", __func__,
ofnode_get_chosen_prop("xlnx,eeprom"));
ofnode_read_chosen_string("xlnx,eeprom"));

ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev);
if (ret)
Expand Down
4 changes: 2 additions & 2 deletions drivers/core/ofnode.c
Expand Up @@ -419,7 +419,7 @@ ofnode ofnode_path(const char *path)
return offset_to_ofnode(fdt_path_offset(gd->fdt_blob, path));
}

const char *ofnode_get_chosen_prop(const char *name)
const char *ofnode_read_chosen_string(const char *name)
{
ofnode chosen_node;

Expand All @@ -432,7 +432,7 @@ ofnode ofnode_get_chosen_node(const char *name)
{
const char *prop;

prop = ofnode_get_chosen_prop(name);
prop = ofnode_read_chosen_string(name);
if (!prop)
return ofnode_null();

Expand Down
9 changes: 5 additions & 4 deletions include/dm/ofnode.h
Expand Up @@ -510,14 +510,15 @@ int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
ofnode ofnode_path(const char *path);

/**
* ofnode_get_chosen_prop() - get the value of a chosen property
* ofnode_read_chosen_string() - get the string value of a chosen property
*
* This looks for a property within the /chosen node and returns its value
* This looks for a property within the /chosen node and returns its value,
* checking that it is a valid nul-terminated string
*
* @propname: Property name to look for
* @return property value if found, else NULL
* @return string value if found, else NULL
*/
const char *ofnode_get_chosen_prop(const char *propname);
const char *ofnode_read_chosen_string(const char *propname);

/**
* ofnode_get_chosen_node() - get the chosen node
Expand Down
21 changes: 21 additions & 0 deletions test/dm/ofnode.c
Expand Up @@ -58,3 +58,24 @@ static int dm_test_ofnode_fmap(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);

static int dm_test_ofnode_read_chosen(struct unit_test_state *uts)
{
const char *str;
ofnode node;

str = ofnode_read_chosen_string("setting");
ut_assertnonnull(str);
ut_asserteq_str("sunrise ohoka", str);
ut_asserteq_ptr(NULL, ofnode_read_chosen_string("no-setting"));

node = ofnode_get_chosen_node("other-node");
ut_assert(ofnode_valid(node));
ut_asserteq_str("c-test@5", ofnode_get_name(node));

node = ofnode_get_chosen_node("setting");
ut_assert(!ofnode_valid(node));

return 0;
}
DM_TEST(dm_test_ofnode_read_chosen, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);

0 comments on commit 19f6d41

Please sign in to comment.