From 4d39e8bd31c71dc4fe856f1074ef96d57550739c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lothar=20Wa=C3=9Fmann?= Date: Fri, 8 Nov 2013 10:25:51 +0100 Subject: [PATCH] karo: prevent video_mode variable from being clobbered by karo_fdt_set_display() --- board/karo/common/fdt.c | 32 ++++++++++++++++++-------------- board/karo/common/karo.h | 6 +++--- board/karo/tx53/tx53.c | 8 ++++---- board/karo/tx6/tx6qdl.c | 8 ++++---- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/board/karo/common/fdt.c b/board/karo/common/fdt.c index 1ab15fe202..7f3c748e05 100644 --- a/board/karo/common/fdt.c +++ b/board/karo/common/fdt.c @@ -534,7 +534,6 @@ int karo_fdt_create_fb_mode(void *blob, const char *name, return ret; } - printf("node '%s' offset=%d\n", "display", off); ret = fdt_subnode_offset(blob, off, subnode); if (ret < 0) { debug("Could not find node '%s' in FDT: %d\n", subnode, ret); @@ -545,7 +544,6 @@ int karo_fdt_create_fb_mode(void *blob, const char *name, } } - printf("node '%s' offset=%d\n", subnode, ret); ret = fdt_add_subnode(blob, ret, name); if (ret < 0) { printf("Failed to add %s subnode: %d\n", name, ret); @@ -600,33 +598,40 @@ out: return ret; } -char *karo_fdt_set_display(char *video_mode, const char *lcd_path, - const char *lvds_path) +const char *karo_fdt_set_display(const char *video_mode, const char *lcd_path, + const char *lvds_path) { - char *vm; + static char buffer[128]; + char *vm, *vmode = buffer; int ret; int off; void *blob = (void *)gd->fdt_blob; - if (video_mode == NULL) + if (video_mode == NULL || strlen(video_mode) == 0) return NULL; + if (strlen(video_mode) >= sizeof(buffer)) { + printf("video_mode string too long\n"); + return NULL; + } + strcpy(buffer, video_mode); + off = fdt_path_offset(blob, "/aliases"); ret = fdt_resize(blob); if (ret < 0) { printf("%s: Failed to resize FDT: %s\n", __func__, fdt_strerror(ret)); } - vm = strsep(&video_mode, ":"); + vm = strsep(&vmode, ":"); if (off < 0) { off = fdt_add_subnode(blob, off, "aliases"); if (off < 0) { printf("%s: Failed to create 'aliases' node: %s\n", __func__, fdt_strerror(off)); - return video_mode ?: vm; + return vmode ?: vm; } } - if (video_mode != NULL) { + if (vmode != NULL) { char display[strlen(lvds_path) + sizeof("/lvds-channel@x")]; strncpy(display, lvds_path, sizeof(display)); @@ -636,9 +641,8 @@ char *karo_fdt_set_display(char *video_mode, const char *lcd_path, } else if (strcmp(vm, "LVDS1") == 0) { strncat(display, "/lvds-channel@1", sizeof(display)); } else { - printf("%s: Syntax error in video_mode\n", - __func__); - return video_mode; + debug("%s: Syntax error in video_mode\n", __func__); + return vmode; } ret = fdt_setprop_string(blob, off, "display", display); debug("setprop_string(display='%s') returned %d\n", display, ret); @@ -660,13 +664,13 @@ char *karo_fdt_set_display(char *video_mode, const char *lcd_path, ret = fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0); } - video_mode = vm; + vmode = vm; } if (ret) { printf("%s: failed to set 'display' alias: %s\n", __func__, fdt_strerror(ret)); } - return video_mode; + return vmode; } int karo_fdt_update_fb_mode(void *blob, const char *name) diff --git a/board/karo/common/karo.h b/board/karo/common/karo.h index 53a5ee9439..854994df11 100644 --- a/board/karo/common/karo.h +++ b/board/karo/common/karo.h @@ -31,8 +31,8 @@ int karo_fdt_get_fb_mode(void *blob, const char *name, int karo_fdt_update_fb_mode(void *blob, const char *name); int karo_fdt_create_fb_mode(void *blob, const char *name, struct fb_videomode *mode); -char *karo_fdt_set_display(char *video_mode, const char *lcd_path, - const char *lvds_path); +const char *karo_fdt_set_display(const char *video_mode, const char *lcd_path, + const char *lvds_path); #else static inline void karo_fdt_remove_node(void *blob, const char *node) { @@ -77,7 +77,7 @@ static inline int karo_fdt_create_fb_mode(void *blob, { return 0; } -static inline char *karo_fdt_set_display(char *video_mode, const char *lcd_path, +static inline const char *karo_fdt_set_display(const char *video_mode, const char *lcd_path, const char *lvds_path) { return video_mode; diff --git a/board/karo/tx53/tx53.c b/board/karo/tx53/tx53.c index cfc63e8f7d..e1d495fb9d 100644 --- a/board/karo/tx53/tx53.c +++ b/board/karo/tx53/tx53.c @@ -841,8 +841,8 @@ static const struct gpio stk5_lcd_gpios[] = { void lcd_ctrl_init(void *lcdbase) { int color_depth = 24; - char *video_mode = getenv("video_mode"); - char *vm; + const char *video_mode = getenv("video_mode"); + const char *vm; unsigned long val; int refresh = 60; struct fb_videomode *p = &tx53_fb_modes[0]; @@ -1020,7 +1020,7 @@ void lcd_ctrl_init(void *lcdbase) if (p != &fb_mode) { int ret; - printf("Creating new display-timing node from '%s'\n", + debug("Creating new display-timing node from '%s'\n", video_mode); ret = karo_fdt_create_fb_mode(working_fdt, video_mode, p); if (ret) @@ -1194,7 +1194,7 @@ void ft_board_setup(void *blob, bd_t *bd) { const char *baseboard = getenv("baseboard"); int stk5_v5 = baseboard != NULL && (strcmp(baseboard, "stk5-v5") == 0); - char *video_mode = getenv("video_mode"); + const char *video_mode = getenv("video_mode"); fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes)); fdt_fixup_ethernet(blob); diff --git a/board/karo/tx6/tx6qdl.c b/board/karo/tx6/tx6qdl.c index c41f0d46d3..d60d868ebc 100644 --- a/board/karo/tx6/tx6qdl.c +++ b/board/karo/tx6/tx6qdl.c @@ -819,8 +819,8 @@ static const struct gpio stk5_lcd_gpios[] = { void lcd_ctrl_init(void *lcdbase) { int color_depth = 24; - char *video_mode = getenv("video_mode"); - char *vm; + const char *video_mode = getenv("video_mode"); + const char *vm; unsigned long val; int refresh = 60; struct fb_videomode *p = &tx6_fb_modes[0]; @@ -998,7 +998,7 @@ void lcd_ctrl_init(void *lcdbase) if (p != &fb_mode) { int ret; - printf("Creating new display-timing node from '%s'\n", + debug("Creating new display-timing node from '%s'\n", video_mode); ret = karo_fdt_create_fb_mode(working_fdt, video_mode, p); if (ret) @@ -1176,7 +1176,7 @@ void ft_board_setup(void *blob, bd_t *bd) { const char *baseboard = getenv("baseboard"); int stk5_v5 = baseboard != NULL && (strcmp(baseboard, "stk5-v5") == 0); - char *video_mode = getenv("video_mode"); + const char *video_mode = getenv("video_mode"); karo_fdt_enable_node(blob, "stk5led", !stk5_v5); -- 2.39.2