diff --git a/board/nm/nrhw20/board.c b/board/nm/nrhw20/board.c index 265020fb8e..e278c2f5ae 100644 --- a/board/nm/nrhw20/board.c +++ b/board/nm/nrhw20/board.c @@ -1273,33 +1273,55 @@ static void ft_enable_node(void* blob, const char* name) static void ft_set_gpio_name(void *blob, const char* gpio, int pin, const char* name) { int node_ofs = fdt_path_offset(blob, gpio); - if (node_ofs != -1) { - const struct fdt_property* prop = fdt_get_property(blob, node_ofs, "gpio-line-names", NULL); - if (prop != NULL) { - const char* text; - int pos = 0; - int i; - char buffer[512]; + int gpios = -1; + const char* text; + int pos = 0; + int i; + char buffer[512]; - /* TODO: Determine number of entries from ngpios field */ + if (node_ofs == -1) { + printf("Can't find node %s\n", gpio); + goto end; + } - for (i=0; i<32; i++) { - if (i == pin) { - /* Take provided name if GPIO pin is matched */ - text = name; - } - else { - /* Take existing name from strin list */ - (void)fdt_get_string_index(blob, node_ofs, "gpio-line-names", i, &text); - } - /* Add name to new string list */ - strncpy(buffer+pos, text, sizeof(buffer)-pos); - pos += strlen(text) + 1; - } + /* get number of IOs in node */ + gpios = fdt_getprop_u32_default_node(blob, node_ofs, 0, "ngpios", -1); + if (gpios == -1 || gpios > 64) { + printf("Illegal number of gpios %d\n", gpios); + goto end; + } - (void)fdt_setprop(blob, node_ofs, "gpio-line-names", buffer, pos); + /* get string array with names */ + const struct fdt_property* prop = fdt_get_property(blob, node_ofs, "gpio-line-names", NULL); + if (prop == NULL) { + goto end; + } + + /* modify given name */ + for (i=0; i 64) { + printf("Illegal number of gpios %d\n", gpios); + goto end; + } - (void)fdt_setprop(blob, node_ofs, "gpio-line-names", buffer, pos); + /* get string array with names */ + const struct fdt_property* prop = fdt_get_property(blob, node_ofs, "gpio-line-names", NULL); + if (prop == NULL) { + goto end; + } + + /* modify given name */ + for (i=0; i