From 2e581d52117bf39a8c48b05922fc5dc140f4ec67 Mon Sep 17 00:00:00 2001 From: Moritz Rosenthal Date: Mon, 21 Jun 2021 09:20:26 +0200 Subject: [PATCH] Fixes based on the code review * simplify set_console() * Prevent buffer overflow in fpga_verify() * Set individual temporary MAC addresses in set_mac_address() * Check return value of miiphy_get_current_dev() BugzId: 66150 --- board/nm/common/nbhw_env.c | 22 +++++----------------- board/nm/common/nbhw_fpga_gpio.c | 4 ++-- board/nm/common/nbhw_init.c | 2 +- board/nm/hw14/mvswitch.c | 4 ++++ 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/board/nm/common/nbhw_env.c b/board/nm/common/nbhw_env.c index 58b2c41ad1..c7982ea16e 100644 --- a/board/nm/common/nbhw_env.c +++ b/board/nm/common/nbhw_env.c @@ -21,7 +21,7 @@ void set_console(void) char buf[6]; char consolefile[] = "/root/boot/consoledev"; char *defaultconsole = env_get("defaultconsole"); - int use_default_console = 0; + int use_default_console = 1; #if defined(CONFIG_PRE_CONSOLE_BUFFER) int len = 0; @@ -29,25 +29,13 @@ void set_console(void) read_file_set_blk_dev("mmc", "0:3", FS_TYPE_EXT); len = get_file_size(consolefile); - if (len>=4) { + if (len>=5) { memset(buf, 0x00, sizeof(buf)); read_file(consolefile, buf, sizeof(buf)-1); - if (strstr(buf, "ttyS")==buf) { - if ((buf[4]<'0') && (buf[4]>'1')) { - /* invalid tty specified */ - use_default_console = 1; - } else { - /* Use retrieved ttySx */ - } - } else if (strstr(buf, "none")==buf) { - /* disable console */ - buf[0] = 0; - } else { - /* invalid device specified */ - use_default_console = 1; + if (strstr(buf, "ttyS") == buf && ( buf[4] == '0' || buf[4] == '1' )) { + /* Use retrieved ttySx */ + use_default_console = 0; } - } else { - use_default_console = 1; } if (use_default_console) { diff --git a/board/nm/common/nbhw_fpga_gpio.c b/board/nm/common/nbhw_fpga_gpio.c index 4b5eb4146a..64873796a8 100644 --- a/board/nm/common/nbhw_fpga_gpio.c +++ b/board/nm/common/nbhw_fpga_gpio.c @@ -149,7 +149,7 @@ static inline void spi_write(const struct nbhw_fpga_priv *priv, u8 data) static int fpga_verify(struct nbhw_fpga_priv *priv) { /* Check, if the FPGA is working */ - char fpga_type[30]; + char fpga_type[128]; u16 signature = readw(priv->regs); u16 fpga_version = readw(priv->regs + 0x02); u8 fpga_major = (fpga_version >> 8) & 0xFF; @@ -318,7 +318,7 @@ static void clean_up_after_programming(const struct nbhw_fpga_priv *priv) writel(0x55555555, MVEBU_MPP_BASE + 0x10); writel(0x06605505, MVEBU_MPP_BASE + 0x14); - dm_gpio_set_value(&priv->reset_logic, 0); //TODO : that seems wrong (AO) + dm_gpio_set_value(&priv->reset_logic, 0); udelay(100); dm_gpio_set_value(&priv->reset_logic, 1); udelay(100); diff --git a/board/nm/common/nbhw_init.c b/board/nm/common/nbhw_init.c index c49ba096a2..f0f0dc6678 100644 --- a/board/nm/common/nbhw_init.c +++ b/board/nm/common/nbhw_init.c @@ -57,7 +57,7 @@ void set_mac_address(int interface, int mac) { else { /* make temporary address */ macaddress[0] = 0; - macaddress[5] += 1; + macaddress[5] += interface; set_mac(interface, macaddress, 6); } } diff --git a/board/nm/hw14/mvswitch.c b/board/nm/hw14/mvswitch.c index 5b92e113f6..ee6f90d8d9 100644 --- a/board/nm/hw14/mvswitch.c +++ b/board/nm/hw14/mvswitch.c @@ -11,6 +11,8 @@ static int check_mvswitch(void) unsigned short switchPortProductId; int res; + if (!miidev) goto abort; + debug ("miidev: %s\n", miidev); res = miiphy_read(miidev, 0x10, 0x03, &switchPortProductId); @@ -54,6 +56,8 @@ static int init_mvswitch(void) unsigned short page; int i; + if (!miidev) goto abort; + debug ("miidev: %s\n", miidev); switch (mvSwType)