libfdt: overlay: Refactor overlay_fixup_phandle
Refactored overlay_fixup_phandle to optimize efficiency by moving the phandle lookup logic based on label outside the overlay_fixup_one_phandle call. This avoids redundant phandle lookups when a single label is associated with multiple modifications. Signed-off-by: Zheng Guangyuan <1628513611@qq.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>main
parent
4dd831affd
commit
ae26223a05
|
@ -315,7 +315,7 @@ static int overlay_update_local_references(void *fdto, uint32_t delta)
|
||||||
* @name: Name of the property holding the phandle reference in the overlay
|
* @name: Name of the property holding the phandle reference in the overlay
|
||||||
* @name_len: number of name characters to consider
|
* @name_len: number of name characters to consider
|
||||||
* @poffset: Offset within the overlay property where the phandle is stored
|
* @poffset: Offset within the overlay property where the phandle is stored
|
||||||
* @label: Label of the node referenced by the phandle
|
* @phandle: Phandle referencing the node
|
||||||
*
|
*
|
||||||
* overlay_fixup_one_phandle() resolves an overlay phandle pointing to
|
* overlay_fixup_one_phandle() resolves an overlay phandle pointing to
|
||||||
* a node in the base device tree.
|
* a node in the base device tree.
|
||||||
|
@ -332,30 +332,14 @@ static int overlay_fixup_one_phandle(void *fdt, void *fdto,
|
||||||
int symbols_off,
|
int symbols_off,
|
||||||
const char *path, uint32_t path_len,
|
const char *path, uint32_t path_len,
|
||||||
const char *name, uint32_t name_len,
|
const char *name, uint32_t name_len,
|
||||||
int poffset, const char *label)
|
int poffset, uint32_t phandle)
|
||||||
{
|
{
|
||||||
const char *symbol_path;
|
|
||||||
uint32_t phandle;
|
|
||||||
fdt32_t phandle_prop;
|
fdt32_t phandle_prop;
|
||||||
int symbol_off, fixup_off;
|
int fixup_off;
|
||||||
int prop_len;
|
|
||||||
|
|
||||||
if (symbols_off < 0)
|
if (symbols_off < 0)
|
||||||
return symbols_off;
|
return symbols_off;
|
||||||
|
|
||||||
symbol_path = fdt_getprop(fdt, symbols_off, label,
|
|
||||||
&prop_len);
|
|
||||||
if (!symbol_path)
|
|
||||||
return prop_len;
|
|
||||||
|
|
||||||
symbol_off = fdt_path_offset(fdt, symbol_path);
|
|
||||||
if (symbol_off < 0)
|
|
||||||
return symbol_off;
|
|
||||||
|
|
||||||
phandle = fdt_get_phandle(fdt, symbol_off);
|
|
||||||
if (!phandle)
|
|
||||||
return -FDT_ERR_NOTFOUND;
|
|
||||||
|
|
||||||
fixup_off = fdt_path_offset_namelen(fdto, path, path_len);
|
fixup_off = fdt_path_offset_namelen(fdto, path, path_len);
|
||||||
if (fixup_off == -FDT_ERR_NOTFOUND)
|
if (fixup_off == -FDT_ERR_NOTFOUND)
|
||||||
return -FDT_ERR_BADOVERLAY;
|
return -FDT_ERR_BADOVERLAY;
|
||||||
|
@ -394,6 +378,10 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,
|
||||||
const char *value;
|
const char *value;
|
||||||
const char *label;
|
const char *label;
|
||||||
int len;
|
int len;
|
||||||
|
const char *symbol_path;
|
||||||
|
int prop_len;
|
||||||
|
int symbol_off;
|
||||||
|
uint32_t phandle;
|
||||||
|
|
||||||
value = fdt_getprop_by_offset(fdto, property,
|
value = fdt_getprop_by_offset(fdto, property,
|
||||||
&label, &len);
|
&label, &len);
|
||||||
|
@ -404,6 +392,18 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
symbol_path = fdt_getprop(fdt, symbols_off, label, &prop_len);
|
||||||
|
if (!symbol_path)
|
||||||
|
return prop_len;
|
||||||
|
|
||||||
|
symbol_off = fdt_path_offset(fdt, symbol_path);
|
||||||
|
if (symbol_off < 0)
|
||||||
|
return symbol_off;
|
||||||
|
|
||||||
|
phandle = fdt_get_phandle(fdt, symbol_off);
|
||||||
|
if (!phandle)
|
||||||
|
return -FDT_ERR_NOTFOUND;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
const char *path, *name, *fixup_end;
|
const char *path, *name, *fixup_end;
|
||||||
const char *fixup_str = value;
|
const char *fixup_str = value;
|
||||||
|
@ -445,7 +445,7 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,
|
||||||
|
|
||||||
ret = overlay_fixup_one_phandle(fdt, fdto, symbols_off,
|
ret = overlay_fixup_one_phandle(fdt, fdto, symbols_off,
|
||||||
path, path_len, name, name_len,
|
path, path_len, name, name_len,
|
||||||
poffset, label);
|
poffset, phandle);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
} while (len > 0);
|
} while (len > 0);
|
||||||
|
|
Loading…
Reference in New Issue