Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 16b8b6de authored by Arnd Bergmann's avatar Arnd Bergmann Committed by David S. Miller
Browse files

rocker: fix Wmaybe-uninitialized false-positive



gcc-7 reports a warning that earlier versions did not have:

drivers/net/ethernet/rocker/rocker_ofdpa.c: In function 'ofdpa_port_stp_update':
arch/x86/include/asm/string_32.h:79:22: error: '*((void *)&prev_ctrls+4)' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   *((short *)to + 2) = *((short *)from + 2);
   ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/rocker/rocker_ofdpa.c:2218:7: note: '*((void *)&prev_ctrls+4)' was declared here

This is clearly a variation of the warning about 'prev_state' that
was shut up using uninitialized_var().

We can slightly simplify the code and get rid of the warning by unconditionally
saving the prev_state and prev_ctrls variables. The inlined memcpy is not
particularly expensive here, as it just has to read five bytes from one or
two cache lines.

Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e497ec68
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -2216,18 +2216,15 @@ static int ofdpa_port_stp_update(struct ofdpa_port *ofdpa_port,
{
	bool want[OFDPA_CTRL_MAX] = { 0, };
	bool prev_ctrls[OFDPA_CTRL_MAX];
	u8 uninitialized_var(prev_state);
	u8 prev_state;
	int err;
	int i;

	if (switchdev_trans_ph_prepare(trans)) {
		memcpy(prev_ctrls, ofdpa_port->ctrls, sizeof(prev_ctrls));
	prev_state = ofdpa_port->stp_state;
	}

	if (ofdpa_port->stp_state == state)
	if (prev_state == state)
		return 0;

	memcpy(prev_ctrls, ofdpa_port->ctrls, sizeof(prev_ctrls));
	ofdpa_port->stp_state = state;

	switch (state) {