fix(st-clock): correct stm32_clk_parse_fdt_by_name

The fdt_getprop() function sets the length to -1 if the property is not
found. We should then not use it later in stm32_clk_parse_fdt_by_name()
in that case. Directly set *nb to 0U and return 0 if the property is not
found.

Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
Change-Id: I19c5c953f392cdc768e0b1f3f240fc99a73a049c
This commit is contained in:
Yann Gautier 2022-04-05 15:16:28 +02:00 committed by Yann Gautier
parent b8eab512bf
commit 7417cda6ae
1 changed files with 8 additions and 5 deletions

View File

@ -1073,12 +1073,15 @@ int stm32_clk_parse_fdt_by_name(void *fdt, int node, const char *name, uint32_t
uint32_t i;
cell = fdt_getprop(fdt, node, name, &len);
if (cell != NULL) {
for (i = 0; i < ((uint32_t)len / sizeof(uint32_t)); i++) {
uint32_t val = fdt32_to_cpu(cell[i]);
if (cell == NULL) {
*nb = 0U;
return 0;
}
tab[i] = val;
}
for (i = 0; i < ((uint32_t)len / sizeof(uint32_t)); i++) {
uint32_t val = fdt32_to_cpu(cell[i]);
tab[i] = val;
}
*nb = (uint32_t)len / sizeof(uint32_t);