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>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/55267
Original-Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/71372
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/flashrom.c b/flashrom.c
index cbb9eab..26f2ca8 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -767,7 +767,7 @@
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)
@@ -1558,11 +1558,9 @@
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);
diff --git a/ichspi.c b/ichspi.c
index 90bbd13..d59fd3b 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -1723,7 +1723,7 @@
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,
@@ -1734,8 +1734,6 @@
ich_generation = ich_gen;
ich_spibar = spibar;
- memset(&desc, 0x00, sizeof(desc));
-
/* Moving registers / bits */
switch (ich_generation) {
case CHIPSET_100_SERIES_SUNRISE_POINT:
diff --git a/jlink_spi.c b/jlink_spi.c
index f2702fa..369c645 100644
--- a/jlink_spi.c
+++ b/jlink_spi.c
@@ -349,9 +349,8 @@
return 1;
}
- 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 316c8ed..998f37a 100644
--- a/linux_mtd.c
+++ b/linux_mtd.c
@@ -311,8 +311,7 @@
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;
diff --git a/physmap.c b/physmap.c
index 6c36814..796860c 100644
--- a/physmap.c
+++ b/physmap.c
@@ -433,8 +433,7 @@
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 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 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/stlinkv3_spi.c b/stlinkv3_spi.c
index fbb9b1b..d09b0d5 100644
--- a/stlinkv3_spi.c
+++ b/stlinkv3_spi.c
@@ -153,14 +153,12 @@
*/
static int stlinkv3_get_clk(uint32_t *bridge_input_clk)
{
- 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;
@@ -227,9 +225,7 @@
static int stlinkv3_check_version(enum fw_version_check_result *result)
{
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;
@@ -246,7 +242,7 @@
static int stlinkv3_spi_open(uint16_t reqested_freq_in_kHz)
{
- uint8_t command[16];
+ uint8_t command[16] = { 0 };
uint8_t answer[2];
uint16_t SCK_freq_in_kHz;
enum spi_prescaler prescaler;
@@ -273,8 +269,6 @@
}
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;
@@ -291,11 +285,9 @@
static int stlinkv3_get_last_readwrite_status(uint32_t *status)
{
- 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;
@@ -310,11 +302,9 @@
static int stlinkv3_spi_set_SPI_NSS(enum spi_nss_level nss_level)
{
- 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);
@@ -330,7 +320,7 @@
const unsigned char *write_arr,
unsigned char *read_arr)
{
- uint8_t command[16];
+ uint8_t command[16] = { 0 };
int rc = 0;
int actual_length = 0;
uint32_t rw_status = 0;
@@ -341,8 +331,6 @@
return -1;
}
- memset(command, 0, sizeof(command));
-
command[0] = STLINK_BRIDGE_COMMAND;
command[1] = STLINK_BRIDGE_WRITE_SPI;
command[2] = (uint8_t)write_cnt;
@@ -431,11 +419,9 @@
static int stlinkv3_spi_shutdown(void *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 58a8a0e..8059840 100644
--- a/usbblaster_spi.c
+++ b/usbblaster_spi.c
@@ -76,7 +76,7 @@
/* 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 };
if (ftdi_init(&ftdic) < 0)
return -1;
@@ -102,7 +102,6 @@
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");
@@ -119,9 +118,8 @@
static int send_write(unsigned int writecnt, const unsigned char *writearr)
{
- 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);
@@ -146,8 +144,7 @@
{
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) {