diff options
author | Angel Pons <th3fanbus@gmail.com> | 2021-06-07 13:29:13 +0200 |
---|---|---|
committer | Nico Huber <nico.h@gmx.de> | 2021-06-09 16:07:45 +0000 |
commit | f41d24823c1703e328fc27588bbcf3c96eecdbc9 (patch) | |
tree | 3bd19f60db955c7206fa72a1ccdb7a2607e7001d | |
parent | 3bd47524c044168b01e54e772d23c7fa723dc0d5 (diff) | |
download | flashrom-f41d24823c1703e328fc27588bbcf3c96eecdbc9.tar.gz flashrom-f41d24823c1703e328fc27588bbcf3c96eecdbc9.tar.bz2 flashrom-f41d24823c1703e328fc27588bbcf3c96eecdbc9.zip |
treewide: Drop unnecessary uses of memset/memcpy
Simply provide an initialiser or use a direct assignment instead.
Change-Id: I07385375cd8eec8a95874001b402b2c17ec09e09
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/55267
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
-rw-r--r-- | flashrom.c | 8 | ||||
-rw-r--r-- | ichspi.c | 4 | ||||
-rw-r--r-- | jlink_spi.c | 3 | ||||
-rw-r--r-- | linux_mtd.c | 3 | ||||
-rw-r--r-- | physmap.c | 9 | ||||
-rw-r--r-- | raiden_debug_spi.c | 6 | ||||
-rw-r--r-- | stlinkv3_spi.c | 28 | ||||
-rw-r--r-- | usbblaster_spi.c | 9 |
8 files changed, 21 insertions, 49 deletions
diff --git a/flashrom.c b/flashrom.c index cd2e9a7e9..b804e2d4f 100644 --- a/flashrom.c +++ b/flashrom.c @@ -761,7 +761,7 @@ int probe_flash(struct registered_master *mst, int startchip, struct flashctx *f msg_gerr("Out of memory!\n"); exit(1); } - memcpy(flash->chip, chip, sizeof(*flash->chip)); + *flash->chip = *chip; flash->mst = mst; if (map_flash(flash) != 0) @@ -1619,11 +1619,9 @@ void list_programmers_linebreak(int startcol, int cols, int paren) static void print_sysinfo(void) { #if IS_WINDOWS - SYSTEM_INFO si; - OSVERSIONINFOEX osvi; + SYSTEM_INFO si = { 0 }; + OSVERSIONINFOEX osvi = { 0 }; - memset(&si, 0, sizeof(SYSTEM_INFO)); - memset(&osvi, 0, sizeof(OSVERSIONINFOEX)); msg_ginfo(" on Windows"); /* Tell Windows which version of the structure we want. */ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); @@ -1720,7 +1720,7 @@ int ich_init_spi(void *spibar, enum ich_chipset ich_gen) char *arg; int ich_spi_rw_restricted = 0; int desc_valid = 0; - struct ich_descriptors desc; + struct ich_descriptors desc = { 0 }; enum ich_spi_mode { ich_auto, ich_hwseq, @@ -1731,8 +1731,6 @@ int ich_init_spi(void *spibar, enum ich_chipset ich_gen) ich_generation = ich_gen; ich_spibar = spibar; - memset(&desc, 0x00, sizeof(desc)); - /* Moving registers / bits */ switch (ich_gen) { case CHIPSET_100_SERIES_SUNRISE_POINT: diff --git a/jlink_spi.c b/jlink_spi.c index 6342e7fca..0b862cf16 100644 --- a/jlink_spi.c +++ b/jlink_spi.c @@ -358,9 +358,8 @@ int jlink_spi_init(void) goto init_err; } - uint8_t caps[JAYLINK_DEV_EXT_CAPS_SIZE]; + uint8_t caps[JAYLINK_DEV_EXT_CAPS_SIZE] = { 0 }; - memset(caps, 0, sizeof(caps)); ret = jaylink_get_caps(jaylink_devh, caps); if (ret != JAYLINK_OK) { diff --git a/linux_mtd.c b/linux_mtd.c index a1af0696a..b06816411 100644 --- a/linux_mtd.c +++ b/linux_mtd.c @@ -315,8 +315,7 @@ static int linux_mtd_setup(int dev_num, struct linux_mtd_data *data) if (snprintf(sysfs_path, sizeof(sysfs_path), "%s/mtd%d/", LINUX_MTD_SYSFS_ROOT, dev_num) < 0) goto linux_mtd_setup_exit; - char buf[4]; - memset(buf, 0, sizeof(buf)); + char buf[4] = { 0 }; if (read_sysfs_string(sysfs_path, "type", buf, sizeof(buf))) return 1; @@ -433,8 +433,7 @@ int wrmsr(int addr, msr_t msr) int setup_cpu_msr(int cpu) { - char msrfilename[64]; - memset(msrfilename, 0, sizeof(msrfilename)); + char msrfilename[64] = { 0 }; snprintf(msrfilename, sizeof(msrfilename), "/dev/cpu/%d/msr", cpu); if (fd_msr != -1) { @@ -509,8 +508,7 @@ int wrmsr(int addr, msr_t msr) int setup_cpu_msr(int cpu) { - char msrfilename[64]; - memset(msrfilename, 0, sizeof(msrfilename)); + char msrfilename[64] = { 0 }; snprintf(msrfilename, sizeof(msrfilename), "/dev/amdmsr"); if (fd_msr != -1) { @@ -591,8 +589,7 @@ int wrmsr(int addr, msr_t msr) int setup_cpu_msr(int cpu) { - char msrfilename[64]; - memset(msrfilename, 0, sizeof(msrfilename)); + char msrfilename[64] = { 0 }; snprintf(msrfilename, sizeof(msrfilename), "/dev/cpu%d", cpu); if (fd_msr != -1) { diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c index 950b8afb1..4e177e545 100644 --- a/raiden_debug_spi.c +++ b/raiden_debug_spi.c @@ -1510,12 +1510,10 @@ int raiden_debug_spi_init(void) found = 1; goto loop_end; } else { - unsigned char dev_serial[32]; + unsigned char dev_serial[32] = { 0 }; struct libusb_device_descriptor descriptor; int rc; - memset(dev_serial, 0, sizeof(dev_serial)); - if (libusb_get_device_descriptor(device->device, &descriptor)) { msg_pdbg("USB: Failed to get device descriptor.\n"); goto loop_end; @@ -1591,7 +1589,7 @@ loop_end: return SPI_GENERIC_ERROR; } - memcpy(spi_config, &spi_master_raiden_debug, sizeof(*spi_config)); + *spi_config = spi_master_raiden_debug; data->dev = device; data->in_ep = in_endpoint; diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c index 24531628a..8b62740ce 100644 --- a/stlinkv3_spi.c +++ b/stlinkv3_spi.c @@ -156,14 +156,12 @@ static int stlinkv3_command(uint8_t *command, size_t command_length, */ static int stlinkv3_get_clk(uint32_t *bridge_input_clk, libusb_device_handle *stlinkv3_handle) { - uint8_t command[16]; + uint8_t command[16] = { 0 }; uint8_t answer[12]; if (bridge_input_clk == NULL) return -1; - memset(command, 0, sizeof(command)); - command[0] = STLINK_BRIDGE_COMMAND; command[1] = STLINK_BRIDGE_GET_CLOCK; command[2] = STLINK_SPI_COM; @@ -234,9 +232,7 @@ static int stlinkv3_spi_calc_prescaler(uint16_t reqested_freq_in_kHz, static int stlinkv3_check_version(enum fw_version_check_result *result, libusb_device_handle *stlinkv3_handle) { uint8_t answer[12]; - uint8_t command[16]; - - memset(command, 0, sizeof(command)); + uint8_t command[16] = { 0 }; command[0] = ST_GETVERSION_EXT; command[1] = 0x80; @@ -256,7 +252,7 @@ static int stlinkv3_check_version(enum fw_version_check_result *result, libusb_d static int stlinkv3_spi_open(uint16_t reqested_freq_in_kHz, libusb_device_handle *stlinkv3_handle) { - uint8_t command[16]; + uint8_t command[16] = { 0 }; uint8_t answer[2]; uint16_t SCK_freq_in_kHz; enum spi_prescaler prescaler; @@ -284,8 +280,6 @@ static int stlinkv3_spi_open(uint16_t reqested_freq_in_kHz, libusb_device_handle } msg_pinfo("SCK frequency set to %d kHz\n", SCK_freq_in_kHz); - memset(command, 0, sizeof(command)); - command[0] = STLINK_BRIDGE_COMMAND; command[1] = STLINK_BRIDGE_INIT_SPI; command[2] = SPI_DIRECTION_2LINES_FULLDUPLEX; @@ -305,11 +299,9 @@ static int stlinkv3_spi_open(uint16_t reqested_freq_in_kHz, libusb_device_handle static int stlinkv3_get_last_readwrite_status(uint32_t *status, libusb_device_handle *stlinkv3_handle) { - uint8_t command[16]; + uint8_t command[16] = { 0 }; uint16_t answer[4]; - memset(command, 0, sizeof(command)); - command[0] = STLINK_BRIDGE_COMMAND; command[1] = STLINK_BRIDGE_GET_RWCMD_STATUS; @@ -325,11 +317,9 @@ static int stlinkv3_get_last_readwrite_status(uint32_t *status, libusb_device_ha static int stlinkv3_spi_set_SPI_NSS(enum spi_nss_level nss_level, libusb_device_handle *stlinkv3_handle) { - uint8_t command[16]; + uint8_t command[16] = { 0 }; uint8_t answer[2]; - memset(command, 0, sizeof(command)); - command[0] = STLINK_BRIDGE_COMMAND; command[1] = STLINK_BRIDGE_CS_SPI; command[2] = (uint8_t) (nss_level); @@ -350,7 +340,7 @@ static int stlinkv3_spi_transmit(const struct flashctx *flash, { struct stlinkv3_spi_data *stlinkv3_data = flash->mst->spi.data; libusb_device_handle *stlinkv3_handle = stlinkv3_data->handle; - uint8_t command[16]; + uint8_t command[16] = { 0 }; int rc = 0; int actual_length = 0; uint32_t rw_status = 0; @@ -361,8 +351,6 @@ static int stlinkv3_spi_transmit(const struct flashctx *flash, return -1; } - memset(command, 0, sizeof(command)); - command[0] = STLINK_BRIDGE_COMMAND; command[1] = STLINK_BRIDGE_WRITE_SPI; command[2] = (uint8_t)write_cnt; @@ -452,11 +440,9 @@ transmit_err: static int stlinkv3_spi_shutdown(void *data) { struct stlinkv3_spi_data *stlinkv3_data = data; - uint8_t command[16]; + uint8_t command[16] = { 0 }; uint8_t answer[2]; - memset(command, 0, sizeof(command)); - command[0] = STLINK_BRIDGE_COMMAND; command[1] = STLINK_BRIDGE_CLOSE; command[2] = STLINK_SPI_COM; diff --git a/usbblaster_spi.c b/usbblaster_spi.c index 115876e88..5f240df93 100644 --- a/usbblaster_spi.c +++ b/usbblaster_spi.c @@ -74,9 +74,8 @@ static uint8_t reverse(uint8_t b) static int send_write(unsigned int writecnt, const unsigned char *writearr, struct ftdi_context ftdic) { - uint8_t buf[BUF_SIZE]; + uint8_t buf[BUF_SIZE] = { 0 }; - memset(buf, 0, sizeof(buf)); while (writecnt) { unsigned int i; unsigned int n_write = min(writecnt, BUF_SIZE - 1); @@ -101,8 +100,7 @@ static int send_read(unsigned int readcnt, unsigned char *readarr, struct ftdi_c { int i; unsigned int n_read; - uint8_t buf[BUF_SIZE]; - memset(buf, 0, sizeof(buf)); + uint8_t buf[BUF_SIZE] = { 0 }; n_read = readcnt; while (n_read) { @@ -181,7 +179,7 @@ static const struct spi_master spi_master_usbblaster = { /* Returns 0 upon success, a negative number upon errors. */ int usbblaster_spi_init(void) { - uint8_t buf[BUF_SIZE + 1]; + uint8_t buf[BUF_SIZE + 1] = { 0 }; struct ftdi_context ftdic; struct usbblaster_spi_data *usbblaster_data; @@ -209,7 +207,6 @@ int usbblaster_spi_init(void) return -1; } - memset(buf, 0, sizeof(buf)); buf[sizeof(buf)-1] = BIT_LED | BIT_CS; if (ftdi_write_data(&ftdic, buf, sizeof(buf)) < 0) { msg_perr("USB-Blaster reset write failed\n"); |