]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
karo: prevent video_mode variable from being clobbered by karo_fdt_set_display()
authorLothar Waßmann <LW@KARO-electronics.de>
Fri, 8 Nov 2013 09:25:51 +0000 (10:25 +0100)
committerLothar Waßmann <LW@KARO-electronics.de>
Fri, 8 Nov 2013 09:25:51 +0000 (10:25 +0100)
board/karo/common/fdt.c
board/karo/common/karo.h
board/karo/tx53/tx53.c
board/karo/tx6/tx6qdl.c

index 1ab15fe2027915be6dc3811556bdfd251fb6f990..7f3c748e05d0815e4c683f565bf5a8e484905f96 100644 (file)
@@ -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)
index 53a5ee9439acfac2f15c23125d1b455a2b3513e2..854994df11dfbb11e16018c97092d898a68b14d7 100644 (file)
@@ -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;
index cfc63e8f7d4eb530282451dcdee7837f189fbd14..e1d495fb9d061cce444cd5cf09da54e07fbddc45 100644 (file)
@@ -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);
index c41f0d46d3effd0e956b6380dbfd8dd6ea364ef4..d60d868ebcb4153f2f508e82222699051673394f 100644 (file)
@@ -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);