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
This commit is contained in:
Moritz Rosenthal 2021-06-21 09:20:26 +02:00
parent 8efea863e6
commit 2e581d5211
4 changed files with 12 additions and 20 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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)