From 4b5515bd00b76332748e4181cdf984c98a83993a Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Fri, 12 Dec 2014 09:19:19 -0800 Subject: [PATCH] panther/beltino/jecht: Fix pointer related errors in lan code BUG=None BRANCH=None TEST=Compiles and boots to "starting kernel" on panther Change-Id: I2f890871ad7cddaf132a0fa59a93f05c51d0c00e Signed-off-by: Furquan Shaikh Reviewed-on: https://chromium-review.googlesource.com/234982 Reviewed-by: Aaron Durbin Tested-by: Furquan Shaikh Commit-Queue: Furquan Shaikh --- src/mainboard/google/beltino/lan.c | 41 +++++++++++++++--------------- src/mainboard/google/jecht/lan.c | 41 +++++++++++++++--------------- src/mainboard/google/panther/lan.c | 41 +++++++++++++++--------------- 3 files changed, 63 insertions(+), 60 deletions(-) diff --git a/src/mainboard/google/beltino/lan.c b/src/mainboard/google/beltino/lan.c index 5f2841c8f6..cd4687a866 100644 --- a/src/mainboard/google/beltino/lan.c +++ b/src/mainboard/google/beltino/lan.c @@ -27,7 +27,7 @@ #include #include "onboard.h" -static unsigned int search(char *p, char *a, unsigned int lengthp, +static unsigned int search(char *p, u8 *a, unsigned int lengthp, unsigned int lengtha) { int i, j; @@ -41,7 +41,7 @@ static unsigned int search(char *p, char *a, unsigned int lengthp, return lengtha; } -static unsigned char get_hex_digit(char *offset) +static unsigned char get_hex_digit(u8 *offset) { unsigned char retval = 0; @@ -53,7 +53,7 @@ static unsigned char get_hex_digit(char *offset) } if (retval > 0x0F) { printk(BIOS_DEBUG, "Error: Invalid Hex digit found: %c - 0x%02x\n", - *offset, (unsigned char)*offset); + *offset, *offset); retval = 0; } @@ -61,14 +61,13 @@ static unsigned char get_hex_digit(char *offset) } static int get_mac_address(u32 *high_dword, u32 *low_dword, - u32 search_address, u32 search_length) + u8 *search_address, u32 search_length) { char key[] = "ethernet_mac"; unsigned int offset; int i; - offset = search(key, (char *)search_address, - sizeof(key) - 1, search_length); + offset = search(key, search_address, sizeof(key) - 1, search_length); if (offset == search_length) { printk(BIOS_DEBUG, "Error: Could not locate '%s' in VPD\n", key); @@ -89,18 +88,18 @@ static int get_mac_address(u32 *high_dword, u32 *low_dword, */ for (i = 0; i < 4; i++) { - *high_dword |= (get_hex_digit((char *)(search_address + offset)) + *high_dword |= (get_hex_digit(search_address + offset) << (4 + (i * 8))); - *high_dword |= (get_hex_digit((char *)(search_address + offset + 1)) + *high_dword |= (get_hex_digit(search_address + offset + 1) << (i * 8)); offset += 3; } *low_dword = 0; for (i = 0; i < 2; i++) { - *low_dword |= (get_hex_digit((char *)(search_address + offset)) + *low_dword |= (get_hex_digit(search_address + offset) << (4 + (i * 8))); - *low_dword |= (get_hex_digit((char *)(search_address + offset + 1)) + *low_dword |= (get_hex_digit(search_address + offset + 1) << (i * 8)); offset += 3; } @@ -108,14 +107,18 @@ static int get_mac_address(u32 *high_dword, u32 *low_dword, return *high_dword | *low_dword; } -static void program_mac_address(u16 io_base, u32 search_address, - u32 search_length) +static void program_mac_address(u16 io_base) { /* Default MAC Address of A0:00:BA:D0:0B:AD */ u32 high_dword = 0xD0BA00A0; /* high dword of mac address */ u32 low_dword = 0x0000AD0B; /* low word of mac address as a dword */ - if (search_length != -1) + void *search_address = NULL; + int search_length = find_fmap_entry("RO_VPD", &search_address); + + if (search_length == -1) + printk(BIOS_ERR, "LAN: find_fmap_entry returned -1.\n"); + else get_mac_address(&high_dword, &low_dword, search_address, search_length); @@ -123,19 +126,18 @@ static void program_mac_address(u16 io_base, u32 search_address, printk(BIOS_DEBUG, "Realtek NIC io_base = 0x%04x\n", io_base); printk(BIOS_DEBUG, "Programming MAC Address\n"); - outb(0xc0, io_base + 0x50); /* Disable register protection */ + /* Disable register protection */ + outb(0xc0, io_base + 0x50); outl(high_dword, io_base); outl(low_dword, io_base + 0x04); outb(0x60, io_base + 54); - outb(0x00, io_base + 0x50); /* Enable register protection again */ + /* Enable register protection again */ + outb(0x00, io_base + 0x50); } } void lan_init(void) { - char **vpd_region_ptr = NULL; - u32 search_length = find_fmap_entry("RO_VPD", (void **)vpd_region_ptr); - u32 search_address = (unsigned long)(*vpd_region_ptr); u16 io_base = 0; struct device *ethernet_dev = NULL; @@ -155,7 +157,7 @@ void lan_init(void) if (io_base) { /* Program MAC address based on VPD data */ - program_mac_address(io_base, search_address, search_length); + program_mac_address(io_base); /* * Program NIC LEDS @@ -175,4 +177,3 @@ void lan_init(void) outb(0x00, io_base + 0x50); /* Enable register protection */ } } - diff --git a/src/mainboard/google/jecht/lan.c b/src/mainboard/google/jecht/lan.c index 52a74bba9c..a8f7968e77 100644 --- a/src/mainboard/google/jecht/lan.c +++ b/src/mainboard/google/jecht/lan.c @@ -27,7 +27,7 @@ #include #include "onboard.h" -static unsigned int search(char *p, char *a, unsigned int lengthp, +static unsigned int search(char *p, u8 *a, unsigned int lengthp, unsigned int lengtha) { int i, j; @@ -41,7 +41,7 @@ static unsigned int search(char *p, char *a, unsigned int lengthp, return lengtha; } -static unsigned char get_hex_digit(char *offset) +static unsigned char get_hex_digit(u8 *offset) { unsigned char retval = 0; @@ -53,7 +53,7 @@ static unsigned char get_hex_digit(char *offset) } if (retval > 0x0F) { printk(BIOS_DEBUG, "Error: Invalid Hex digit found: %c - 0x%02x\n", - *offset, (unsigned char)*offset); + *offset, *offset); retval = 0; } @@ -61,14 +61,13 @@ static unsigned char get_hex_digit(char *offset) } static int get_mac_address(u32 *high_dword, u32 *low_dword, - u32 search_address, u32 search_length) + u8 *search_address, u32 search_length) { char key[] = "ethernet_mac"; unsigned int offset; int i; - offset = search(key, (char *)search_address, - sizeof(key) - 1, search_length); + offset = search(key, search_address, sizeof(key) - 1, search_length); if (offset == search_length) { printk(BIOS_DEBUG, "Error: Could not locate '%s' in VPD\n", key); @@ -89,18 +88,18 @@ static int get_mac_address(u32 *high_dword, u32 *low_dword, */ for (i = 0; i < 4; i++) { - *high_dword |= (get_hex_digit((char *)(search_address + offset)) + *high_dword |= (get_hex_digit(search_address + offset) << (4 + (i * 8))); - *high_dword |= (get_hex_digit((char *)(search_address + offset + 1)) + *high_dword |= (get_hex_digit(search_address + offset + 1) << (i * 8)); offset += 3; } *low_dword = 0; for (i = 0; i < 2; i++) { - *low_dword |= (get_hex_digit((char *)(search_address + offset)) + *low_dword |= (get_hex_digit(search_address + offset) << (4 + (i * 8))); - *low_dword |= (get_hex_digit((char *)(search_address + offset + 1)) + *low_dword |= (get_hex_digit(search_address + offset + 1) << (i * 8)); offset += 3; } @@ -108,14 +107,18 @@ static int get_mac_address(u32 *high_dword, u32 *low_dword, return *high_dword | *low_dword; } -static void program_mac_address(u16 io_base, u32 search_address, - u32 search_length) +static void program_mac_address(u16 io_base) { /* Default MAC Address of A0:00:BA:D0:0B:AD */ u32 high_dword = 0xD0BA00A0; /* high dword of mac address */ u32 low_dword = 0x0000AD0B; /* low word of mac address as a dword */ - if (search_length != -1) + void *search_address = NULL; + int search_length = find_fmap_entry("RO_VPD", &search_address); + + if (search_length == -1) + printk(BIOS_ERR, "LAN: find_fmap_entry returned -1.\n"); + else get_mac_address(&high_dword, &low_dword, search_address, search_length); @@ -123,19 +126,18 @@ static void program_mac_address(u16 io_base, u32 search_address, printk(BIOS_DEBUG, "Realtek NIC io_base = 0x%04x\n", io_base); printk(BIOS_DEBUG, "Programming MAC Address\n"); - outb(0xc0, io_base + 0x50); /* Disable register protection */ + /* Disable register protection */ + outb(0xc0, io_base + 0x50); outl(high_dword, io_base); outl(low_dword, io_base + 0x04); outb(0x60, io_base + 54); - outb(0x00, io_base + 0x50); /* Enable register protection again */ + /* Enable register protection again */ + outb(0x00, io_base + 0x50); } } void lan_init(void) { - char **vpd_region_ptr = NULL; - u32 search_length = find_fmap_entry("RO_VPD", (void **)vpd_region_ptr); - u32 search_address = (unsigned long)(*vpd_region_ptr); u16 io_base = 0; struct device *ethernet_dev = NULL; @@ -155,7 +157,7 @@ void lan_init(void) if (io_base) { /* Program MAC address based on VPD data */ - program_mac_address(io_base, search_address, search_length); + program_mac_address(io_base); /* * Program NIC LEDS @@ -175,4 +177,3 @@ void lan_init(void) outb(0x00, io_base + 0x50); /* Enable register protection */ } } - diff --git a/src/mainboard/google/panther/lan.c b/src/mainboard/google/panther/lan.c index 64f53f3037..06178a75b8 100644 --- a/src/mainboard/google/panther/lan.c +++ b/src/mainboard/google/panther/lan.c @@ -27,7 +27,7 @@ #include #include "onboard.h" -static unsigned int search(char *p, char *a, unsigned int lengthp, +static unsigned int search(char *p, u8 *a, unsigned int lengthp, unsigned int lengtha) { int i, j; @@ -41,7 +41,7 @@ static unsigned int search(char *p, char *a, unsigned int lengthp, return lengtha; } -static unsigned char get_hex_digit(char *offset) +static unsigned char get_hex_digit(u8 *offset) { unsigned char retval = 0; @@ -53,7 +53,7 @@ static unsigned char get_hex_digit(char *offset) } if (retval > 0x0F) { printk(BIOS_DEBUG, "Error: Invalid Hex digit found: %c - 0x%02x\n", - *offset, (unsigned char)*offset); + *offset, *offset); retval = 0; } @@ -61,14 +61,13 @@ static unsigned char get_hex_digit(char *offset) } static int get_mac_address(u32 *high_dword, u32 *low_dword, - u32 search_address, u32 search_length) + u8 *search_address, u32 search_length) { char key[] = "ethernet_mac"; unsigned int offset; int i; - offset = search(key, (char *)search_address, - sizeof(key) - 1, search_length); + offset = search(key, search_address, sizeof(key) - 1, search_length); if (offset == search_length) { printk(BIOS_DEBUG, "Error: Could not locate '%s' in VPD\n", key); @@ -89,18 +88,18 @@ static int get_mac_address(u32 *high_dword, u32 *low_dword, */ for (i = 0; i < 4; i++) { - *high_dword |= (get_hex_digit((char *)(search_address + offset)) + *high_dword |= (get_hex_digit(search_address + offset) << (4 + (i * 8))); - *high_dword |= (get_hex_digit((char *)(search_address + offset + 1)) + *high_dword |= (get_hex_digit(search_address + offset + 1) << (i * 8)); offset += 3; } *low_dword = 0; for (i = 0; i < 2; i++) { - *low_dword |= (get_hex_digit((char *)(search_address + offset)) + *low_dword |= (get_hex_digit(search_address + offset) << (4 + (i * 8))); - *low_dword |= (get_hex_digit((char *)(search_address + offset + 1)) + *low_dword |= (get_hex_digit(search_address + offset + 1) << (i * 8)); offset += 3; } @@ -108,14 +107,18 @@ static int get_mac_address(u32 *high_dword, u32 *low_dword, return *high_dword | *low_dword; } -static void program_mac_address(u16 io_base, u32 search_address, - u32 search_length) +static void program_mac_address(u16 io_base) { /* Default MAC Address of A0:00:BA:D0:0B:AD */ u32 high_dword = 0xD0BA00A0; /* high dword of mac address */ u32 low_dword = 0x0000AD0B; /* low word of mac address as a dword */ - if (search_length != -1) + void *search_address = NULL; + int search_length = find_fmap_entry("RO_VPD", &search_address); + + if (search_length == -1) + printk(BIOS_ERR, "LAN: find_fmap_entry returned -1.\n"); + else get_mac_address(&high_dword, &low_dword, search_address, search_length); @@ -123,19 +126,18 @@ static void program_mac_address(u16 io_base, u32 search_address, printk(BIOS_DEBUG, "Realtek NIC io_base = 0x%04x\n", io_base); printk(BIOS_DEBUG, "Programming MAC Address\n"); - outb(0xc0, io_base + 0x50); /* Disable register protection */ + /* Disable register protection */ + outb(0xc0, io_base + 0x50); outl(high_dword, io_base); outl(low_dword, io_base + 0x04); outb(0x60, io_base + 54); - outb(0x00, io_base + 0x50); /* Enable register protection again */ + /* Enable register protection again */ + outb(0x00, io_base + 0x50); } } void lan_init(void) { - char **vpd_region_ptr = NULL; - u32 search_length = find_fmap_entry("RO_VPD", (void **)vpd_region_ptr); - u32 search_address = (unsigned long)(*vpd_region_ptr); u16 io_base = 0; struct device *ethernet_dev = NULL; @@ -155,7 +157,7 @@ void lan_init(void) if (io_base) { /* Program MAC address based on VPD data */ - program_mac_address(io_base, search_address, search_length); + program_mac_address(io_base); /* * Program NIC LEDS @@ -175,4 +177,3 @@ void lan_init(void) outb(0x00, io_base + 0x50); /* Enable register protection */ } } -