[Midnightbsd-cvs] src [8900] trunk/sys/dev/mxge/if_mxge.c: mxge(4): remove vestigal null pointer tests.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Mon Sep 26 18:36:32 EDT 2016
Revision: 8900
http://svnweb.midnightbsd.org/src/?rev=8900
Author: laffer1
Date: 2016-09-26 18:36:32 -0400 (Mon, 26 Sep 2016)
Log Message:
-----------
mxge(4): remove vestigal null pointer tests. use strlcpy. Check the mac address more strictly. Remove buffer limit check.
Modified Paths:
--------------
trunk/sys/dev/mxge/if_mxge.c
Modified: trunk/sys/dev/mxge/if_mxge.c
===================================================================
--- trunk/sys/dev/mxge/if_mxge.c 2016-09-26 22:35:42 UTC (rev 8899)
+++ trunk/sys/dev/mxge/if_mxge.c 2016-09-26 22:36:32 UTC (rev 8900)
@@ -287,42 +287,43 @@
static int
mxge_parse_strings(mxge_softc_t *sc)
{
-#define MXGE_NEXT_STRING(p) while(ptr < limit && *ptr++)
-
- char *ptr, *limit;
+ char *ptr;
int i, found_mac, found_sn2;
+ char *endptr;
ptr = sc->eeprom_strings;
- limit = sc->eeprom_strings + MXGE_EEPROM_STRINGS_SIZE;
found_mac = 0;
found_sn2 = 0;
- while (ptr < limit && *ptr != '\0') {
- if (memcmp(ptr, "MAC=", 4) == 0) {
- ptr += 1;
- sc->mac_addr_string = ptr;
- for (i = 0; i < 6; i++) {
- ptr += 3;
- if ((ptr + 2) > limit)
+ while (*ptr != '\0') {
+ if (strncmp(ptr, "MAC=", 4) == 0) {
+ ptr += 4;
+ for (i = 0;;) {
+ sc->mac_addr[i] = strtoul(ptr, &endptr, 16);
+ if (endptr - ptr != 2)
goto abort;
- sc->mac_addr[i] = strtoul(ptr, NULL, 16);
- found_mac = 1;
+ ptr = endptr;
+ if (++i == 6)
+ break;
+ if (*ptr++ != ':')
+ goto abort;
}
- } else if (memcmp(ptr, "PC=", 3) == 0) {
+ found_mac = 1;
+ } else if (strncmp(ptr, "PC=", 3) == 0) {
ptr += 3;
- strncpy(sc->product_code_string, ptr,
- sizeof (sc->product_code_string) - 1);
- } else if (!found_sn2 && (memcmp(ptr, "SN=", 3) == 0)) {
+ strlcpy(sc->product_code_string, ptr,
+ sizeof(sc->product_code_string));
+ } else if (!found_sn2 && (strncmp(ptr, "SN=", 3) == 0)) {
ptr += 3;
- strncpy(sc->serial_number_string, ptr,
- sizeof (sc->serial_number_string) - 1);
- } else if (memcmp(ptr, "SN2=", 4) == 0) {
+ strlcpy(sc->serial_number_string, ptr,
+ sizeof(sc->serial_number_string));
+ } else if (strncmp(ptr, "SN2=", 4) == 0) {
/* SN2 takes precedence over SN */
ptr += 4;
found_sn2 = 1;
- strncpy(sc->serial_number_string, ptr,
- sizeof (sc->serial_number_string) - 1);
+ strlcpy(sc->serial_number_string, ptr,
+ sizeof(sc->serial_number_string));
}
- MXGE_NEXT_STRING(ptr);
+ while (*ptr++ != '\0') {}
}
if (found_mac)
@@ -648,12 +649,6 @@
return (mxge_load_firmware(sc, 0));
}
-union qualhack
-{
- const char *ro_char;
- char *rw_char;
-};
-
static int
mxge_validate_firmware(mxge_softc_t *sc, const mcp_gen_header_t *hdr)
{
@@ -666,7 +661,7 @@
}
/* save firmware version for sysctl */
- strncpy(sc->fw_version, hdr->version, sizeof (sc->fw_version));
+ strlcpy(sc->fw_version, hdr->version, sizeof(sc->fw_version));
if (mxge_verbose)
device_printf(sc->dev, "firmware id: %s\n", hdr->version);
@@ -3324,8 +3319,6 @@
size_t bytes;
int err, i;
- err = ENOMEM;
-
/* allocate per-slice receive resources */
ss->rx_small.mask = ss->rx_big.mask = rx_ring_entries - 1;
@@ -3334,24 +3327,16 @@
/* allocate the rx shadow rings */
bytes = rx_ring_entries * sizeof (*ss->rx_small.shadow);
ss->rx_small.shadow = malloc(bytes, M_DEVBUF, M_ZERO|M_WAITOK);
- if (ss->rx_small.shadow == NULL)
- return err;
bytes = rx_ring_entries * sizeof (*ss->rx_big.shadow);
ss->rx_big.shadow = malloc(bytes, M_DEVBUF, M_ZERO|M_WAITOK);
- if (ss->rx_big.shadow == NULL)
- return err;
/* allocate the rx host info rings */
bytes = rx_ring_entries * sizeof (*ss->rx_small.info);
ss->rx_small.info = malloc(bytes, M_DEVBUF, M_ZERO|M_WAITOK);
- if (ss->rx_small.info == NULL)
- return err;
bytes = rx_ring_entries * sizeof (*ss->rx_big.info);
ss->rx_big.info = malloc(bytes, M_DEVBUF, M_ZERO|M_WAITOK);
- if (ss->rx_big.info == NULL)
- return err;
/* allocate the rx busdma resources */
err = bus_dma_tag_create(sc->parent_dmat, /* parent */
@@ -3448,8 +3433,6 @@
bytes = 8 +
sizeof (*ss->tx.req_list) * (ss->tx.max_desc + 4);
ss->tx.req_bytes = malloc(bytes, M_DEVBUF, M_WAITOK);
- if (ss->tx.req_bytes == NULL)
- return err;
/* ensure req_list entries are aligned to 8 bytes */
ss->tx.req_list = (mcp_kreq_ether_send_t *)
((unsigned long)(ss->tx.req_bytes + 7) & ~7UL);
@@ -3458,14 +3441,10 @@
bytes = sizeof (*ss->tx.seg_list) * ss->tx.max_desc;
ss->tx.seg_list = (bus_dma_segment_t *)
malloc(bytes, M_DEVBUF, M_WAITOK);
- if (ss->tx.seg_list == NULL)
- return err;
/* allocate the tx host info ring */
bytes = tx_ring_entries * sizeof (*ss->tx.info);
ss->tx.info = malloc(bytes, M_DEVBUF, M_ZERO|M_WAITOK);
- if (ss->tx.info == NULL)
- return err;
/* allocate the tx busdma resources */
err = bus_dma_tag_create(sc->parent_dmat, /* parent */
More information about the Midnightbsd-cvs
mailing list