[PATCH] dm: uclass: allow phandle < -1 with u32 type

Jianqun Xu jay.xu at rock-chips.com
Fri Jan 15 01:43:11 CET 2021


First, the uclass_find_device_by_phandle will try to get phandle of device node
by name, calls the dev_read_u32_default, the function always return the
argument 'u32 def', as following:
	ofnode_read_u32_default(ofnode node, const char *propname, u32 def)
		assert(ofnode_valid(node));
		ofnode_read_u32(node, propname, &def);
		return def;

In this case, the 'def' has been intalized to '-1'.

Second, the phandle of fdt is generated by get_node_phandle in livetree,
which is part of dtc script tool, as following:
	get_node_phandle(struct node *root, struct node *node)
		static cell_t phandle = 1;
		if ((node->phandle != 0) && (node->phandle != -1))
			return node->phandle;
		while (get_node_by_phandle(root, phandle))
			phandle++;

The cell_t is defined by 'typedef uint32_t cell_t'.

Gernerally, the valid phandle of fdt is from 1 to -2, if dev_read_u32_default
return '-1' means the 'u32 def' keeps the intalized value.

Signed-off-by: Jianqun Xu <jay.xu at rock-chips.com>
---
 drivers/core/uclass.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index c3f1b73cd6..86cc04ecac 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -385,12 +385,12 @@ int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent,
 {
 	struct udevice *dev;
 	struct uclass *uc;
-	int find_phandle;
+	u32 find_phandle;
 	int ret;
 
 	*devp = NULL;
 	find_phandle = dev_read_u32_default(parent, name, -1);
-	if (find_phandle <= 0)
+	if (find_phandle == -1)
 		return -ENOENT;
 	ret = uclass_get(id, &uc);
 	if (ret)
-- 
2.25.1





More information about the U-Boot mailing list