Commit 4903ec74 authored by Lukasz Majewski's avatar Lukasz Majewski Committed by Carles Cufi
Browse files

drivers: ethernet: tc6: Check footer parity before updating struct oa_tc6



The parity of the received footer from data transfer (also including the
NORX) shall be checked before members of struct tc6 are updated.

This prevents from updating the driver's crucial metadata (i.e. struct
oa_tc6) with malformed values and informs the upper layers of the driver
that error has been detected.

Signed-off-by: default avatarLukasz Majewski <lukma@denx.de>
parent d2e864f1
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -254,12 +254,19 @@ int oa_tc6_check_status(struct oa_tc6 *tc6)
	return 0;
}

static void oa_tc6_update_status(struct oa_tc6 *tc6, uint32_t ftr)
static int oa_tc6_update_status(struct oa_tc6 *tc6, uint32_t ftr)
{
	if (oa_tc6_get_parity(ftr)) {
		LOG_DBG("OA Status Update: Footer parity error!");
		return -EIO;
	}

	tc6->exst = FIELD_GET(OA_DATA_FTR_EXST, ftr);
	tc6->sync = FIELD_GET(OA_DATA_FTR_SYNC, ftr);
	tc6->rca = FIELD_GET(OA_DATA_FTR_RCA, ftr);
	tc6->txc = FIELD_GET(OA_DATA_FTR_TXC, ftr);

	return 0;
}

int oa_tc6_chunk_spi_transfer(struct oa_tc6 *tc6, uint8_t *buf_rx, uint8_t *buf_tx,
@@ -295,9 +302,8 @@ int oa_tc6_chunk_spi_transfer(struct oa_tc6 *tc6, uint8_t *buf_rx, uint8_t *buf_
		return ret;
	}
	*ftr = sys_be32_to_cpu(*ftr);
	oa_tc6_update_status(tc6, *ftr);

	return 0;
	return oa_tc6_update_status(tc6, *ftr);
}

int oa_tc6_read_status(struct oa_tc6 *tc6, uint32_t *ftr)